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 Example03 extends SimpleApplication { Geometry floor1, floor2, floor3; Node boxes; Geometry ball; 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); 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); } } } 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) { Example03 app = new Example03(); app.start(); } }