private void addChildShapeDirect(CollisionShape shape, Vector3f location, Matrix3f rotation) { if(shape instanceof CompoundCollisionShape){ throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!"); } // Transform transA = new Transform(Converter.convert(rotation)); // Converter.convert(location, transA.origin); // Converter.convert(rotation, transA.basis); addChildShape(objectId, shape.getObjectId(), location, rotation); // ((CompoundShape) objectId).addChildShape(transA, shape.getObjectId()); }
/** * Remove a child from this shape. * * @param shape the child shape to remove (not null) */ public void removeChildShape(CollisionShape shape) { removeChildShape(objectId, shape.getObjectId()); // ((CompoundShape) objectId).removeChildShape(shape.getObjectId()); for (Iterator<ChildCollisionShape> it = children.iterator(); it.hasNext();) { ChildCollisionShape childCollisionShape = it.next(); if (childCollisionShape.shape == shape) { it.remove(); } } }
/** * Perform a sweep-collision test and store the results in an existing list. * <p> * The starting and ending locations must be at least 0.4f physics-space * units apart. * <p> * A sweep test will miss a collision if it starts inside an object and * sweeps away from the object's center. * * @param shape the shape to sweep (not null) * @param start the starting physics-space transform (not null) * @param end the ending physics-space transform (not null) * @param results the list to hold results (not null, modified) * @param allowedCcdPenetration true→allow, false→disallow * @return results */ public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end, List<PhysicsSweepTestResult> results, float allowedCcdPenetration ) { results.clear(); sweepTest_native(shape.getObjectId(), start, end, physicsSpaceId, results, allowedCcdPenetration); return results; }
/** * Create the configured character in Bullet. */ protected void buildObject() { if (objectId == 0) { objectId = createGhostObject(); Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Creating GhostObject {0}", Long.toHexString(objectId)); initUserPointer(); } setCharacterFlags(objectId); attachCollisionShape(objectId, collisionShape.getObjectId()); if (characterId != 0) { Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Clearing Character {0}", Long.toHexString(objectId)); finalizeNativeCharacter(characterId); } characterId = createCharacterObject(objectId, collisionShape.getObjectId(), stepHeight); Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Creating Character {0}", Long.toHexString(characterId)); }
/** * Create the configured object in Bullet. */ protected void buildObject() { if (objectId == 0) { // gObject = new PairCachingGhostObject(); objectId = createGhostObject(); Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Ghost Object {0}", Long.toHexString(objectId)); setGhostFlags(objectId); initUserPointer(); } // if (gObject == null) { // gObject = new PairCachingGhostObject(); // gObject.setCollisionFlags(gObject.getCollisionFlags() | CollisionFlags.NO_CONTACT_RESPONSE); // } attachCollisionShape(objectId, collisionShape.getObjectId()); }
/** * Apply the specified CollisionShape to this body. * <p> * Note that the body should not be in any physics space while changing * shape; the body gets rebuilt on the physics side. * * @param collisionShape the shape to apply (not null, alias created) */ public void setCollisionShape(CollisionShape collisionShape) { super.setCollisionShape(collisionShape); if (collisionShape instanceof MeshCollisionShape && mass != 0) { throw new IllegalStateException("Dynamic rigidbody can not have mesh collision shape!"); } if (objectId == 0) { rebuildRigidBody(); } else { setCollisionShape(objectId, collisionShape.getObjectId()); updateMassProps(objectId, collisionShape.getObjectId(), mass); } }
/** * Alter this body's mass. Bodies with mass=0 are static. For dynamic * bodies, it is best to keep the mass around 1. * * @param mass the desired mass (>0) or 0 for a static body (default=1) */ public void setMass(float mass) { this.mass = mass; if (collisionShape instanceof MeshCollisionShape && mass != 0) { throw new IllegalStateException("Dynamic rigidbody can not have mesh collision shape!"); } if (objectId != 0) { if (collisionShape != null) { updateMassProps(objectId, collisionShape.getObjectId(), mass); } if (mass == 0.0f) { setStatic(objectId, true); } else { setStatic(objectId, false); } } }
/** * Build/rebuild this body after parameters have changed. */ protected void rebuildRigidBody() { boolean removed = false; if (collisionShape instanceof MeshCollisionShape && mass != 0) { throw new IllegalStateException("Dynamic rigidbody can not have mesh collision shape!"); } if (objectId != 0) { if (isInWorld(objectId)) { PhysicsSpace.getPhysicsSpace().remove(this); removed = true; } Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Clearing RigidBody {0}", Long.toHexString(objectId)); finalizeNative(objectId); } preRebuild(); objectId = createRigidBody(mass, motionState.getObjectId(), collisionShape.getObjectId()); Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created RigidBody {0}", Long.toHexString(objectId)); postRebuild(); if (removed) { PhysicsSpace.getPhysicsSpace().add(this); } }
/** * Add a child shape with the specified local translation and orientation. * * @param shape the child shape to add (not null, not a compound shape, * alias created) * @param location the local coordinates of the child shape's center (not * null, unaffected) * @param rotation the local orientation of the child shape (not null, * unaffected) */ public void addChildShape(CollisionShape shape, Vector3f location, Matrix3f rotation) { if(shape instanceof CompoundCollisionShape){ throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!"); } // Transform transA = new Transform(Converter.convert(rotation)); // Converter.convert(location, transA.origin); // Converter.convert(rotation, transA.basis); children.add(new ChildCollisionShape(location.clone(), rotation.clone(), shape)); addChildShape(objectId, shape.getObjectId(), location, rotation); // ((CompoundShape) objectId).addChildShape(transA, shape.getObjectId()); }
/** * Apply the specified CollisionShape to this character. Note that the * character should not be in any physics space while changing shape; the * character gets rebuilt on the physics side. * * @param collisionShape the shape to apply (not null, alias created) */ @Override public void setCollisionShape(CollisionShape collisionShape) { // if (!(collisionShape.getObjectId() instanceof ConvexShape)) { // throw (new UnsupportedOperationException("Kinematic character nodes cannot have mesh collision shapes")); // } super.setCollisionShape(collisionShape); if (objectId == 0) { buildObject(); } else { attachCollisionShape(objectId, collisionShape.getObjectId()); } }
/** * Apply the specified CollisionShape to this object. Note that the object * should not be in any physics space while changing shape; the object gets * rebuilt on the physics side. * * @param collisionShape the shape to apply (not null, alias created) */ @Override public void setCollisionShape(CollisionShape collisionShape) { super.setCollisionShape(collisionShape); if (objectId == 0) { buildObject(); } else { attachCollisionShape(objectId, collisionShape.getObjectId()); } }
/** * Create a mesh for visualizing the specified shape. * * @param shape (not null, unaffected) * @return a new mesh (not null) */ public static Mesh getDebugMesh(CollisionShape shape) { Mesh mesh = new Mesh(); DebugMeshCallback callback = new DebugMeshCallback(); long id = shape.getObjectId(); getVertices(id, callback); mesh.setBuffer(Type.Position, 3, callback.getVertices()); mesh.getFloatBuffer(Type.Position).clear(); return mesh; }
/** * Performs a sweep collision test and returns the results as a list of * PhysicsSweepTestResults<br/> You have to use different Transforms for * start and end (at least distance > allowedCcdPenetration). SweepTest will not see a * collision if it starts INSIDE an object and is moving AWAY from its * center. */ public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end, List<PhysicsSweepTestResult> results, float allowedCcdPenetration ) { results.clear(); sweepTest_native(shape.getObjectId(), start, end, physicsSpaceId, results, allowedCcdPenetration); return results; }
private void addChildShapeDirect(CollisionShape shape, Vector3f location, Matrix3f rotation) { if(shape instanceof CompoundCollisionShape){ throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!"); } // Transform transA = new Transform(Converter.convert(rotation)); // Converter.convert(location, transA.origin); // Converter.convert(rotation, transA.basis); addChildShape(objectId, shape.getObjectId(), location, rotation); // ((CompoundShape) objectId).addChildShape(transA, shape.getObjectId()); }
private void addChildShapeDirect(CollisionShape shape, Vector3f location, Matrix3f rotation) { if(shape instanceof CompoundCollisionShape){ throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!"); } // Transform transA = new Transform(Converter.convert(rotation)); // Converter.convert(location, transA.origin); // Converter.convert(rotation, transA.basis); addChildShape(objectId, shape.getObjectId(), location, rotation); // ((CompoundShape) objectId).addChildShape(transA, shape.getObjectId()); }
public void setCollisionShape(CollisionShape collisionShape) { super.setCollisionShape(collisionShape); if (collisionShape instanceof MeshCollisionShape && mass != 0) { throw new IllegalStateException("Dynamic rigidbody can not have mesh collision shape!"); } if (objectId == 0) { rebuildRigidBody(); } else { setCollisionShape(objectId, collisionShape.getObjectId()); updateMassProps(objectId, collisionShape.getObjectId(), mass); } }
public void setCollisionShape(CollisionShape collisionShape) { super.setCollisionShape(collisionShape); if (collisionShape instanceof MeshCollisionShape && mass != 0) { throw new IllegalStateException("Dynamic rigidbody can not have mesh collision shape!"); } if (objectId == 0) { rebuildRigidBody(); } else { setCollisionShape(objectId, collisionShape.getObjectId()); updateMassProps(objectId, collisionShape.getObjectId(), mass); } }
@Override public void setCollisionShape(CollisionShape collisionShape) { // if (!(collisionShape.getObjectId() instanceof ConvexShape)) { // throw (new UnsupportedOperationException("Kinematic character nodes cannot have mesh collision shapes")); // } super.setCollisionShape(collisionShape); if (objectId == 0) { buildObject(); } else { attachCollisionShape(objectId, collisionShape.getObjectId()); } }
@Override public void setCollisionShape(CollisionShape collisionShape) { super.setCollisionShape(collisionShape); if (objectId == 0) { buildObject(); } else { attachCollisionShape(objectId, collisionShape.getObjectId()); } }
public static Mesh getDebugMesh(CollisionShape shape) { Mesh mesh = new Mesh(); mesh = new Mesh(); DebugMeshCallback callback = new DebugMeshCallback(); getVertices(shape.getObjectId(), callback); mesh.setBuffer(Type.Position, 3, callback.getVertices()); mesh.getFloatBuffer(Type.Position).clear(); return mesh; }