• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * To change this template, choose Tools | Templates
3  * and open the template in the editor.
4  */
5 package jme3test.bullet;
6 
7 import com.jme3.app.SimpleApplication;
8 import com.jme3.bullet.BulletAppState;
9 import com.jme3.bullet.PhysicsSpace;
10 import com.jme3.bullet.collision.shapes.MeshCollisionShape;
11 import com.jme3.bullet.collision.shapes.PlaneCollisionShape;
12 import com.jme3.bullet.collision.shapes.SphereCollisionShape;
13 import com.jme3.bullet.control.RigidBodyControl;
14 import com.jme3.math.Plane;
15 import com.jme3.math.Vector3f;
16 import com.jme3.scene.Node;
17 import com.jme3.scene.shape.Sphere;
18 
19 /**
20  *
21  * @author Nehon
22  */
23 public class TestKinematicAddToPhysicsSpaceIssue extends SimpleApplication {
24 
main(String[] args)25     public static void main(String[] args) {
26         TestKinematicAddToPhysicsSpaceIssue app = new TestKinematicAddToPhysicsSpaceIssue();
27         app.start();
28     }
29     BulletAppState bulletAppState;
30 
31     @Override
simpleInitApp()32     public void simpleInitApp() {
33 
34         bulletAppState = new BulletAppState();
35         stateManager.attach(bulletAppState);
36         bulletAppState.getPhysicsSpace().enableDebug(assetManager);
37         // Add a physics sphere to the world
38         Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
39         physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
40         rootNode.attachChild(physicsSphere);
41 
42         //Setting the rigidBody to kinematic before adding it to the physic space
43         physicsSphere.getControl(RigidBodyControl.class).setKinematic(true);
44         //adding it to the physic space
45         getPhysicsSpace().add(physicsSphere);
46         //Making it not kinematic again, it should fall under gravity, it doesn't
47         physicsSphere.getControl(RigidBodyControl.class).setKinematic(false);
48 
49         // Add a physics sphere to the world using the collision shape from sphere one
50         Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
51         physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(5, 6, 0));
52         rootNode.attachChild(physicsSphere2);
53 
54         //Adding the rigid body to physic space
55         getPhysicsSpace().add(physicsSphere2);
56         //making it kinematic
57         physicsSphere2.getControl(RigidBodyControl.class).setKinematic(false);
58         //Making it not kinematic again, it works properly, the rigidbody is affected by grvity.
59         physicsSphere2.getControl(RigidBodyControl.class).setKinematic(false);
60 
61 
62 
63         // an obstacle mesh, does not move (mass=0)
64         Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
65         node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f));
66         rootNode.attachChild(node2);
67         getPhysicsSpace().add(node2);
68 
69         // the floor mesh, does not move (mass=0)
70         Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0);
71         node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
72         rootNode.attachChild(node3);
73         getPhysicsSpace().add(node3);
74 
75     }
76 
getPhysicsSpace()77     private PhysicsSpace getPhysicsSpace() {
78         return bulletAppState.getPhysicsSpace();
79     }
80 }
81