use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.
the class CompoundCollisionShape method addChildShape.
/**
* 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());
}
use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.
the class PhysicsTestHelper method createPhysicsTestNode.
/**
* creates an empty node with a RigidBodyControl
* @param manager
* @param shape
* @param mass
* @return
*/
public static Node createPhysicsTestNode(AssetManager manager, CollisionShape shape, float mass) {
Node node = new Node("PhysicsNode");
RigidBodyControl control = new RigidBodyControl(shape, mass);
node.addControl(control);
return node;
}
use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.
the class TestHoveringTank method buildPlayer.
private void buildPlayer() {
spaceCraft = assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");
CollisionShape colShape = CollisionShapeFactory.createDynamicMeshShape(spaceCraft);
spaceCraft.setShadowMode(ShadowMode.CastAndReceive);
spaceCraft.setLocalTranslation(new Vector3f(-140, 50, -23));
spaceCraft.setLocalRotation(new Quaternion(new float[] { 0, 0.01f, 0 }));
hoverControl = new PhysicsHoverControl(colShape, 500);
spaceCraft.addControl(hoverControl);
rootNode.attachChild(spaceCraft);
getPhysicsSpace().add(hoverControl);
hoverControl.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
spaceCraft.addControl(chaseCam);
flyCam.setEnabled(false);
}
use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.
the class TestGhostObject method simpleInitApp.
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
// Mesh to be shared across several boxes.
Box boxGeom = new Box(1f, 1f, 1f);
// CollisionShape to be shared across several boxes.
CollisionShape shape = new BoxCollisionShape(new Vector3f(1, 1, 1));
Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, shape, 1);
physicsBox.setName("box0");
physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f));
rootNode.attachChild(physicsBox);
getPhysicsSpace().add(physicsBox);
Node physicsBox1 = PhysicsTestHelper.createPhysicsTestNode(assetManager, shape, 1);
physicsBox1.setName("box1");
physicsBox1.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0, 40, 0));
rootNode.attachChild(physicsBox1);
getPhysicsSpace().add(physicsBox1);
Node physicsBox2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1);
physicsBox2.setName("box0");
physicsBox2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.5f, 80, -.8f));
rootNode.attachChild(physicsBox2);
getPhysicsSpace().add(physicsBox2);
// the floor, does not move (mass=0)
Node node = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(100, 1, 100)), 0);
node.setName("floor");
node.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
rootNode.attachChild(node);
getPhysicsSpace().add(node);
initGhostObject();
}
use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.
the class BetterCharacterControl method getShape.
/**
* Gets a new collision shape based on the current scale parameter. The
* created collisionshape is a capsule collision shape that is attached to a
* compound collision shape with an offset to set the object center at the
* bottom of the capsule.
*
* @return
*/
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;
}
Aggregations