protected void preRebuild() { collisionShape.calculateLocalInertia(mass, localInertia); if (constructionInfo == null) { constructionInfo = new RigidBodyConstructionInfo(mass, motionState, collisionShape.getCShape(), localInertia); } else { constructionInfo.mass = mass; constructionInfo.collisionShape = collisionShape.getCShape(); constructionInfo.motionState = motionState; } }
/** * @param shape The CollisionShape (no Mesh or CompoundCollisionShapes) * @param stepHeight The quantization size for vertical movement */ public PhysicsCharacter(CollisionShape shape, float stepHeight) { this.collisionShape = shape; if (!(shape.getCShape() instanceof ConvexShape)) { throw (new UnsupportedOperationException("Kinematic character nodes cannot have mesh collision shapes")); } this.stepHeight = stepHeight; buildObject(); }
/** * removes a child shape * @param shape the child shape to remove */ public void removeChildShape(CollisionShape shape) { ((CompoundShape) cShape).removeChildShape(shape.getCShape()); for (Iterator<ChildCollisionShape> it = children.iterator(); it.hasNext();) { ChildCollisionShape childCollisionShape = it.next(); if (childCollisionShape.shape == shape) { it.remove(); } } }
@Override public void setCollisionShape(CollisionShape collisionShape) { if (!(collisionShape.getCShape() instanceof ConvexShape)) { throw (new UnsupportedOperationException("Kinematic character nodes cannot have mesh collision shapes")); } super.setCollisionShape(collisionShape); if (gObject == null) { buildObject(); }else{ gObject.setCollisionShape(collisionShape.getCShape()); } }
/** * 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 > 0.4f). * 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) { results.clear(); if (!(shape.getCShape() instanceof ConvexShape)) { logger.log(Level.WARNING, "Trying to sweep test with incompatible mesh shape!"); return results; } dynamicsWorld.convexSweepTest((ConvexShape) shape.getCShape(), Converter.convert(start, sweepTrans1), Converter.convert(end, sweepTrans2), new InternalSweepListener(results)); return results; }
/** * 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 > 0.4f). * 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 = new LinkedList<PhysicsSweepTestResult>(); if (!(shape.getCShape() instanceof ConvexShape)) { logger.log(Level.WARNING, "Trying to sweep test with incompatible mesh shape!"); return results; } dynamicsWorld.convexSweepTest((ConvexShape) shape.getCShape(), Converter.convert(start, sweepTrans1), Converter.convert(end, sweepTrans2), new InternalSweepListener(results)); return results; }
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 (rBody == null) { rebuildRigidBody(); } else { collisionShape.calculateLocalInertia(mass, localInertia); constructionInfo.collisionShape = collisionShape.getCShape(); rBody.setCollisionShape(collisionShape.getCShape()); } }
public static Mesh getDebugMesh(CollisionShape shape) { Mesh mesh = null; if (shape.getCShape() instanceof ConvexShape) { mesh = new Mesh(); mesh.setBuffer(Type.Position, 3, getVertices((ConvexShape) shape.getCShape())); mesh.getFloatBuffer(Type.Position).clear(); } else if (shape.getCShape() instanceof ConcaveShape) { mesh = new Mesh(); mesh.setBuffer(Type.Position, 3, getVertices((ConcaveShape) shape.getCShape())); mesh.getFloatBuffer(Type.Position).clear(); } return mesh; }
@Override public void setCollisionShape(CollisionShape collisionShape) { super.setCollisionShape(collisionShape); if (gObject == null) { buildObject(); }else{ gObject.setCollisionShape(collisionShape.getCShape()); } }
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); ((CompoundShape) cShape).addChildShape(transA, shape.getCShape()); }
protected void buildObject() { if (gObject == null) { gObject = new PairCachingGhostObject(); } gObject.setCollisionFlags(CollisionFlags.CHARACTER_OBJECT); gObject.setCollisionFlags(gObject.getCollisionFlags() & ~CollisionFlags.NO_CONTACT_RESPONSE); gObject.setCollisionShape(collisionShape.getCShape()); gObject.setUserPointer(this); character = new KinematicCharacterController(gObject, (ConvexShape) collisionShape.getCShape(), stepHeight); }
protected void buildObject() { if (gObject == null) { gObject = new PairCachingGhostObject(); gObject.setCollisionFlags(gObject.getCollisionFlags() | CollisionFlags.NO_CONTACT_RESPONSE); } gObject.setCollisionShape(collisionShape.getCShape()); gObject.setUserPointer(this); }
/** * adds a child shape at the given local translation * @param shape the child shape to add * @param location the local location of the child shape */ 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)); ((CompoundShape) cShape).addChildShape(transA, shape.getCShape()); }
/** * adds a child shape at the given local translation * @param shape the child shape to add * @param location the local location of the child shape */ public void addChildShape(CollisionShape shape, Vector3f location) { Transform transA = new Transform(Converter.convert(new Matrix3f())); Converter.convert(location, transA.origin); children.add(new ChildCollisionShape(location.clone(), new Matrix3f(), shape)); ((CompoundShape) cShape).addChildShape(transA, shape.getCShape()); }
@Override public void read(JmeImporter e) throws IOException { super.read(e); InputCapsule capsule = e.getCapsule(this); stepHeight = capsule.readFloat("stepHeight", 1.0f); buildObject(); character = new KinematicCharacterController(gObject, (ConvexShape) collisionShape.getCShape(), stepHeight); setGravity(capsule.readFloat("gravity", 9.8f * 3)); setContactResponse(capsule.readBoolean("contactResponse", true)); setMaxSlope(capsule.readFloat("maxSlope", 1.0f)); setFallSpeed(capsule.readFloat("fallSpeed", 55.0f)); setJumpSpeed(capsule.readFloat("jumpSpeed", 10.0f)); setUpAxis(capsule.readInt("upAxis", 1)); setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0)); setCcdSweptSphereRadius(capsule.readFloat("ccdSweptSphereRadius", 0)); setPhysicsLocation((Vector3f) capsule.readSavable("physicsLocation", new Vector3f())); } }
protected void preRebuild() { collisionShape.calculateLocalInertia(mass, localInertia); if (constructionInfo == null) { constructionInfo = new RigidBodyConstructionInfo(mass, motionState, collisionShape.getCShape(), localInertia); } else { constructionInfo.mass = mass; constructionInfo.collisionShape = collisionShape.getCShape(); constructionInfo.motionState = motionState; } }
/** * @param shape The CollisionShape (no Mesh or CompoundCollisionShapes) * @param stepHeight The quantization size for vertical movement */ public PhysicsCharacter(CollisionShape shape, float stepHeight) { this.collisionShape = shape; if (!(shape.getCShape() instanceof ConvexShape)) { throw (new UnsupportedOperationException("Kinematic character nodes cannot have mesh collision shapes")); } this.stepHeight = stepHeight; buildObject(); }
@Override public void setCollisionShape(CollisionShape collisionShape) { if (!(collisionShape.getCShape() instanceof ConvexShape)) { throw (new UnsupportedOperationException("Kinematic character nodes cannot have mesh collision shapes")); } super.setCollisionShape(collisionShape); if (gObject == null) { buildObject(); }else{ gObject.setCollisionShape(collisionShape.getCShape()); } }
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); ((CompoundShape) cShape).addChildShape(transA, shape.getCShape()); }
/** * adds a child shape at the given local translation * @param shape the child shape to add * @param location the local location of the child shape */ public void addChildShape(CollisionShape shape, Vector3f location) { Transform transA = new Transform(Converter.convert(new Matrix3f())); Converter.convert(location, transA.origin); children.add(new ChildCollisionShape(location.clone(), new Matrix3f(), shape)); ((CompoundShape) cShape).addChildShape(transA, shape.getCShape()); }