This is what I did but but it didn't work :
public class CarSimulation extends Xith3DTest
{
private static final Vector2f X_AXIS = new Vector2f( 1.0f, 0.0f );
private FirstPersonInputHandler fpih;
private Node fpihDebugNode;
private Model avatar;
private Model floorModel;
private Transform avatarTG;
private PhysicsEngine physEngine;
private CollideableGroup collGroup;
private Body b;
private float speed = 1.5f;
@Override
public void onKeyPressed( KeyPressedEvent e, Key key )
{
switch ( key.getKeyID() )
{
case Y:
fpih.flipMouseYAxis();
break;
}
}
@Override
public void onKeyReleased( KeyReleasedEvent e, Key key )
{
switch ( key.getKeyID() )
{
case V:
fpihDebugNode.setRenderable( !fpihDebugNode.isRenderable() );
break;
}
}
@Override
public void onKeyStateChanged( KeyStateEvent e, Key key, boolean state )
{
switch ( key.getKeyID() )
{
case LEFT_CONTROL:
fpih.setSuspended( state );
break;
}
}
private void createAvatarCollider( final PhysicsEngine physEngine, FirstPersonInputHandler fpHandler, BranchGroup sceneBranch)
{
SimulationWorld world = physEngine.getSimulationEngine().newWorld();
world.setGravity( 0f,0f,0f );
b = world.newBody();
world.addBody(b );
FPIHInputBindingsManager bindings = fpHandler.getBindingsManager();
bindings.createDefaultBindings();
bindings.bind( Keys.LEFT, FPIHInputAction.TURN_LEFT, InputBindingsSet.PRIMARY );
bindings.bind( Keys.RIGHT, FPIHInputAction.TURN_RIGHT, InputBindingsSet.PRIMARY );
fpHandler.setMouseSuspended( true );
fpHandler.setPhysicsObject( new MyFPIHPhysics( 2.7f, 2.0f, new Vector3f( 0f, 1f, 0f ), physEngine, world, true, true) );
fpihDebugNode = fpHandler.getPhysicsObject().getDebugNode();
sceneBranch.addChild( fpihDebugNode );
fpHandler.getPhysicsObject().setSlidingColliderCheckCallback( physEngine.getCollisionEngine(), collGroup );
}
private void loadAvatar( URL modelResource, String skin, FirstPersonInputHandler fpHandler, BranchGroup sceneBranch, PhysicsEngine physEngine ) throws Exception
{
this.avatar = ModelLoader.getInstance().loadModel( modelResource, skin, 0.04f );
this.avatarTG = new Transform();
avatarTG.getTransform().setIdentity();
avatarTG.addRotationY( FastMath.PI_HALF );
avatarTG.addChild( avatar );
avatarTG.addChild( new AmbientLight( Colorf.GRAY50 ) );
AvatarTransform at = new DefaultAvatarTransform( avatarTG, 0f, sceneBranch );
fpHandler.addAvatar( at );
fpHandler.setThirdPersonOffset( 0f, 0f, 7f );
fpHandler.setMaxThirdPersonDistance( 10f );
fpHandler.setMinThirdPersonDistance( 10f );
fpHandler.setDiscreteThirdPersonStepSize( 0.5f );
fpHandler.setMovementSpeedForward(speed);
createAvatarCollider( physEngine, fpHandler, sceneBranch);
}
private void createWorldColliders( final CollisionEngine collEngine, Shape3D[] m )
{
this.collGroup = collEngine.newGroup( "Simple" );
for ( int i = 0; i < m.length; i++ )
{
Collideable modelcollider = collEngine.newTriMesh(m[i]);
collGroup.addCollideable( modelcollider );
}
}
private float getAngle2X( Vector2f vec )
{
if ( vec.getY() <= 0f )
return ( vec.angle( X_AXIS ) );
return ( FastMath.TWO_PI - X_AXIS.angle( vec ) );
}
private Model createFloor(URL modelResource, String skin)throws Exception
{
floorModel = ModelLoader.getInstance().loadModel( modelResource, skin, 0.04f );
return(floorModel);
}
private BranchGroup createSceneGraph( ResourceLocator resLoc, FirstPersonInputHandler fpHandler ) throws Exception
{
BranchGroup scene = new BranchGroup();
scene.addChild( new DirectionalLight( true, Colorf.GRAY50, new Vector3f( 0.0f, -0.77f, -0.77f ) ) );
Texture.setDefaultFilter( TextureFilter.TRILINEAR );
final float ROOM_WIDTH = 1024f;
final float ROOM_DEPTH = 768f;
Model model = createFloor(resLoc.getResource( "coolcity/cool.3ds" ),"marvin.pcx");
scene.addChild(model);
createWorldColliders( physEngine.getCollisionEngine(), model.getShapes() );
Texture.setDefaultFilter( TextureFilter.NICER );
loadAvatar( resLoc.getResource( "mine/pajero.obj" ), "marvin.pcx", fpHandler, scene, physEngine );
return ( scene );
}
private HUD createHUD( Sized2iRO canvasRes )
{
HUD hud = new HUD( canvasRes, 800f );
DeviceComponent[] comps = new DeviceComponent[] { new MouseAxis( null, 'm', "FPS input" ), Keys.LEFT_CONTROL, Keys.V, Keys.Y };
String[] boundActions = new String[] { "Control", "Get HUD mouse control", "Toggle FirstPersonInputHandler collider visualization", "Invert the mouse y-axis" };
TestUtils.displayInputBindings( comps, boundActions, hud );
return ( hud );
}
public CarSimulation( BasicApplicationArguments arguments, ResourceLocator rl, Xith3DEnvironment env, FirstPersonInputHandler fpih ) throws Throwable
{
super( arguments.getMaxFPS() );
this.physEngine = new JoodePhysicsEngine();
env.getCanvas().clear();
env.getView().setPosition( 150f, 0f, 350f );
env.setPhysicsEngine( physEngine );
env.addRenderPass( SkyBoxTest.createSkyBox( rl.getResource( "skyboxes/" ), "normal" ) );
this.fpih = fpih;
env.addPerspectiveBranch( createSceneGraph( rl, this.fpih ) );
env.addHUD( createHUD( arguments.getResolution() ) );
}
}
please help