Hi I've got unexpected behaviour when I create a new PhysicsNode from a Box. If I give the box the desired centre vector then when the simulation starts the physics node does a jump. If I give the Box a zero vector then set the local translation of the same vector then the physics node doesn't jump.
Jumps:
Box box=new Box("physicsobstaclemesh",hammerStart,.5f,size,.5f);
hammer = new PhysicsNode(box);
Does not jump:
Box box=new Box("physicsobstaclemesh",Vector3f.ZERO,.5f,size,.5f);
hammer = new PhysicsNode(box);
hammer.setLocalTranslation(hammerStart);
Here is a shorted version of the TestHingeJointMotor class to show what I mean:
/*
* Copyright (c) 2009 Normen Hansen
*/
import java.util.concurrent.Callable;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;
import com.jme.util.GameTaskQueueManager;
import com.jmex.game.StandardGame;
import com.jmex.game.state.DebugGameState;
import com.jmex.game.state.GameStateManager;
import com.jmex.jbullet.PhysicsSpace;
import com.jmex.jbullet.collision.shapes.CollisionShape;
import com.jmex.jbullet.joints.PhysicsHingeJoint;
import com.jmex.jbullet.nodes.PhysicsNode;
/**
* This is a basic Test of jbullet-jme hinge joint motors
*
* @author normenhansen
*/
public class Test {
private static PhysicsNode hammer;
private static PhysicsHingeJoint joint;
public static void setupGame(){
// creates and initializes the PhysicsSpace
final PhysicsSpace pSpace=PhysicsSpace.getPhysicsSpace();
DebugGameState state = new DebugGameState(){
CollisionShape shape;
@Override
public void update(float tpf) {
pSpace.update(tpf);
super.update(tpf);
}
};
Vector3f start = new Vector3f(0,1,0);
Sphere sphere=new Sphere("physicsobstaclemesh",8,8,0.25f);
PhysicsNode holder=new PhysicsNode(sphere, CollisionShape.ShapeTypes.SPHERE,0);
holder.setLocalTranslation(0,1,0);
state.getRootNode().attachChild(holder);
holder.updateRenderState();
pSpace.add(holder);
float size = 0.5f;
float gap = 3f;
Vector3f hammerStart = start.add(0, -(size + gap),0);
/*
//this one jumps
Box box=new Box("physicsobstaclemesh",hammerStart,.5f,size,.5f);
hammer = new PhysicsNode(box);
//*/
// /*
//this one does not jump
Box box=new Box("physicsobstaclemesh",Vector3f.ZERO,.5f,size,.5f);
hammer = new PhysicsNode(box);
hammer.setLocalTranslation(hammerStart);
//*/
state.getRootNode().attachChild(hammer);
hammer.updateRenderState();
pSpace.add(hammer);
joint=new PhysicsHingeJoint(holder, hammer, new Vector3f(), new Vector3f(0,size +gap,0),
Vector3f.UNIT_Z, Vector3f.UNIT_Z);
pSpace.add(joint);
// Add the gamestate to the manager
GameStateManager.getInstance().attachChild(state);
// Activate the game state
state.setActive(true);
}
public static void main(String[] args) throws Exception {
// Enable statistics gathering
System.setProperty("jme.stats", "set");
// Instantiate StandardGame
StandardGame game = new StandardGame("A Simple Test");
game.start();
GameTaskQueueManager.getManager().update(new Callable<Void>() {
public Void call() throws Exception {
setupGame();
return null;
}
});
}
}