Search in sources :

Example 31 with Plane

use of com.jme3.math.Plane in project jmonkeyengine by jMonkeyEngine.

the class TestLocalPhysics method simpleInitApp.

@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    // Add a physics sphere to the world
    Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
    physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
    physicsSphere.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
    rootNode.attachChild(physicsSphere);
    getPhysicsSpace().add(physicsSphere);
    // Add a physics sphere to the world using the collision shape from sphere one
    Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, physicsSphere.getControl(RigidBodyControl.class).getCollisionShape(), 1);
    physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0));
    physicsSphere2.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
    rootNode.attachChild(physicsSphere2);
    getPhysicsSpace().add(physicsSphere2);
    // Add a physics box to the world
    Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1);
    physicsBox.getControl(RigidBodyControl.class).setFriction(0.1f);
    physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f));
    physicsBox.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
    rootNode.attachChild(physicsBox);
    getPhysicsSpace().add(physicsBox);
    // Add a physics cylinder to the world
    Node physicsCylinder = PhysicsTestHelper.createPhysicsTestNode(assetManager, new CylinderCollisionShape(new Vector3f(1f, 1f, 1.5f)), 1);
    physicsCylinder.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2, 2, 0));
    physicsCylinder.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
    rootNode.attachChild(physicsCylinder);
    getPhysicsSpace().add(physicsCylinder);
    // an obstacle mesh, does not move (mass=0)
    Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
    node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f));
    node2.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
    rootNode.attachChild(node2);
    getPhysicsSpace().add(node2);
    // the floor mesh, does not move (mass=0)
    Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0);
    node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
    node3.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true);
    rootNode.attachChild(node3);
    getPhysicsSpace().add(node3);
// Join the physics objects with a Point2Point joint
//        PhysicsPoint2PointJoint joint=new PhysicsPoint2PointJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0));
//        PhysicsHingeJoint joint=new PhysicsHingeJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0), Vector3f.UNIT_Z,Vector3f.UNIT_Z);
//        getPhysicsSpace().add(joint);
}
Also used : Sphere(com.jme3.scene.shape.Sphere) Plane(com.jme3.math.Plane) BulletAppState(com.jme3.bullet.BulletAppState) Node(com.jme3.scene.Node) Vector3f(com.jme3.math.Vector3f) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 32 with Plane

use of com.jme3.math.Plane in project jmonkeyengine by jMonkeyEngine.

the class PlaneCollisionShape method write.

public void write(JmeExporter ex) throws IOException {
    super.write(ex);
    OutputCapsule capsule = ex.getCapsule(this);
    capsule.write(plane, "collisionPlane", new Plane());
}
Also used : OutputCapsule(com.jme3.export.OutputCapsule) Plane(com.jme3.math.Plane)

Example 33 with Plane

use of com.jme3.math.Plane in project jmonkeyengine by jMonkeyEngine.

the class PlaneCollisionShape method read.

public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule capsule = im.getCapsule(this);
    plane = (Plane) capsule.readSavable("collisionPlane", new Plane());
    createShape();
}
Also used : Plane(com.jme3.math.Plane) InputCapsule(com.jme3.export.InputCapsule)

Aggregations

Vector3f (com.jme3.math.Vector3f)20 Plane (com.jme3.math.Plane)9 Sphere (com.jme3.scene.shape.Sphere)7 TempVars (com.jme3.util.TempVars)7 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)6 Material (com.jme3.material.Material)6 Geometry (com.jme3.scene.Geometry)6 Node (com.jme3.scene.Node)6 BulletAppState (com.jme3.bullet.BulletAppState)4 Quad (com.jme3.scene.shape.Quad)4 MeshCollisionShape (com.jme3.bullet.collision.shapes.MeshCollisionShape)3 Box (com.jme3.scene.shape.Box)3 CollisionResult (com.jme3.collision.CollisionResult)2 AmbientLight (com.jme3.light.AmbientLight)2 DirectionalLight (com.jme3.light.DirectionalLight)2 Triangle (com.jme3.math.Triangle)2 Camera (com.jme3.renderer.Camera)2 Spatial (com.jme3.scene.Spatial)2 Structure (com.jme3.scene.plugins.blender.file.Structure)2 Texture (com.jme3.texture.Texture)2