Physics, Gamestates, and Applets

So basically I'm trying to write a FPS in an applet with physics.  Not having too many troubles.  One that I'm having is enabling Physics into an applet.  Since for applets there's only SimpleJMEApplet and SimpleJMEPassApplet, I having a little trouble extending it to allow physics.  I could add the SimplePhysicsGame code to the SimpleJMEApplet code (and I have, which didn't really work for some reason, probably some small bug).  That's not really my problem, I was looking throughout more of JME2 and JME Physics and I noticed Gamestates.  I read Dark Frog's article (very nice), and understand the concept of what these Gamestates do.  My question is whether someone has actually gotten physics to work in applets, through Gamestates? Any help or code is appreciated.    :smiley:

A little side-track question… why don't you use java webstart instead of an applet? It is much more reliable, has fewer restrictions, etc.

enabling jmephysics in SimpleJMEApplet, shouldnt make too much troubles.

Just create a physics space, and render / update it.



Also make sure to update the Timer, as SimpleJmeApplet isn't doing that yet.




import com.jme.bounding.BoundingBox;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Pyramid;
import com.jme.util.Timer;
import com.jmex.awt.applet.SimpleJMEApplet;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.PhysicsSpace;
import com.jmex.physics.StaticPhysicsNode;
import com.jmex.physics.material.Material;

public class TestPhysicsApplet extends SimpleJMEApplet {
   private static final long serialVersionUID = 1L;
   private PhysicsSpace physicsSpace;
   @Override
   public void init() {
      super.init();
      physicsSpace = PhysicsSpace.create();
   }
   
   @Override
   public void simpleAppletRender() {
   }
   @Override
   public void simpleAppletSetup() {
      Box floor = new Box("floor", new Vector3f(), 50, 1, 50);
      floor.setModelBound(new BoundingBox());
      floor.updateModelBound();
      StaticPhysicsNode floorNode = physicsSpace.createStaticNode();
      floorNode.attachChild(floor);
      floorNode.setMaterial(Material.CONCRETE);
      floorNode.generatePhysicsGeometry();
      floorNode.setLocalTranslation(-20, -3, -20);
      getRootNode().attachChild(floorNode);
      
      Box box = new Box("box", new Vector3f(), 1,1,1);
      box.setModelBound(new BoundingBox());
      box.updateModelBound();
      DynamicPhysicsNode boxNode = physicsSpace.createDynamicNode();
      boxNode.attachChild(box);
      boxNode.setMaterial(Material.PLASTIC);
      boxNode.generatePhysicsGeometry();
      boxNode.computeMass();
      boxNode.setLocalTranslation(0, 30, 0);

      getRootNode().attachChild(boxNode);
      getRootNode().updateGeometricState(0, true);
   }
   
   @Override
   public void simpleAppletUpdate() {
      physicsSpace.update(Timer.getTimer().getTimePerFrame());
      Timer.getTimer().update();
   }
}

Thanks for the code that will help me a lot.  I guess this topic is still open if anyone has figured gamestates for applets.