package lecture18; import com.jme3.app.SimpleApplication; import com.jme3.bullet.BulletAppState; import com.jme3.bullet.control.RigidBodyControl; import com.jme3.light.DirectionalLight; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; import com.jme3.scene.Geometry; import com.jme3.scene.Node; import com.jme3.scene.shape.Sphere; public class Example04 extends SimpleApplication { Geometry floor1, floor2, floor3; Node boxes; Geometry redBall; Vector3f floor2Normal = new Vector3f(-1f, 2f, 0).normalize(); Vector3f floor3Normal = new Vector3f(1f, 2f, 0).normalize(); private BulletAppState bulletAppState; public void simpleInitApp() { bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); bulletAppState.getPhysicsSpace().setGravity(Vector3f.ZERO); DirectionalLight sun = new DirectionalLight(); sun.setDirection(new Vector3f(1, -5, -7)); sun.setColor(ColorRGBA.White); rootNode.addLight(sun); Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); mat.setBoolean("UseMaterialColors", true); mat.setColor("Ambient", ColorRGBA.White); mat.setColor("Diffuse", ColorRGBA.White); Sphere s = new Sphere(60, 60, 1f); int size = 10; for (int i = 0; i < size; i++){ for (int j = 0; j < size; j++) { for(int k = 0; k < size; k++) { Geometry ballG = new Geometry("Sphere", s); ballG.setMaterial(mat); ballG.move(i*2f, j*2f, k*2f); RigidBodyControl ballControl = new RigidBodyControl(1f); ballG.addControl(ballControl); ballControl.setRestitution(.8f); ballControl.setFriction(2); ballControl.setDamping(0, 0.1f); ballControl.setGravity(new Vector3f(0,0,0)); bulletAppState.getPhysicsSpace().add(ballControl); rootNode.attachChild(ballG); } } } redBall = new Geometry("Sphere", s); Material red = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); red.setBoolean("UseMaterialColors", true); red.setColor("Ambient", ColorRGBA.Red); red.setColor("Diffuse", ColorRGBA.Red); redBall.setMaterial(red); redBall.move(5f, 5f, 50); RigidBodyControl redBallControl = new RigidBodyControl(100f); redBall.addControl(redBallControl); redBallControl.setRestitution(.8f); redBallControl.setFriction(2); redBallControl.setDamping(0, 0.1f); redBallControl.setLinearVelocity(new Vector3f(1,1,-20f)); bulletAppState.getPhysicsSpace().add(redBallControl); rootNode.attachChild(redBall); cam.setLocation(new Vector3f(0, 10, 100)); cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y); } @Override public void simpleUpdate(float tpf) { } public static void main(String[] args) { Example04 app = new Example04(); app.start(); } }