This commit is contained in:
Daniel Collin 2009-03-11 17:58:04 +00:00
parent 47c43078f0
commit b26ee23c41

View file

@ -2,8 +2,6 @@ package sg.input;
import com.jme.input.KeyBindingManager; import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput; import com.jme.input.KeyInput;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f; import com.jme.math.Vector3f;
import com.jme.renderer.Camera; import com.jme.renderer.Camera;
import com.jme.scene.Node; import com.jme.scene.Node;
@ -13,8 +11,6 @@ import com.jmex.physics.DynamicPhysicsNode;
public class FirstPersonHandler extends GlobalInputHandler{ public class FirstPersonHandler extends GlobalInputHandler{
private final Vector3f appliedForce = new Vector3f(); private final Vector3f appliedForce = new Vector3f();
private Vector3f rotation; private Vector3f rotation;
private Quaternion qRot = new Quaternion();
private float xAngle, yAngle, zAngle;
private Node ship; private Node ship;
private DynamicPhysicsNode shipNode; private DynamicPhysicsNode shipNode;
private Camera cam; private Camera cam;
@ -25,51 +21,27 @@ public class FirstPersonHandler extends GlobalInputHandler{
this.cam = cam; this.cam = cam;
KeyBindingManager manager = KeyBindingManager.getKeyBindingManager(); KeyBindingManager manager = KeyBindingManager.getKeyBindingManager();
manager.set("yaw", KeyInput.KEY_K); manager.set("yaw", KeyInput.KEY_K);
manager.set("yaw2", KeyInput.KEY_I); manager.set("yaw2", KeyInput.KEY_I);
manager.set("roll", KeyInput.KEY_U); manager.set("roll", KeyInput.KEY_U);
manager.set("roll2", KeyInput.KEY_O); manager.set("roll2", KeyInput.KEY_O);
manager.set("pitch", KeyInput.KEY_J); manager.set("pitch", KeyInput.KEY_J);
manager.set("pitch2", KeyInput.KEY_L); manager.set("pitch2", KeyInput.KEY_L);
manager.set("forw", KeyInput.KEY_2); manager.set("forw", KeyInput.KEY_2);
manager.set("backw", KeyInput.KEY_1); manager.set("backw", KeyInput.KEY_1);
} }
public void update(float time){ public void update(float time){
super.update(time); super.update(time);
if ( KeyBindingManager.getKeyBindingManager().isValidCommand("yaw", true ) ) { rotation = ship.getLocalRotation().getRotationColumn(2);
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));
}
if ( KeyBindingManager.getKeyBindingManager().isValidCommand("forw", true ) ) { if ( KeyBindingManager.getKeyBindingManager().isValidCommand("forw", true ) ) {
rotation = ship.getLocalRotation().getRotationColumn(2);
appliedForce.set(rotation.mult(-700)).multLocal(time); appliedForce.set(rotation.mult(-700)).multLocal(time);
shipNode.addForce(appliedForce); shipNode.addForce(appliedForce);
} }
if ( KeyBindingManager.getKeyBindingManager().isValidCommand("backw", true ) ) { else if ( KeyBindingManager.getKeyBindingManager().isValidCommand("backw", true ) ) {
rotation = ship.getLocalRotation().getRotationColumn(2);
appliedForce.set(rotation.mult(700)).multLocal(time); appliedForce.set(rotation.mult(700)).multLocal(time);
shipNode.addForce(appliedForce); shipNode.addForce(appliedForce);
} }
} }
} }