use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.
the class RigidBodyControl method createCollisionShape.
protected void createCollisionShape() {
if (spatial == null) {
return;
}
if (spatial instanceof Geometry) {
Geometry geom = (Geometry) spatial;
Mesh mesh = geom.getMesh();
if (mesh instanceof Sphere) {
collisionShape = new SphereCollisionShape(((Sphere) mesh).getRadius());
return;
} else if (mesh instanceof Box) {
collisionShape = new BoxCollisionShape(new Vector3f(((Box) mesh).getXExtent(), ((Box) mesh).getYExtent(), ((Box) mesh).getZExtent()));
return;
}
}
if (mass > 0) {
collisionShape = CollisionShapeFactory.createDynamicMeshShape(spatial);
} else {
collisionShape = CollisionShapeFactory.createMeshShape(spatial);
}
}
use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.
the class VehicleControl method jmeClone.
@Override
public Object jmeClone() {
VehicleControl control = new VehicleControl(collisionShape, mass);
control.setAngularFactor(getAngularFactor());
control.setAngularSleepingThreshold(getAngularSleepingThreshold());
control.setAngularVelocity(getAngularVelocity());
control.setCcdMotionThreshold(getCcdMotionThreshold());
control.setCcdSweptSphereRadius(getCcdSweptSphereRadius());
control.setCollideWithGroups(getCollideWithGroups());
control.setCollisionGroup(getCollisionGroup());
control.setDamping(getLinearDamping(), getAngularDamping());
control.setFriction(getFriction());
control.setGravity(getGravity());
control.setKinematic(isKinematic());
control.setLinearSleepingThreshold(getLinearSleepingThreshold());
control.setLinearVelocity(getLinearVelocity());
control.setPhysicsLocation(getPhysicsLocation());
control.setPhysicsRotation(getPhysicsRotationMatrix());
control.setRestitution(getRestitution());
control.setFrictionSlip(getFrictionSlip());
control.setMaxSuspensionTravelCm(getMaxSuspensionTravelCm());
control.setSuspensionStiffness(getSuspensionStiffness());
control.setSuspensionCompression(tuning.suspensionCompression);
control.setSuspensionDamping(tuning.suspensionDamping);
control.setMaxSuspensionForce(getMaxSuspensionForce());
for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext(); ) {
VehicleWheel wheel = it.next();
VehicleWheel newWheel = control.addWheel(wheel.getLocation(), wheel.getDirection(), wheel.getAxle(), wheel.getRestLength(), wheel.getRadius(), wheel.isFrontWheel());
newWheel.setFrictionSlip(wheel.getFrictionSlip());
newWheel.setMaxSuspensionTravelCm(wheel.getMaxSuspensionTravelCm());
newWheel.setSuspensionStiffness(wheel.getSuspensionStiffness());
newWheel.setWheelsDampingCompression(wheel.getWheelsDampingCompression());
newWheel.setWheelsDampingRelaxation(wheel.getWheelsDampingRelaxation());
newWheel.setMaxSuspensionForce(wheel.getMaxSuspensionForce());
// Copy the wheel spatial reference directly for now. They'll
// get fixed up in the cloneFields() method
newWheel.setWheelSpatial(wheel.getWheelSpatial());
}
control.setApplyPhysicsLocal(isApplyPhysicsLocal());
control.setEnabled(isEnabled());
control.spatial = spatial;
return control;
}
use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.
the class DebugShapeFactory method getDebugMesh.
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;
}
use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.
the class DebugShapeFactory method createDebugShape.
private static Geometry createDebugShape(CollisionShape shape) {
Geometry geom = new Geometry();
geom.setMesh(DebugShapeFactory.getDebugMesh(shape));
// geom.setLocalScale(shape.getScale());
geom.updateModelBound();
return geom;
}
use of com.jme3.bullet.collision.shapes.CollisionShape in project jmonkeyengine by jMonkeyEngine.
the class HelloCollision method simpleInitApp.
public void simpleInitApp() {
/** Set up Physics */
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
//bulletAppState.getPhysicsSpace().enableDebug(assetManager);
// We re-use the flyby camera for rotation, while positioning is handled by physics
viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
flyCam.setMoveSpeed(100);
setUpKeys();
setUpLight();
// We load the scene from the zip file and adjust its size.
assetManager.registerLocator("town.zip", ZipLocator.class);
sceneModel = assetManager.loadModel("main.scene");
sceneModel.setLocalScale(2f);
// We set up collision detection for the scene by creating a
// compound collision shape and a static RigidBodyControl with mass zero.
CollisionShape sceneShape = CollisionShapeFactory.createMeshShape((Node) sceneModel);
landscape = new RigidBodyControl(sceneShape, 0);
sceneModel.addControl(landscape);
// We set up collision detection for the player by creating
// a capsule collision shape and a CharacterControl.
// The CharacterControl offers extra settings for
// size, stepheight, jumping, falling, and gravity.
// We also put the player in its starting position.
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
player = new CharacterControl(capsuleShape, 0.05f);
player.setJumpSpeed(20);
player.setFallSpeed(30);
player.setGravity(30);
player.setPhysicsLocation(new Vector3f(0, 10, 0));
// We attach the scene and the player to the rootnode and the physics space,
// to make them appear in the game world.
rootNode.attachChild(sceneModel);
bulletAppState.getPhysicsSpace().add(landscape);
bulletAppState.getPhysicsSpace().add(player);
}
Aggregations