Search in sources :

Example 1 with CollisionShape

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);
    }
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) Vector3f(com.jme3.math.Vector3f) Mesh(com.jme3.scene.Mesh) Box(com.jme3.scene.shape.Box) BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape)

Example 2 with CollisionShape

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;
}
Also used : VehicleWheel(com.jme3.bullet.objects.VehicleWheel)

Example 3 with CollisionShape

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;
}
Also used : Mesh(com.jme3.scene.Mesh)

Example 4 with CollisionShape

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;
}
Also used : Geometry(com.jme3.scene.Geometry)

Example 5 with CollisionShape

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);
}
Also used : CapsuleCollisionShape(com.jme3.bullet.collision.shapes.CapsuleCollisionShape) CollisionShape(com.jme3.bullet.collision.shapes.CollisionShape) ColorRGBA(com.jme3.math.ColorRGBA) CharacterControl(com.jme3.bullet.control.CharacterControl) BulletAppState(com.jme3.bullet.BulletAppState) Vector3f(com.jme3.math.Vector3f) CapsuleCollisionShape(com.jme3.bullet.collision.shapes.CapsuleCollisionShape) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Aggregations

CollisionShape (com.jme3.bullet.collision.shapes.CollisionShape)8 Vector3f (com.jme3.math.Vector3f)7 ChildCollisionShape (com.jme3.bullet.collision.shapes.infos.ChildCollisionShape)6 Geometry (com.jme3.scene.Geometry)6 Node (com.jme3.scene.Node)6 Matrix3f (com.jme3.math.Matrix3f)5 BoxCollisionShape (com.jme3.bullet.collision.shapes.BoxCollisionShape)4 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)4 Spatial (com.jme3.scene.Spatial)4 CompoundCollisionShape (com.jme3.bullet.collision.shapes.CompoundCollisionShape)3 Mesh (com.jme3.scene.Mesh)3 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)2 Transform (com.bulletphysics.linearmath.Transform)2 BulletAppState (com.jme3.bullet.BulletAppState)2 CapsuleCollisionShape (com.jme3.bullet.collision.shapes.CapsuleCollisionShape)2 VehicleWheel (com.jme3.bullet.objects.VehicleWheel)2 Transform (com.jme3.math.Transform)2 Box (com.jme3.scene.shape.Box)2 TempVars (com.jme3.util.TempVars)2 ConcaveShape (com.bulletphysics.collision.shapes.ConcaveShape)1