Yep, I got it
Now I can move my cube.
Now I want to try to put wheels under my cube. I started with 1 cube (I read that I can only use spheres as wheels because cylinders are not realiable in collision detection, right?). I read and saw in the TestVehicle example that I have to use Joints. As I understood a joint is a connection between 2 Nodes, isn't it?
Now I tried to use these but get a high-jumping object (I mean very high)
Here is my code:
public class Auto extends SimplePhysicsGame {
/**
* @param args
*/
public static void main(String[] args) {
new Auto().start();
}
@Override
protected void simpleInitGame() {
final StaticPhysicsNode terrain = getPhysicsSpace().createStaticNode();
terrain.createMesh("Boden");
PhysicsMesh terrainmesh = terrain.createMesh( "terrain mesh" );
Box terrainbox=new Box("Terrain Box",new Vector3f(0,0,0),new Vector3f(15,0.1f,15));
terrainbox.setSolidColor(ColorRGBA.blue);
terrainmesh.copyFrom( terrainbox );
terrainbox.setModelBound( new BoundingBox() );
terrainbox.updateModelBound();
terrain.attachChild(terrainbox);
rootNode.attachChild(terrain);
final DynamicPhysicsNode chassis = getPhysicsSpace().createDynamicNode();
chassis.createMesh( "chassis" );
PhysicsMesh myboxmesh = chassis.createMesh( "sphere mesh" );
Box mybox=new Box("Chassis Box",new Vector3f(0,0,0),1,2,2);
myboxmesh.copyFrom( mybox );
mybox.setModelBound( new BoundingBox() );
chassis.setLocalTranslation(new Vector3f(5,5,5));
mybox.updateModelBound();
chassis.attachChild(mybox);
chassis.computeMass();
chassis.setMass(10);
rootNode.attachChild( chassis );
final DynamicPhysicsNode[] tire = new DynamicPhysicsNode[1];
DynamicPhysicsNode tire0 = getPhysicsSpace().createDynamicNode();;
for(int i=0;i<tire.length;i++) {
chassis.createMesh( "tire 0" );
PhysicsMesh tiremesh = tire0.createMesh( "sphere mesh" );
Sphere tiresphere=new Sphere("Chassis Box",10,10,1);
tiremesh.copyFrom( tiresphere );
tiresphere.setModelBound( new BoundingSphere() );
tire0.setLocalTranslation(new Vector3f(8,8,8));
tiresphere.updateModelBound();
tire0.attachChild(tiresphere);
rootNode.attachChild( tire0 );
tire0.computeMass();
tire0.setMass(1);
}
getPhysicsSpace().setDirectionalGravity(new Vector3f(0f,-2.81f,0f));
Joint joint = getPhysicsSpace().createJoint();
joint.attach( chassis, tire0 );
joint.setAnchor( tire0.getLocalTranslation() );
final JointAxis axis1 = joint.createRotationalAxis();
axis1.setDirection( new Vector3f( 0, 1, 0 ) );
axis1.setPositionMinimum( -0.5f );
axis1.setPositionMaximum( 0.5f );
axis1.setAvailableAcceleration( 100 );
axis1.setDesiredVelocity( 0 );
final JointAxis axis2 = joint.createRotationalAxis();
axis2.setDirection( new Vector3f( 0, 0, 1 ) );
axis2.setAvailableAcceleration( 100 );
axis2.setRelativeToSecondObject( true );
InputAction throttleAction = new InputAction() {
public void performAction( InputActionEvent evt ) {
chassis.addForce(chassis.getLocalRotation().mult(new Vector3f(1,0,0)));
}
};
input.addAction( throttleAction, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_O, InputHandler.AXIS_NONE, true );
InputAction steerLeftAction = new InputAction() {
public void performAction( InputActionEvent evt ) {
chassis.setAngularVelocity(new Vector3f(0,1,0));
}
};
input.addAction( steerLeftAction, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_K, InputHandler.AXIS_NONE, true );
InputAction steerRightAction = new InputAction() {
public void performAction( InputActionEvent evt ) {
chassis.setAngularVelocity(new Vector3f(0,-1,0));
}
};
input.addAction( steerRightAction, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_L, InputHandler.AXIS_NONE, true );
InputAction brakeAction = new InputAction() {
public void performAction( InputActionEvent evt ) {
chassis.addForce(chassis.getLocalRotation().mult(new Vector3f(-1,0,0)));
}
};
input.addAction( brakeAction, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_COMMA, InputHandler.AXIS_NONE, true );
showPhysics=true;
}
}
Hope somebody could solve my problem and also explain how Joints exactly work (or is there a forum message about this topic - I search…)
Thanks, daryl