Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import com.jme3.gde.core.scene.controller.AbstractCameraController;
import com.jme3.input.InputManager;
import com.jme3.input.event.KeyInputEvent;
import com.jme3.renderer.Camera;
import com.jme3.scene.Spatial;

Expand All @@ -43,6 +44,7 @@
public class VehicleCreatorCameraController extends AbstractCameraController {

private Spatial vehicle;
private VehicleEditorController editorController;

public VehicleCreatorCameraController(Camera cam, InputManager inputManager) {
super(cam, inputManager);
Expand All @@ -67,6 +69,21 @@ public void setVehicle(Spatial vehicle) {
this.vehicle = vehicle;
}

/**
* @param editorController the VehicleEditorController to forward key events to
*/
public void setEditorController(VehicleEditorController editorController) {
this.editorController = editorController;
}

@Override
public void onKeyEvent(KeyInputEvent kie) {
super.onKeyEvent(kie);
if (editorController != null) {
editorController.onKeyEvent(kie);
}
}

@Override
public boolean useCameraControls() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ public void sceneOpened(final SceneRequest request) {
editorController = newEditorController;
cameraController = new VehicleCreatorCameraController(SceneApplication.getApplication().getCamera(), SceneApplication.getApplication().getInputManager());
cameraController.setMaster(this);
cameraController.setEditorController(editorController);
cameraController.enable();
cameraController.setVehicle(request.getRootNode());
setLoadedScene(currentRequest.getDataObject().getNodeDelegate(), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.event.KeyInputEvent;
import com.jme3.light.DirectionalLight;
import com.jme3.math.Matrix3f;
import com.jme3.math.Vector3f;
Expand Down Expand Up @@ -522,6 +523,39 @@ public void onAction(String binding, boolean value, float f) {
}
}

/**
* Handles key input events forwarded from the camera controller.
* Converts key codes to action bindings and calls onAction.
*
* @param kie the key input event
*/
public void onKeyEvent(KeyInputEvent kie) {
String binding;
switch (kie.getKeyCode()) {
case KeyInput.KEY_A:
binding = "VehicleEditor_Left";
break;
case KeyInput.KEY_D:
binding = "VehicleEditor_Right";
break;
case KeyInput.KEY_W:
binding = "VehicleEditor_Up";
break;
case KeyInput.KEY_S:
binding = "VehicleEditor_Down";
break;
case KeyInput.KEY_SPACE:
binding = "VehicleEditor_Space";
break;
case KeyInput.KEY_RETURN:
binding = "VehicleEditor_Reset";
break;
default:
return;
}
onAction(binding, kie.isPressed(), 0);
}

/**
* @return the motorForce
*/
Expand Down