This commit is contained in:
parent
e3cc55162f
commit
f705ff8fb4
1 changed files with 41 additions and 29 deletions
|
|
@ -17,6 +17,7 @@ import com.jme.input.InputHandler;
|
||||||
import com.jme.input.KeyInput;
|
import com.jme.input.KeyInput;
|
||||||
import com.jme.input.action.InputAction;
|
import com.jme.input.action.InputAction;
|
||||||
import com.jme.input.action.InputActionEvent;
|
import com.jme.input.action.InputActionEvent;
|
||||||
|
import com.jme.math.Quaternion;
|
||||||
import com.jme.math.Vector3f;
|
import com.jme.math.Vector3f;
|
||||||
import com.jme.util.TextureManager;
|
import com.jme.util.TextureManager;
|
||||||
import com.jmex.physics.DynamicPhysicsNode;
|
import com.jmex.physics.DynamicPhysicsNode;
|
||||||
|
|
@ -54,21 +55,25 @@ public class SpaceGame extends SimplePhysicsGame {
|
||||||
|
|
||||||
//light
|
//light
|
||||||
//TODO
|
//TODO
|
||||||
|
|
||||||
//controll
|
//controll
|
||||||
physicsStepInputHandler = new InputHandler();
|
physicsStepInputHandler = new InputHandler();
|
||||||
getPhysicsSpace().addToUpdateCallbacks( new PhysicsUpdateCallback() {
|
getPhysicsSpace().addToUpdateCallbacks( new PhysicsUpdateCallback() {
|
||||||
public void beforeStep( PhysicsSpace space, float time ) {
|
public void beforeStep( PhysicsSpace space, float time ) {
|
||||||
physicsStepInputHandler.update( time );
|
physicsStepInputHandler.update( time );
|
||||||
}
|
}
|
||||||
public void afterStep( PhysicsSpace space, float time ) {
|
public void afterStep( PhysicsSpace space, float time ) {
|
||||||
|
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
physicsStepInputHandler.addAction( new MyInputAction( new Vector3f( 0, 700, 0 ) ),
|
physicsStepInputHandler.addAction( new MyInputAction(700, MyInputAction.FORWARD),
|
||||||
InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_HOME, InputHandler.AXIS_NONE, true );
|
InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_HOME, InputHandler.AXIS_NONE, true );
|
||||||
physicsStepInputHandler.addAction( new MyInputAction( new Vector3f( 0, -700, 0 ) ),
|
physicsStepInputHandler.addAction( new MyInputAction(700, MyInputAction.BACK),
|
||||||
InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_END, InputHandler.AXIS_NONE, true );
|
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
|
//sphere
|
||||||
/*
|
/*
|
||||||
|
|
@ -86,13 +91,12 @@ public class SpaceGame extends SimplePhysicsGame {
|
||||||
ts.setTexture(texture);
|
ts.setTexture(texture);
|
||||||
s.setRenderState(ts);
|
s.setRenderState(ts);
|
||||||
dynamicNode.attachChild(s);
|
dynamicNode.attachChild(s);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Node ship = SGUtil.loadModel("sg/data/models/ships/G6.3ds");
|
Node ship = SGUtil.loadModel("sg/data/models/ships/G6.3ds");
|
||||||
ship.setLocalTranslation(new Vector3f(0,0,-40));
|
ship.setLocalTranslation(new Vector3f(0,0,-40));
|
||||||
//ship.setLocalScale(0.01f);
|
|
||||||
dynamicNode.attachChild(ship);
|
dynamicNode.attachChild(ship);
|
||||||
|
|
||||||
//ChaseCamera ccam = new ChaseCamera( cam, ship);
|
//ChaseCamera ccam = new ChaseCamera( cam, ship);
|
||||||
//input = ccam;
|
//input = ccam;
|
||||||
}
|
}
|
||||||
|
|
@ -100,18 +104,26 @@ public class SpaceGame extends SimplePhysicsGame {
|
||||||
public void simpleUpdate(){
|
public void simpleUpdate(){
|
||||||
environment.update();
|
environment.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MyInputAction extends InputAction {
|
private class MyInputAction extends InputAction {
|
||||||
private final Vector3f direction;
|
public static final int FORWARD = 1;
|
||||||
private final Vector3f appliedForce = new Vector3f();
|
public static final int BACK = 2;
|
||||||
|
public static final int LEFT = 3;
|
||||||
public MyInputAction( Vector3f direction ) {
|
public static final int RIGHT = 4;
|
||||||
this.direction = direction;
|
private final float force;
|
||||||
}
|
private final Vector3f appliedForce = new Vector3f();
|
||||||
|
private Vector3f rotation;
|
||||||
public void performAction( InputActionEvent evt ) {
|
private final int direction;
|
||||||
appliedForce.set( direction ).multLocal( evt.getTime() );
|
|
||||||
dynamicNode.addForce( appliedForce );
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue