Moving from simplegame to basegame physics stopped working

I was able to get physics working in simplegame no prob but when i try it in basegame the box doesnt fall.

Im pretty new to programming so i assume im missing something simple, here is the code…

any help would be greatly appreciated




package main;

import com.jme.app.BaseGame;
import com.jme.bounding.BoundingBox;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.util.Timer;
import com.jmex.physics.DynamicPhysicsObject;
import com.jmex.physics.PhysicsObject;
import com.jmex.physics.PhysicsWorld;
import com.jmex.physics.StaticPhysicsObject;

public class DiceGame extends BaseGame {
   protected Timer timer;
   private Camera cam;
   private Node scene;   
   private int width, height, depth, freq;
   private boolean fullscreen;
   
   public static void main(String[] args) {
      DiceGame app = new DiceGame();
      app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG, DiceGame.class.getClassLoader()
            .getResource("diceLogo2.png"));
      app.start();
   }
 
   protected void initSystem() {
      
      width = properties.getWidth();
      height = properties.getHeight();
      depth = properties.getDepth();
      freq = properties.getFreq();
      fullscreen = properties.getFullscreen();
      
      try {
         display = DisplaySystem.getDisplaySystem(properties.getRenderer());
         display.createWindow(width, height, depth, freq, fullscreen);
 
         cam = display.getRenderer().createCamera(width, height);
      } catch (JmeException e) {
         e.printStackTrace();
         System.exit(1);
      }
 
      //set the background to black
      display.getRenderer().setBackgroundColor(ColorRGBA.black);
      
      //initialize the camera
      cam.setFrustumPerspective(45.0f, (float)width / (float)height, 1, 1000);
      Vector3f loc = new Vector3f(0.0f, 0.0f, 25.0f);
      Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
      Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
      Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);
      // Move our camera to a correct place and orientation.
      cam.setFrame(loc, left, up, dir);
      /** Signal that we've changed our camera's location/frustum. */
      cam.update();
      display.getRenderer().setCamera(cam);
       /** Get a high resolution timer for FPS updates. */
       timer = Timer.getTimer(properties.getRenderer());
 
      KeyBindingManager.getKeyBindingManager().set("exit",
            KeyInput.KEY_ESCAPE);
      
      PhysicsWorld.create();
      PhysicsWorld.getInstance().setUpdateRate(100);
      PhysicsWorld.getInstance().setStepSize(2f/100f);   
   }
 
   protected void initGame() {
   
      scene = new Node("Scene graph node");
   
      buildPhysicsBox();
      
      scene.updateGeometricState(0.0f, true);
      scene.updateRenderState();
      
   }
   private void buildPhysicsBox(){
      
      
      Box floorGraphics = new Box("Floor", new Vector3f(), 50, 1, 50);
      //floorGraphics.setModelBound(new BoundingBox());
      //floorGraphics.updateModelBound();
      floorGraphics.setLocalTranslation(new Vector3f(0, -14, 10));
         
      Box b = new Box("b", new Vector3f(), 10, 10, 10);
      b.setLocalTranslation(new Vector3f(0, 0, -40));
      b.setModelBound(new BoundingBox());
      b.updateModelBound();
      
      scene.attachChild(b);
      scene.attachChild(floorGraphics);
      
      PhysicsObject floorPhysics = new StaticPhysicsObject(floorGraphics);
      PhysicsObject dice1Physics = new DynamicPhysicsObject(b, 10f);
      
      PhysicsWorld.getInstance().addObject(dice1Physics);
      PhysicsWorld.getInstance().addObject(floorPhysics);
            
   }
 
   
   protected void reinit() {
      display.recreateWindow(width, height, depth, freq, fullscreen);
   }
 
   
   protected void cleanup() {
      
      PhysicsWorld.getInstance().cleanup();
   }
   protected void update(float interpolation) {
      
      timer.update();
      interpolation = timer.getTimePerFrame();
      
      PhysicsWorld.getInstance().update(timer.getTimePerFrame());
      //if escape was pressed, we exit
      if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
         finished = true;
      }
      
   }
 
   protected void render(float interpolation) {
   
      display.getRenderer().clearBuffers();
 
      display.getRenderer().draw(scene);
      
   }
}

Hmmm, looks alright to me.  I would try it on my machine, but it will have to wait until this evening.



darkfrog

:smiley: ok i figured it out. I was missing this line in the update method


scene.updateGeometricState(timer.getTimePerFrame(), true);

Hehe, I was looking for a physics issue. :)  Good debugging. :wink:



darkfrog