Let's add a dynamic object to the scene to see what happens when it falls onto the platform. You already know how to create a nicely textured sphere and turn it into a physical ball.
Open PhysicsKinematic.java
again and add the following method:
private RigidBodyControl ballPhy; private static final String BALL = "Ball"; public void dropBall() { Sphere ballMesh = new Sphere(32, 32, .75f, true, false); ballMesh.setTextureMode(TextureMode.Projected); TangentBinormalGenerator.generate(ballMesh); Geometry ballGeo = new Geometry(BALL, ballMesh); ballGeo.setMaterial(stoneMat); rootNode.attachChild(ballGeo); /** Create physical ball and add to physics space. */ ballPhy = new RigidBodyControl(5f); ballGeo.addControl(ballPhy); bulletAppState.getPhysicsSpace().add(ballPhy); ballPhy.setPhysicsLocation(new Vector3f(0, 10, 0)); }
Call dropBall();
from simpleInitApp()
, and run the app. You should see the ball fall and land...