- applied changes of the core to terraineditor


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7931 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 14 years ago
parent b8025984a0
commit 3b47418f4f
  1. 108
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainCameraController.java

@ -44,7 +44,6 @@ import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
/**
* Runs in the JME thread, not awt thread.
* Listens to mouse/camera input and relays the movements
@ -58,7 +57,6 @@ public class TerrainCameraController extends AbstractCameraController {
private TerrainEditorController editorController;
private boolean forceCameraControls = false; // when user holds shift, this is true
private boolean useCameraControls = true; // based on what a tool specifies
private boolean terrainEditToolActivated = false;
protected Application app;
private float toolModifyRate = 0.05f; // how frequently (in seconds) it should update to throttle down the tool effect
@ -77,79 +75,27 @@ public class TerrainCameraController extends AbstractCameraController {
this.editorController = editorController;
}
@Override
public void onMouseMotionEvent(MouseMotionEvent mme) {
super.onMouseMotionEvent(mme);
// if one of the terrain edit buttons is not enabled, return
if (!isTerrainEditButtonEnabled())
if (!isTerrainEditButtonEnabled()) {
return;
}
// move the marker
Vector3f pos = getTerrainCollisionPoint();
if (pos != null)
if (pos != null) {
toolController.doMoveEditTool(pos);
}
}
private boolean isTerrainEditButtonEnabled() {
return toolController.isTerrainEditButtonEnabled();
}
@Override
public void onAnalog(String string, float f1, float f) {
if ("MouseAxisX".equals(string)) {
moved = true;
movedR = true;
if (useCameraControls || forceCameraControls) {
if (buttonDownL) {
rotateCamera(Vector3f.UNIT_Y, -f1 * 2.5f);
}
if (buttonDownR) {
panCamera(f1 * 2.5f, 0);
}
}
} else if ("MouseAxisY".equals(string)) {
moved = true;
movedR = true;
if (useCameraControls || forceCameraControls) {
if (buttonDownL) {
rotateCamera(cam.getLeft(), -f1 * 2.5f);
}
if (buttonDownR) {
panCamera(0, -f1 * 2.5f);
}
}
} else if ("MouseAxisX-".equals(string)) {
moved = true;
movedR = true;
if (useCameraControls || forceCameraControls) {
if (buttonDownL) {
rotateCamera(Vector3f.UNIT_Y, f1 * 2.5f);
}
if (buttonDownR) {
panCamera(-f1 * 2.5f, 0);
}
}
} else if ("MouseAxisY-".equals(string)) {
moved = true;
movedR = true;
if (useCameraControls || forceCameraControls) {
if (buttonDownL) {
rotateCamera(cam.getLeft(), f1 * 2.5f);
}
if (buttonDownR) {
panCamera(0, f1 * 2.5f);
}
}
} else if ("MouseWheel".equals(string)) {
zoomCamera(.1f);
} else if ("MouseWheel-".equals(string)) {
zoomCamera(-.1f);
}
}
@Override
public void update(float f) {
super.update(f);
@ -159,17 +105,18 @@ public class TerrainCameraController extends AbstractCameraController {
@Override
protected void checkClick(int button, boolean pressed) {
/*if (button == 0) {
/*if (button == 0) {
if (isTerrainEditButtonEnabled() && !forceCameraControls) {
if (leftMouse)
terrainEditToolActivated = true;
terrainEditToolActivated = true;
}
}
if (button == 1) {
if (isTerrainEditButtonEnabled() && !forceCameraControls) {
toolController.doTerrainEditToolAlternateActivated();
}
}*/
if (button == 1) {
if (isTerrainEditButtonEnabled() && !forceCameraControls) {
toolController.doTerrainEditToolAlternateActivated();
}
}*/
if (button == 1) {
if (isTerrainEditButtonEnabled() && !forceCameraControls) {
@ -180,12 +127,13 @@ public class TerrainCameraController extends AbstractCameraController {
@Override
protected void checkDragged(int button, boolean pressed) {
terrainEditToolActivated = true;
if (button == 0 && !forceCameraControls) {
terrainEditToolActivated = true;
}
}
@Override
protected void checkMoved() {
}
/**
@ -201,8 +149,9 @@ public class TerrainCameraController extends AbstractCameraController {
if (lastModifyTime >= toolModifyRate) {
lastModifyTime = 0;
if (terrainEditToolActivated)
if (terrainEditToolActivated) {
toolController.doTerrainEditToolActivated();
}
terrainEditToolActivated = false;
lastModifyTime = app.getContext().getTimer().getTime();
}
@ -211,25 +160,26 @@ public class TerrainCameraController extends AbstractCameraController {
@Override
public void onKeyEvent(KeyInputEvent kie) {
super.onKeyEvent(kie);
if (kie.isPressed()) {
if ( KeyInput.KEY_LSHIFT == kie.getKeyCode() ) {
if (KeyInput.KEY_LSHIFT == kie.getKeyCode()) {
forceCameraControls = true;
}
} else if (kie.isReleased()){
if ( KeyInput.KEY_LSHIFT == kie.getKeyCode() ) {
} else if (kie.isReleased()) {
if (KeyInput.KEY_LSHIFT == kie.getKeyCode()) {
forceCameraControls = false;
}
}
}
/**
* Find where on the terrain the mouse intersects.
*/
protected Vector3f getTerrainCollisionPoint() {
if (editorController.getTerrain(null) == null)
if (editorController.getTerrain(null) == null) {
return null;
}
CollisionResults results = new CollisionResults();
Ray ray = new Ray();
@ -243,8 +193,9 @@ public class TerrainCameraController extends AbstractCameraController {
return null;
}
final CollisionResult result = results.getClosestCollision();
if (result == null)
if (result == null) {
return null;
}
return result.getContactPoint();
}
@ -252,7 +203,8 @@ public class TerrainCameraController extends AbstractCameraController {
this.useCameraControls = useCameraControls;
}
@Override
public boolean useCameraControls() {
return useCameraControls || forceCameraControls;
}
}

Loading…
Cancel
Save