Hello,
is it possible to give objects a color in SimplePhysicsGame? If I set a color with setSolidColor() everything stays grey.
But that's only a question beside the real one: I have a pseudo-car with 4 spheres as wheels and a box as chassis. I can addForce as I want, the thing does only move when it's in the air. Possibly I have to rotate the axs instead of adding Force but I don't know how. Here is my code until now:
public class Auto extends SimplePhysicsGame {
/**
* @param args
*/
public static void main(String[] args) {
LoggingSystem.getLogger().setLevel( Level.WARNING );
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(-10,0,-10),new Vector3f(15,0.1f,15));
terrainmesh.copyFrom( terrainbox );
terrainmesh.getLocalTranslation().set( terrain.getLocalTranslation() );
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),2,0.1f,1);
myboxmesh.copyFrom( mybox );
mybox.setModelBound( new BoundingBox() );
chassis.setLocalTranslation(new Vector3f(0,1,0));
mybox.updateModelBound();
chassis.attachChild(mybox);
//chassis.computeMass();
//chassis.setMass(100);
rootNode.attachChild( chassis );
DynamicPhysicsNode wheels[] = new DynamicPhysicsNode[4];
for(int i=0;i<4;i++) {
final DynamicPhysicsNode tire = getPhysicsSpace().createDynamicNode();
wheels[i]=tire;
tire.createMesh( "tire" );
PhysicsMesh tiremesh = tire.createMesh( "sphere mesh" );
Sphere tiresphere=new Sphere("Tire Sphere",10,10,0.4f);
tiremesh.copyFrom( tiresphere );
tiresphere.setModelBound( new BoundingSphere() );
tiresphere.updateModelBound();
tire.setMaterial( Material.RUBBER );
tire.getLocalTranslation().set( ( 0.5f - ( i & 1 ) ), 1, ( 1 - ( i & 2 ) ) * 0.5f );
tire.computeMass();
tire.setMass( 10 );
rootNode.attachChild( tire );
tire.computeMass();
Joint joint = getPhysicsSpace().createJoint();
joint.attach( chassis, tire);
joint.setAnchor( new Vector3f(0,0,0) );
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 ) {
tire.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 ) {
tire.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 ) {
tire.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 ) {
tire.addForce(chassis.getLocalRotation().mult(new Vector3f(-1,0,0)));
}
};
input.addAction( brakeAction, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_COMMA, InputHandler.AXIS_NONE, true );
}
//getPhysicsSpace().setDirectionalGravity(new Vector3f(0f,-9.81f,0f));
showPhysics=true;
rootNode.updateGeometricState(0.0f, true);
rootNode.updateRenderState();
}
}