diff --git a/src/sg/SpaceGame.java b/src/sg/SpaceGame.java index 26b1b6d..b53807d 100644 --- a/src/sg/SpaceGame.java +++ b/src/sg/SpaceGame.java @@ -17,6 +17,7 @@ import com.jme.input.InputHandler; import com.jme.input.KeyInput; import com.jme.input.action.InputAction; import com.jme.input.action.InputActionEvent; +import com.jme.math.Quaternion; import com.jme.math.Vector3f; import com.jme.util.TextureManager; import com.jmex.physics.DynamicPhysicsNode; @@ -54,21 +55,25 @@ public class SpaceGame extends SimplePhysicsGame { //light //TODO - + //controll physicsStepInputHandler = new InputHandler(); - getPhysicsSpace().addToUpdateCallbacks( new PhysicsUpdateCallback() { - public void beforeStep( PhysicsSpace space, float time ) { - physicsStepInputHandler.update( time ); - } - public void afterStep( PhysicsSpace space, float time ) { + getPhysicsSpace().addToUpdateCallbacks( new PhysicsUpdateCallback() { + public void beforeStep( PhysicsSpace space, float time ) { + physicsStepInputHandler.update( time ); + } + public void afterStep( PhysicsSpace space, float time ) { - } - } ); - physicsStepInputHandler.addAction( new MyInputAction( new Vector3f( 0, 700, 0 ) ), - InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_HOME, InputHandler.AXIS_NONE, true ); - physicsStepInputHandler.addAction( new MyInputAction( new Vector3f( 0, -700, 0 ) ), - InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_END, InputHandler.AXIS_NONE, true ); + } + } ); + physicsStepInputHandler.addAction( new MyInputAction(700, MyInputAction.FORWARD), + InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_HOME, InputHandler.AXIS_NONE, true ); + physicsStepInputHandler.addAction( new MyInputAction(700, MyInputAction.BACK), + InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_END, InputHandler.AXIS_NONE, true ); + physicsStepInputHandler.addAction( new MyInputAction(700, MyInputAction.LEFT), + InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_PGUP, InputHandler.AXIS_NONE, true ); + physicsStepInputHandler.addAction( new MyInputAction(700, MyInputAction.RIGHT), + InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_PGDN, InputHandler.AXIS_NONE, true ); //sphere /* @@ -86,13 +91,12 @@ public class SpaceGame extends SimplePhysicsGame { ts.setTexture(texture); s.setRenderState(ts); dynamicNode.attachChild(s); - */ - + */ + Node ship = SGUtil.loadModel("sg/data/models/ships/G6.3ds"); ship.setLocalTranslation(new Vector3f(0,0,-40)); - //ship.setLocalScale(0.01f); dynamicNode.attachChild(ship); - + //ChaseCamera ccam = new ChaseCamera( cam, ship); //input = ccam; } @@ -100,18 +104,26 @@ public class SpaceGame extends SimplePhysicsGame { public void simpleUpdate(){ environment.update(); } - + private class MyInputAction extends InputAction { - private final Vector3f direction; - private final Vector3f appliedForce = new Vector3f(); - - public MyInputAction( Vector3f direction ) { - this.direction = direction; - } - - public void performAction( InputActionEvent evt ) { - appliedForce.set( direction ).multLocal( evt.getTime() ); - dynamicNode.addForce( appliedForce ); - } - } + public static final int FORWARD = 1; + public static final int BACK = 2; + public static final int LEFT = 3; + public static final int RIGHT = 4; + private final float force; + private final Vector3f appliedForce = new Vector3f(); + private Vector3f rotation; + private final int direction; + + public MyInputAction(float force, int direction) { + this.force = force; + this.direction = direction; + } + + public void performAction( InputActionEvent evt ) { + rotation = dynamicNode.getLocalRotation().getRotationColumn(2); + appliedForce.set(rotation.mult(force)).multLocal( evt.getTime() ); + dynamicNode.addForce(appliedForce); + } + } } \ No newline at end of file