PhysicsSystem and FixedLogicrateGame issues

yer it has been commited, per did that about half an hour ago…maybe more…



because youve’ updated the file locally, eclipse might just skim over it, i suggest you do an update specifically on that file and if it doesn’t work…keep trying!



DP

Well I wiped out my jmePhysics project and redownloaded the whole thing and I still didn’t get the fix. GO figure. Maybe it takes a while to update?



Any ideas as to why the thruster might still be lagging?

Well I wiped out my jmePhysics project and redownloaded the whole thing and I still didn't get the fix. GO figure. Maybe it takes a while to update?

Rightclick on your DynamicPhysicsObject file, and select Replace With -> Latest from HEAD. Does it work? It does for me.

Any ideas as to why the thruster might still be lagging?

Why don't you try and make your ship a node, and just passing that into the DynamicPhysicsObject constructor? Then you could attach that jet of yours on that.

Hope that helps!
Why don't you try and make your ship a node, and just passing that into the DynamicPhysicsObject constructor? Then you could attach that jet of yours on that.


That's what I originally wanted to do but couldn't figure out how that would work. Right now i load a jme model into a LoaderNode. I then parse the LoaderNode to extract the ship Geometry into shipGeo. I then pass that into DynamicPhysicsObject to create my physics object.

Since you can't attach children to Geometry I couldn't directly attach the thrusters to the ship. I thought maybe I could attach the shipGeo to a shipNode and then attach the thrusters to the shipNode but that doesn't seem like it would work.

Since the PhysicsSystem updates the geometry directly the shipNode wouldn't change so the thruster wouldn't move. At least that's what I thought and is what happened in my limited testing.

Am I incorrect here?

Also doing the Replace with -> Latest from HEAD didn't work :/ My DynamicPhysicsObject file is still at version 1.5

Oh, forgot this was a new feature - v.04 brings you compounded objects, meaning that you can pass in a Node, and it’ll automatically get stripped for geometetry, adding to the body.



However, I also forgot that we have some tiny weenie problem with this one - the local translation of the children isn’t taken into consideration, and the initial translation of the node itself always get set to 0,0,0 :(. We hope to get this finished very soon though (maybe tonight).


Also doing the Replace with -> Latest from HEAD didn't work :/ My DynamicPhysicsObject file is still at version 1.5


Strange stuff as it's even browsable here:
http://cvs.sourceforge.net/viewcvs.py/jme-physics/jmephysics/src/com/jmex/physics/

I'd try doing a fresh checkout, and if that doesn't help... well... :?

Well when I woke up this morning the first thing I did was try a cvs update and it worked heh. Go figure.



As far as the new “being able to pass a node to DynamicPhysicsObject” DarkProphet mentioned that a while back and I couldn’t wait to try it out.



Would you do something along the lines of:


// Create the Ship
        shipNode = new LoaderNode("my ship");
        try {
            ship.loadFromFilePath("binary", "spaceship.jme", new HashMap());
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        DynamicPhysicsObject shipObj = new DynamicPhysicsObject(shipNode, 50f);
        shipNode.attachChild(thrusters);



Then updates to shipObj will include shipNode so that will effect my thrusters?

yer, pretty much :slight_smile:



DP

I was messing around with the new “load a node” feature and ran into a stumbling block. If I just pass in my LoaderNode everything works great. However, when I try to attach an object to that LoderNode it doesn’t show up. I modified the SimpleTest to try and recreate the problem.



public class SimpleTest extends SimpleGame {
   
   private DynamicPhysicsObject shipPhysics;
   
   /**
    * Inits everything needed for this test.
    */
   protected void simpleInitGame() {
      display.setTitle("Simple Test");
      
      // Set up the PhysicsWorld. It's set with a couple of default
      // values, e.g. Earths gravity.
      PhysicsWorld.create();
      
      // Here we tell the PhysicsWorld how many times per second we would like to
      // update it. It'll make the PhysicsWorlds internal timer govern the frequency
      // of update calls, thus obtaining frame rate independance. We set it to
      // 100 updates per second - the default is no restriction.
      PhysicsWorld.getInstance().setUpdateRate(100);
      
      // Here we tell the PhysicsWorld how much should change with each update.
      // A bigger value -> faster animation. A step size of 2/UPS (updates/sec)
      // seem to give a rather nice simulation/result.
      PhysicsWorld.getInstance().setStepSize(2/100f);
      
      // Creates the box that makes out the floor.
      Box floorGraphics = new Box("Floor", new Vector3f(), 50, 1, 50);      

      // We move it down 5 units, and away from the camera 10 units.
      floorGraphics.setLocalTranslation(new Vector3f(0, -5, 10));
      
      // In order to add it to the PhysicsWorld we need to create a PhysicsObject
      // from it. Note that we don't pass a mass in the constructor. This is because
      // it's static.
      StaticPhysicsObject floorPhysics = new StaticPhysicsObject(floorGraphics);
      
      // Creates the box that falls down on the floor.
      Box boxGraphics = new Box("Box", new Vector3f(), 1f, 1f, 1f);
      // Move the box over 5
      boxGraphics.setLocalTranslation(new Vector3f(5,0,0));
      
      // Load our model
        LoaderNode shipNode = new LoaderNode("my ship");
        try {
            shipNode.loadFromFilePath("binary", "spaceship.jme", new HashMap());
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        shipNode.setLocalScale(.01f);
       
       
      // We move it 10 units up, and 10 units away from the camera.
      shipNode.setLocalTranslation(new Vector3f(-10, 10, 10));
      
      // Create a dynamic physics object from it. Because it is dynamic, we need to
      // provide it with a mass.
      shipPhysics = new DynamicPhysicsObject(shipNode, 1f);
      
      // Attach the box to the shipNode so it should follow the box's path
      shipNode.attachChild(boxGraphics);
      
      // Add the graphical representations to the rootNode. You could also get
      // references to them by calling PhysicsObject.getSpatial().
      rootNode.attachChild(floorGraphics);
      rootNode.attachChild(shipNode);
      
      // And the physical representations to the PhysicsWorld.
      PhysicsWorld.getInstance().addObject(floorPhysics);
      PhysicsWorld.getInstance().addObject(shipPhysics);
   }
   
   /**
    * Gets called on application ending.
    */
   protected void cleanup() {
      super.cleanup();
      // Before ending your application you should always clean up the PhysicsWorld.
      PhysicsWorld.getInstance().cleanup();
   }
   
   /**
    * Gets called every frame.
    */
   protected void simpleUpdate() {
      // We must call this method in order to make the simulation step forward. It doesn't
      // matter how many times per second we make the call, as long as we have a
      // FPS >= the updaterate we've given the PhysicsWorld. This is because of the
      // PhysicsWorlds internal timer, that govern the frequency of actual updates.
      PhysicsWorld.getInstance().update(tpf);
   }
   
   public static void main(String[] args) {
      SimpleTest app = new SimpleTest();
      app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG,
            SimpleTest.class
            .getClassLoader().getResource
            ("jmextest/data/images/jmephysics_logo.png"));
      app.start();
   }
}



Am I doing this right or am I confused about what you can and cannot do?

If you want to try it out with my model you can get it http://www.mekamedia.com/spaceship.jme

well, this works fine with me. I obviously dont have your code about LoaderNode…but the code below works:



public class SimpleTest extends SimpleGame {

   private DynamicPhysicsObject shipPhysics;

   /**
    * Inits everything needed for this test.
    */
   protected void simpleInitGame() {
      display.setTitle("Simple Test");

      // Set up the PhysicsWorld. It's set with a couple of default
      // values, e.g. Earths gravity.
      PhysicsWorld.create();

      // Here we tell the PhysicsWorld how many times per second we would like
      // to
      // update it. It'll make the PhysicsWorlds internal timer govern the
      // frequency
      // of update calls, thus obtaining frame rate independance. We set it to
      // 100 updates per second - the default is no restriction.
      PhysicsWorld.getInstance().setUpdateRate(100);

      // Here we tell the PhysicsWorld how much should change with each
      // update.
      // A bigger value -> faster animation. A step size of 2/UPS
      // (updates/sec)
      // seem to give a rather nice simulation/result.
      PhysicsWorld.getInstance().setStepSize(2 / 100f);

      // Creates the box that makes out the floor.
      Box floorGraphics = new Box("Floor", new Vector3f(), 50, 1, 50);

      // We move it down 5 units, and away from the camera 10 units.
      floorGraphics.setLocalTranslation(new Vector3f(0, -5, 10));

      // In order to add it to the PhysicsWorld we need to create a
      // PhysicsObject
      // from it. Note that we don't pass a mass in the constructor. This is
      // because
      // it's static.
      StaticPhysicsObject floorPhysics = new StaticPhysicsObject(
            floorGraphics);

      // Creates the box that falls down on the floor.
      Box boxGraphics = new Box("Box", new Vector3f(), 1f, 1f, 1f);
      // Move the box over 5 and 3
      boxGraphics.setLocalTranslation(new Vector3f(5, 3, 0));

      // Load our model
      Node shipNode = new Node("my Ship");
      Box shipBox = new Box("my ship", new Vector3f(), 1, 1, 1);
      shipNode.attachChild(shipBox);

      // We move it 10 units up, and 10 units away from the camera.
      shipNode.setLocalTranslation(new Vector3f(-10, 10, 10));

      // Create a dynamic physics object from it. Because it is dynamic, we
      // need to
      // provide it with a mass.
      shipPhysics = new DynamicPhysicsObject(shipNode, 1f);

      // Attach the box to the shipNode so it should follow the box's path
      shipNode.attachChild(boxGraphics);

      // Add the graphical representations to the rootNode. You could also get
      // references to them by calling PhysicsObject.getSpatial().
      rootNode.attachChild(floorGraphics);
      rootNode.attachChild(shipNode);

      // And the physical representations to the PhysicsWorld.
      PhysicsWorld.getInstance().addObject(floorPhysics);
      PhysicsWorld.getInstance().addObject(shipPhysics);
   }

   /**
    * Gets called on application ending.
    */
   protected void cleanup() {
      super.cleanup();
      // Before ending your application you should always clean up the
      // PhysicsWorld.
      PhysicsWorld.getInstance().cleanup();
   }

   /**
    * Gets called every frame.
    */
   protected void simpleUpdate() {
      // We must call this method in order to make the simulation step
      // forward. It doesn't
      // matter how many times per second we make the call, as long as we have
      // a
      // FPS >= the updaterate we've given the PhysicsWorld. This is because
      // of the
      // PhysicsWorlds internal timer, that govern the frequency of actual
      // updates.
      PhysicsWorld.getInstance().update(tpf);
   }

   public static void main(String[] args) {
      SimpleTest app = new SimpleTest();
      app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG, SimpleTest.class
            .getClassLoader().getResource(
                  "jmextest/data/images/jmephysics_logo.png"));
      app.start();
   }
}



DP
I obviously dont have your code about LoaderNode


LoaderNode is part of jME :)

I thought it was the correct way to load jME models due to this post

http://www.jmonkeyengine.com/jmeforum/viewtopic.php?t=1353&postdays=0&postorder=asc&start=0

oh…fair enough…i load em up using JmeBinaryReader instead…



Yeah the problem was I was setting the scale of the shipNode to shrink my model down but that was also being applied to the box so the box became suuuuuuper tiny and I couldn’t see it.



How can I scale the shipNode without it affecting any of the nodes attached to it??

if setting the scale of the shipNode affected none of the children of that node, it would basically have no affect on anything (including your ship.) What you want to do is either apply the scale further down the graph on your ship, or add a parent to the ship node and attach the box to that and do translation, rotation or whatnot on that new node.

f setting the scale of the shipNode affected none of the children of that node, it would basically have no affect on anything (including your ship.) What you want to do is either apply the scale further down the graph on your ship, or add a parent to the ship node and attach the box to that and do translation, rotation or whatnot on that new node.


doh :// I should have known that haha. Sorry for the dumb question.

or you could scale up your box by 100 :slight_smile:



DP

Okay … I’ve put together a little test program to show off what I think might be a problem (again this could just be me :wink: )



Basically my hierarchy looks like this



RootNode -> ShipNode -> ShipModel



The idea here is that anything you want to follow the ship can be added to ShipNode. (e.g., thrusters)



I then create a DynamicPhysicsObject by passing it ShipNode. If I add this physicsObject to the PhysicsWorld nothing is rendered at all. If I don’t add it everything is rendered fine but no physics (obviously).



If I create the DynamicPhysicsObject using ShipModel instead of ShipNode the geometry is all rendered but no physics.



Here’s a link to my spaceship.jme model just in case anyone needs it or wants to use it.



www.mekamedia.com/spaceship.jme



My guess is it’s a scaling issue? Like the physicsObject doesn’t account for rescaling of the subnodes? Maybe not.



Here is my code.


import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;

import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.model.XMLparser.JmeBinaryReader;
import com.jme.scene.shape.Box;
import com.jme.util.LoggingSystem;
import com.jmex.physics.DynamicPhysicsObject;
import com.jmex.physics.PhysicsWorld;
import com.jmex.physics.StaticPhysicsObject;

public class SimpleTest extends SimpleGame {

    private DynamicPhysicsObject shipPhysics;

    /**
     * Inits everything needed for this test.
     */
    protected void simpleInitGame() {
       display.setTitle("Simple Test");
       PhysicsWorld.create();
       PhysicsWorld.getInstance().setUpdateRate(100);
       PhysicsWorld.getInstance().setStepSize(2 / 100f);

       // Creates the box that makes out the floor.
       Box floorGraphics = new Box("Floor", new Vector3f(), 50, 1, 50);
       // We move it down 5 units, and away from the camera 10 units.
       floorGraphics.setLocalTranslation(new Vector3f(0, -5, 10));
       // Create static physics object
       StaticPhysicsObject floorPhysics = new StaticPhysicsObject(floorGraphics);

       // shipNode is the parent node for the shipModel and thrusterNode
       Node shipNode = new Node("my Ship");
       shipNode.setLocalTranslation(new Vector3f(0,0,0));
       
       Node shipModel = new Node();
       try {
          JmeBinaryReader jbr = new JmeBinaryReader();
          InputStream loaderInput=new File("spaceship.jme").toURI().toURL().openStream();
          shipModel = jbr.loadBinaryFormat(loaderInput);
       } catch (IOException ioe) {
          LoggingSystem.getLogger().log(Level.WARNING,
                "Could not load model: ");
       }
       // Shrink the model down
       shipModel.setLocalScale(.01f);
       
       // Attach our shipModel to the shipNode
       shipNode.attachChild(shipModel);
 
       // We move it 10 units up, and 10 units away from the camera.
       shipNode.setLocalTranslation(new Vector3f(0, 0, 10));
       
       // Create a dynamic physics object from it. Because it is dynamic, we
       // need to provide it with a mass.
       shipPhysics = new DynamicPhysicsObject(shipNode, 1f);

       // Add the graphical representations to the rootNode. You could also get
       // references to them by calling PhysicsObject.getSpatial().
       rootNode.attachChild(floorGraphics);
       rootNode.attachChild(shipNode);

       // And the physical representations to the PhysicsWorld.
       PhysicsWorld.getInstance().addObject(floorPhysics);
       /* NOTE
        * If you comment out the below line the ship shows up no problem.  When you put it in
        * no geometry is drawn
        */
       PhysicsWorld.getInstance().addObject(shipPhysics);
    }

    /**
     * Gets called on application ending.
     */
    protected void cleanup() {
       super.cleanup();
       PhysicsWorld.getInstance().cleanup();
    }

    /**
     * Gets called every frame.
     */
    protected void simpleUpdate() {
       PhysicsWorld.getInstance().update(tpf);
    }

    public static void main(String[] args) {
       SimpleTest app = new SimpleTest();
       app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG, SimpleTest.class
             .getClassLoader().getResource(
                   "jmextest/data/images/jmephysics_logo.png"));
       app.start();
    }
 }



Any ideas? Once agian thank you for all the help.

Your problems sure seem strange… I havn’t looked into them though as I’ve spent several hours today trying to fix those compounded objects - the problem seems to more well hidden than I first thought… dang - I really thought this one was going to be easy :frowning:



Now both me and DP are working on fixing this…



Just wanted to give you an update so that you wouldn’t think we’d given up on this :slight_smile:

Thanks! You guys are great. :smiley:

Getting closer… there was an odejava class we removed some time ago (GeomTransform) that has a vital role in compounded objects. Just some math-lib conversion job left to do…

Thanks Per … Can’t wait to get my hands on it