When physics go wild

Hi, im developing a bowling game and im stuck with the physics.



Im required (by the teachers) to use X3D format, so I've manage to add metalanguage in there to describe the physics… Running some basics test ive noticed some weird behaviours so I decided to Just test the physiscs and emulate my loader, here is the code. If you can run this you will notice that the cylinder start jumping around. Sometimes if the mood is right it evens passes throuhg the floor.






package physics;



import com.jme.bounding.BoundingBox;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jmex.game.StandardGame;
import com.jmex.game.state.BasicGameState;
import com.jmex.game.state.DebugGameState;
import com.jmex.game.state.GameStateManager;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.PhysicsDebugger;
import com.jmex.physics.StaticPhysicsNode;
import com.jmex.physics.geometry.PhysicsBox;
import com.jmex.physics.geometry.PhysicsCylinder;
import com.jmex.physics.material.Material;
import com.jmex.physics.util.states.PhysicsGameState;

public class TestPhysicsRaw {
   public static StandardGame game;// = new StandardGame("Test2");
   public static PhysicsGameState physicsGameState;// = new PhysicsGameState("Physics");

   public static void main(String[] args) {
      try {
         game = new StandardGame("Test2");
         
         game.start();
         
         BasicGameState state = new MiGameState2();
         physicsGameState = new PausedPhysics2("Physics");
            
         Spatial sp = createPhysics();
               
            
         sp.updateRenderState();
         
         state.getRootNode().attachChild(sp);
         state.getRootNode().updateRenderState();
         GameStateManager.getInstance().attachChild(state);
         GameStateManager.getInstance().attachChild(physicsGameState);
         state.setActive(true);   
         physicsGameState.setActive(true);
      } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   
   }

   private static Spatial createPhysics() {
      Node ans = new Node();
      
      ans.attachChild(createCylinderPin());
      ans.attachChild(createBoxPin());
      ans.attachChild(createFloor());
      
      ans.setModelBound(new BoundingBox());
      ans.updateModelBound();
      return ans;
   }

   private static Spatial createFloor() {
      StaticPhysicsNode group = physicsGameState.getPhysicsSpace().createStaticNode();
      
      PhysicsBox bx = group.createBox("box1");
      Vector3f box_extent = new Vector3f(25.417055f, 30.045217f, 0.247226f);
      
      bx.setLocalScale(box_extent);
      bx.setLocalTranslation(new Vector3f(0, 0, 0));
      
      group.setLocalTranslation(new Vector3f(0.325375f, -0.161774f, 4.989698f));
      group.setMaterial(Material.WOOD);
      
      group.getLocalRotation().fromAngleAxis(
            1.570796f,
                new Vector3f(-1.000000f, 0.000000f, 0.000000f));

      
      
      
      return group;
   }

   private static Spatial createBoxPin() {
      Node trans = new Node();
      
      
      DynamicPhysicsNode group = physicsGameState.getPhysicsSpace().createDynamicNode();
      PhysicsBox bx = group.createBox("box1");
      Vector3f box_extent = new Vector3f(0.12803f, 0.128031f, 0.368542f);
      
      bx.setLocalScale(box_extent);
      bx.setLocalTranslation(new Vector3f(0.0f, 0.0f, 0.184271f));
      
      group.setMaterial(Material.WOOD);
      
      trans.attachChild(group);
      trans.setLocalTranslation(new Vector3f(0.412552f, -0.000000f, -8.502293f));
      trans.getLocalRotation().fromAngleAxis(
               1.570796f,
                   new Vector3f(-1.000000f, 0.000000f, 0.000000f));
      
      return trans;
   }

   private static Spatial createCylinderPin() {
      DynamicPhysicsNode group = physicsGameState.getPhysicsSpace().createDynamicNode();
      
      PhysicsCylinder cy = group.createCylinder("cyl1");
      Vector3f cy_extent = new Vector3f(0.12803f, 0.128031f, 0.368542f);
      
      cy.setLocalScale(cy_extent);
      cy.setLocalTranslation(new Vector3f(0.0f, 0.0f, 0.184271f));
      
      group.setLocalTranslation(new Vector3f(0.412552f, 0.100000f, -6.302293f));
      group.setMaterial(Material.WOOD);
      group.getLocalRotation().fromAngleAxis(
            1.570796f,
                new Vector3f(-1.000000f, 0.000000f, 0.000000f));

      
      
      
      return group;

   }
}



class PausedPhysics2 extends PhysicsGameState {
   private boolean paused = true;
   public PausedPhysics2(String name) {
      super(name);
        /** Assign key P to action "toggle_pause". */
        KeyBindingManager.getKeyBindingManager().set("ptoggle_pause",
                KeyInput.KEY_0);
        KeyBindingManager.getKeyBindingManager().set("oneframe",
                KeyInput.KEY_9);
   }
   @Override
   public void update(float arg0) {
      // TODO Auto-generated method stub
      boolean doOneFrame;
        if (KeyBindingManager.getKeyBindingManager().isValidCommand(
                "ptoggle_pause", false)) {
            paused = !paused;
        }
        doOneFrame = KeyBindingManager.getKeyBindingManager().isValidCommand("oneframe", false);
        if (doOneFrame)
           System.out.println("OneFrame");
       
        // Si un objeto est

Ok, Im on my office right now (using windows) and that same example works flawesly. :S

maybe your other machine is slower and can't keep up with the physics updates or something along these lines.


That would explain passing through walls… but anyway thats not the case, my machine is way better than the toaster I have at work.



When I get back home I'm going to try recompiling odejava from source and removing the dust on my windows partition.



Anyways asking around a couple of college friends I found that other group is having strange behaviour with linux too.