Hi
I have been trying to run a simple physics example involving a box and a floor, but I can't get it to work. The program refuses to run unless I have commented out
PhysicsWorld.getInstance().addObject(boxPhysics);
Any ideas about what causes this or how to fix it?
The error message:
INFO: Child (Box) attached to this node (rootNode)
Jan 7, 2006 2:57:16 PM com.jmex.physics.PhysicsWorld addObject
INFO: Physics Object (Floor) has been added to the PhysicsWorld
Jan 7, 2006 2:57:16 PM com.jmex.physics.PhysicsWorld addObject
INFO: Physics Object (Box) has been added to the PhysicsWorld
java.lang.NoSuchMethodError: com.jme.math.Quaternion.set(Lcom/jme/math/Quaternion;)V
at com.jmex.physics.PhysicsSynchronizer.update(PhysicsSynchronizer.java:86)
at com.jme.scene.Spatial.updateWorldData(Unknown Source)
at com.jme.scene.Spatial.updateGeometricState(Unknown Source)
at com.jme.scene.Node.updateWorldData(Unknown Source)
at com.jme.scene.Spatial.updateGeometricState(Unknown Source)
at com.jme.app.SimpleGame.initGame(Unknown Source)
at com.jme.app.BaseGame.start(Unknown Source)
at TestSphere.main(TestSphere.java:90)
Jan 7, 2006 2:57:16 PM com.jme.app.SimpleGame cleanup
INFO: Cleaning up resources.
Jan 7, 2006 2:57:16 PM com.jme.app.BaseGame start
INFO: Application ending.
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# SIGSEGV (0xb) at pc=0xb1783198, pid=8364, tid=2978839472
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode, sharing)
# Problematic frame:
# C 0xb1783198
The code, "borrowed" from someone else on this forum
import org.odejava.Odejava;
import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;
import com.jmex.physics.DynamicPhysicsObject;
import com.jmex.physics.PhysicsObject;
import com.jmex.physics.PhysicsWorld;
import com.jmex.physics.StaticPhysicsObject;
public class TestSphere extends SimpleGame {
Box boxGraphics;
DynamicPhysicsObject boxPhysics;
protected void simpleInitGame() {
display.setTitle("Simple Test");
// Set up the PhysicsWorld. It's got a couple of default
// values, e.g. Earths gravity.
Odejava.init();
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 leads to a faster animation. A step size
// of 2/UPS (updates/sec) seem to give a rather nice simulation/result.
// PhysicsWorld.getInstance().setStepSize(2f/100f);
// Creates the box that makes out the floor (graphics only).
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));
// Add the graphical representations to the rootNode. You could also get
// references to them by calling PhysicsObject.getSpatial().
rootNode.attachChild(floorGraphics);
// 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.
PhysicsObject floorPhysics = new StaticPhysicsObject(floorGraphics);
// Creates the box that falls down on the floor.
boxGraphics = new Box("Box", new Vector3f(), 1f, 1f, 1f);
// We move it 10 units up, and 10 units away from the camera.
boxGraphics.setLocalTranslation(new Vector3f(-10, 10, 10));
// Attach the graphical representation to the scene.
rootNode.attachChild(boxGraphics);
// Create a dynamic physics object from it. Because it is dynamic, we
// need to provide it with a mass.
boxPhysics = new DynamicPhysicsObject(boxGraphics, 1f);
com.jme.math.Quaternion q = new com.jme.math.Quaternion();
q.set(1,1,1,1);
PhysicsWorld.getInstance().addObject(floorPhysics);
// PhysicsWorld.getInstance().addObject(boxPhysics);
}
protected void cleanup() {
super.cleanup();
PhysicsWorld.getInstance().cleanup();
}
/**
* Gets called every frame.
*/
protected void simpleUpdate() {
boxPhysics.resetForces();
boxPhysics.setTorque(new Vector3f(0, 20f, 0));
System.err.println(boxPhysics.getAngularVelocity());
PhysicsWorld.getInstance().update(tpf);
}
public static void main(String[] args) {
TestSphere app = new TestSphere();
app.start();
}
}