diff --git a/src/sg/input/FirstPersonHandler.java b/src/sg/input/FirstPersonHandler.java index e5683c5..ada3728 100644 --- a/src/sg/input/FirstPersonHandler.java +++ b/src/sg/input/FirstPersonHandler.java @@ -2,8 +2,6 @@ package sg.input; import com.jme.input.KeyBindingManager; import com.jme.input.KeyInput; -import com.jme.math.FastMath; -import com.jme.math.Quaternion; import com.jme.math.Vector3f; import com.jme.renderer.Camera; import com.jme.scene.Node; @@ -13,63 +11,37 @@ import com.jmex.physics.DynamicPhysicsNode; public class FirstPersonHandler extends GlobalInputHandler{ private final Vector3f appliedForce = new Vector3f(); private Vector3f rotation; - private Quaternion qRot = new Quaternion(); - private float xAngle, yAngle, zAngle; private Node ship; private DynamicPhysicsNode shipNode; private Camera cam; - + public FirstPersonHandler(Node ship, DynamicPhysicsNode shipNode, Camera cam){ this.ship = ship; this.shipNode = shipNode; this.cam = cam; - + KeyBindingManager manager = KeyBindingManager.getKeyBindingManager(); - manager.set("yaw", KeyInput.KEY_K); - manager.set("yaw2", KeyInput.KEY_I); - manager.set("roll", KeyInput.KEY_U); - manager.set("roll2", KeyInput.KEY_O); - manager.set("pitch", KeyInput.KEY_J); - manager.set("pitch2", KeyInput.KEY_L); - manager.set("forw", KeyInput.KEY_2); - manager.set("backw", KeyInput.KEY_1); + manager.set("yaw", KeyInput.KEY_K); + manager.set("yaw2", KeyInput.KEY_I); + manager.set("roll", KeyInput.KEY_U); + manager.set("roll2", KeyInput.KEY_O); + manager.set("pitch", KeyInput.KEY_J); + manager.set("pitch2", KeyInput.KEY_L); + manager.set("forw", KeyInput.KEY_2); + manager.set("backw", KeyInput.KEY_1); } - + public void update(float time){ super.update(time); - if ( KeyBindingManager.getKeyBindingManager().isValidCommand("yaw", true ) ) { - xAngle = (xAngle + 0.05f) % (2*FastMath.PI); - ship.setLocalRotation(qRot.fromAngles(xAngle, yAngle, zAngle)); - } - if ( KeyBindingManager.getKeyBindingManager().isValidCommand("yaw2", true ) ) { - xAngle = (xAngle - 0.05f) % (2*FastMath.PI); - ship.setLocalRotation(qRot.fromAngles(xAngle, yAngle, zAngle)); - } - if ( KeyBindingManager.getKeyBindingManager().isValidCommand("roll", true ) ) { - yAngle = (yAngle + 0.05f) % (2*FastMath.PI); - ship.setLocalRotation(qRot.fromAngles(xAngle, yAngle, zAngle)); - } - if ( KeyBindingManager.getKeyBindingManager().isValidCommand("roll2", true ) ) { - yAngle = (yAngle - 0.05f) % (2*FastMath.PI); - ship.setLocalRotation(qRot.fromAngles(xAngle, yAngle, zAngle)); - } - if ( KeyBindingManager.getKeyBindingManager().isValidCommand("pitch", true ) ) { - zAngle = (zAngle + 0.05f) % (2*FastMath.PI); - ship.setLocalRotation(qRot.fromAngles(xAngle, yAngle, zAngle)); - } - if ( KeyBindingManager.getKeyBindingManager().isValidCommand("pitch2", true ) ) { - zAngle = (zAngle - 0.05f) % (2*FastMath.PI); - ship.setLocalRotation(qRot.fromAngles(xAngle, yAngle, zAngle)); - } + rotation = ship.getLocalRotation().getRotationColumn(2); if ( KeyBindingManager.getKeyBindingManager().isValidCommand("forw", true ) ) { - rotation = ship.getLocalRotation().getRotationColumn(2); appliedForce.set(rotation.mult(-700)).multLocal(time); shipNode.addForce(appliedForce); - } - if ( KeyBindingManager.getKeyBindingManager().isValidCommand("backw", true ) ) { - rotation = ship.getLocalRotation().getRotationColumn(2); + } + else if ( KeyBindingManager.getKeyBindingManager().isValidCommand("backw", true ) ) { appliedForce.set(rotation.mult(700)).multLocal(time); shipNode.addForce(appliedForce); - } + } + } }