private Node createLimb(float width, float height, Vector3f location, boolean rotate) { int axis = rotate ? PhysicsSpace.AXIS_X : PhysicsSpace.AXIS_Y; CapsuleCollisionShape shape = new CapsuleCollisionShape(width, height, axis); Node node = new Node("Limb"); RigidBodyControl rigidBodyControl = new RigidBodyControl(shape, 1); node.setLocalTranslation(location); node.addControl(rigidBodyControl); return node; }
/** * Instantiate the configured shape in Bullet. */ protected void createShape(){ objectId = createShape(axis, radius, height); Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId)); setScale(scale); setMargin(margin); // switch(axis){ // case 0: // objectId=new CapsuleShapeX(radius,height); // break; // case 1: // objectId=new CapsuleShape(radius,height); // break; // case 2: // objectId=new CapsuleShapeZ(radius,height); // break; // } // objectId.setLocalScaling(Converter.convert(getScale())); // objectId.setMargin(margin); }
/** * Creates a capsule shape around the given axis (0=X,1=Y,2=Z). * @param radius * @param height * @param axis */ public CapsuleCollisionShape(float radius, float height, int axis) { this.radius=radius; this.height=height; this.axis=axis; createShape(); }
protected void createShape(){ switch(axis){ case 0: cShape=new CapsuleShapeX(radius,height); break; case 1: cShape=new CapsuleShape(radius,height); break; case 2: cShape=new CapsuleShapeZ(radius,height); break; } cShape.setLocalScaling(Converter.convert(getScale())); cShape.setMargin(margin); }
/** * Instantiate a Y-axis capsule shape with the specified radius and height. * * @param radius the desired radius (≥0) * @param height the desired height (of the cylindrical portion) (≥0) */ public CapsuleCollisionShape(float radius, float height) { this.radius=radius; this.height=height; this.axis=1; createShape(); }
protected void createShape(){ switch(axis){ case 0: cShape=new CapsuleShapeX(radius,height); break; case 1: cShape=new CapsuleShape(radius,height); break; case 2: cShape=new CapsuleShapeZ(radius,height); break; } cShape.setLocalScaling(Converter.convert(getScale())); cShape.setMargin(margin); }
/** * Create a collision shape based on the scale parameter. The new shape is a * compound shape containing an offset capsule. * * @return a new compound shape (not null) */ protected CollisionShape getShape() { //TODO: cleanup size mess.. CapsuleCollisionShape capsuleCollisionShape = new CapsuleCollisionShape(getFinalRadius(), (getFinalHeight() - (2 * getFinalRadius()))); CompoundCollisionShape compoundCollisionShape = new CompoundCollisionShape(); Vector3f addLocation = new Vector3f(0, (getFinalHeight() / 2.0f), 0); compoundCollisionShape.addChildShape(capsuleCollisionShape, addLocation); return compoundCollisionShape; }
protected void createShape(){ objectId = createShape(axis, radius, height); Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId)); setScale(scale); setMargin(margin); // switch(axis){ // case 0: // objectId=new CapsuleShapeX(radius,height); // break; // case 1: // objectId=new CapsuleShape(radius,height); // break; // case 2: // objectId=new CapsuleShapeZ(radius,height); // break; // } // objectId.setLocalScaling(Converter.convert(getScale())); // objectId.setMargin(margin); }
/** * Instantiate a capsule shape around the specified main (height) axis. * * @param radius the desired radius (≥0) * @param height the desired height (of the cylindrical portion) (≥0) * @param axis which local axis: 0→X, 1→Y, 2→Z */ public CapsuleCollisionShape(float radius, float height, int axis) { this.radius=radius; this.height=height; this.axis=axis; createShape(); }
/** * Create a collision shape based on the scale parameter. The new shape is a * compound shape containing an offset capsule. * * @return a new compound shape (not null) */ protected CollisionShape getShape() { //TODO: cleanup size mess.. CapsuleCollisionShape capsuleCollisionShape = new CapsuleCollisionShape(getFinalRadius(), (getFinalHeight() - (2 * getFinalRadius()))); CompoundCollisionShape compoundCollisionShape = new CompoundCollisionShape(); Vector3f addLocation = new Vector3f(0, (getFinalHeight() / 2.0f), 0); compoundCollisionShape.addChildShape(capsuleCollisionShape, addLocation); return compoundCollisionShape; }
protected void createShape(){ objectId = createShape(axis, radius, height); Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Shape {0}", Long.toHexString(objectId)); setScale(scale); setMargin(margin); // switch(axis){ // case 0: // objectId=new CapsuleShapeX(radius,height); // break; // case 1: // objectId=new CapsuleShape(radius,height); // break; // case 2: // objectId=new CapsuleShapeZ(radius,height); // break; // } // objectId.setLocalScaling(Converter.convert(getScale())); // objectId.setMargin(margin); }
public void read(JmeImporter im) throws IOException { super.read(im); InputCapsule capsule = im.getCapsule(this); radius = capsule.readFloat("radius", 0.5f); height = capsule.readFloat("height", 0.5f); axis = capsule.readInt("axis", 1); createShape(); }
private void createCharacter() { CapsuleCollisionShape capsule = new CapsuleCollisionShape(3f, 4f); character = new CharacterControl(capsule, 0.01f); model = (Node) assetManager.loadModel("Models/Oto/OtoOldAnim.j3o"); //model.setLocalScale(0.5f); model.addControl(character); character.setPhysicsLocation(new Vector3f(-140, 40, -10)); rootNode.attachChild(model); getPhysicsSpace().add(character); }
/** * De-serialize this shape, for example when loading from a J3O file. * * @param im importer (not null) * @throws IOException from importer */ public void read(JmeImporter im) throws IOException { super.read(im); InputCapsule capsule = im.getCapsule(this); radius = capsule.readFloat("radius", 0.5f); height = capsule.readFloat("height", 0.5f); axis = capsule.readInt("axis", 1); createShape(); }
@Override public void simpleInitApp() { obstacleCollisionShape = new CapsuleCollisionShape(0.3f, 0.5f); capsuleCollisionShape = new CapsuleCollisionShape(1f, 1f); stateManager.attach(bulletAppState); capsule = new Node("capsule"); capsule.move(-2, 0, 0); capsule.addControl(new RigidBodyControl(capsuleCollisionShape, 1)); capsule.getControl(RigidBodyControl.class).setKinematic(true); bulletAppState.getPhysicsSpace().add(capsule); rootNode.attachChild(capsule); obstacle = new Node("obstacle"); obstacle.move(2, 0, 0); RigidBodyControl bodyControl = new RigidBodyControl(obstacleCollisionShape, 0); obstacle.addControl(bodyControl); bulletAppState.getPhysicsSpace().add(obstacle); rootNode.attachChild(obstacle); bulletAppState.setDebugEnabled(true); }
/** * creates a capsule shape around the given axis (0=X,1=Y,2=Z) * @param radius * @param height * @param axis */ public CapsuleCollisionShape(float radius, float height, int axis) { this.radius=radius; this.height=height; this.axis=axis; createShape(); }
@Override public void simpleInitApp() { // activate physics bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); // init a physical test scene PhysicsTestHelper.createPhysicsTestWorldSoccer(rootNode, assetManager, bulletAppState.getPhysicsSpace()); setupKeys(); // Add a physics character to the world physicsCharacter = new CharacterControl(new CapsuleCollisionShape(0.5f, 1.8f), .1f); physicsCharacter.setPhysicsLocation(new Vector3f(0, 1, 0)); characterNode = new Node("character node"); Spatial model = assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml"); model.scale(0.25f); characterNode.addControl(physicsCharacter); getPhysicsSpace().add(physicsCharacter); rootNode.attachChild(characterNode); characterNode.attachChild(model); // set forward camera node that follows the character camNode = new CameraNode("CamNode", cam); camNode.setControlDir(ControlDirection.SpatialToCamera); camNode.setLocalTranslation(new Vector3f(0, 1, -5)); camNode.lookAt(model.getLocalTranslation(), Vector3f.UNIT_Y); characterNode.attachChild(camNode); //disable the default 1st-person flyCam (don't forget this!!) flyCam.setEnabled(false); }
/** * creates a new CapsuleCollisionShape with the given radius and height * @param radius the radius of the capsule * @param height the height of the capsule */ public CapsuleCollisionShape(float radius, float height) { this.radius=radius; this.height=height; this.axis=1; createShape(); }
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(0.5f, 1.8f, 1); player3 = new CharacterControl(capsuleShape, 0.5f); player3.setJumpSpeed(20);
/** * Creates a capsule shape around the given axis (0=X,1=Y,2=Z). * @param radius * @param height * @param axis */ public CapsuleCollisionShape(float radius, float height, int axis) { this.radius=radius; this.height=height; this.axis=axis; createShape(); }