|
@@ -1,33 +1,26 @@
|
|
|
/*
|
|
|
- * Copyright (c) 2009-2010 jMonkeyEngine
|
|
|
- * All rights reserved.
|
|
|
+ * Copyright (c) 2009-2010 jMonkeyEngine All rights reserved. <p/>
|
|
|
+ * Redistribution and use in source and binary forms, with or without
|
|
|
+ * modification, are permitted provided that the following conditions are met:
|
|
|
*
|
|
|
- * Redistribution and use in source and binary forms, with or without
|
|
|
- * modification, are permitted provided that the following conditions are
|
|
|
- * met:
|
|
|
- *
|
|
|
- * * Redistributions of source code must retain the above copyright
|
|
|
- * notice, this list of conditions and the following disclaimer.
|
|
|
- *
|
|
|
- * * Redistributions in binary form must reproduce the above copyright
|
|
|
- * notice, this list of conditions and the following disclaimer in the
|
|
|
- * documentation and/or other materials provided with the distribution.
|
|
|
- *
|
|
|
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
|
|
- * may be used to endorse or promote products derived from this software
|
|
|
- * without specific prior written permission.
|
|
|
- *
|
|
|
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
|
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
+ * * Redistributions of source code must retain the above copyright notice,
|
|
|
+ * this list of conditions and the following disclaimer. <p/> * Redistributions
|
|
|
+ * in binary form must reproduce the above copyright notice, this list of
|
|
|
+ * conditions and the following disclaimer in the documentation and/or other
|
|
|
+ * materials provided with the distribution. <p/> * Neither the name of
|
|
|
+ * 'jMonkeyEngine' nor the names of its contributors may be used to endorse or
|
|
|
+ * promote products derived from this software without specific prior written
|
|
|
+ * permission. <p/> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
|
|
|
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
|
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
*/
|
|
|
package com.jme3.gde.core.scene.controller;
|
|
|
|
|
@@ -35,6 +28,7 @@ import com.jme3.app.Application;
|
|
|
import com.jme3.app.state.AbstractAppState;
|
|
|
import com.jme3.app.state.AppStateManager;
|
|
|
import com.jme3.gde.core.scene.SceneApplication;
|
|
|
+import com.jme3.gde.core.sceneviewer.SceneViewerTopComponent;
|
|
|
import com.jme3.input.InputManager;
|
|
|
import com.jme3.input.RawInputListener;
|
|
|
import com.jme3.input.controls.ActionListener;
|
|
@@ -50,21 +44,25 @@ import com.jme3.math.Quaternion;
|
|
|
import com.jme3.math.Vector3f;
|
|
|
import com.jme3.renderer.Camera;
|
|
|
import com.jme3.renderer.RenderManager;
|
|
|
+import java.awt.FocusTraversalPolicy;
|
|
|
import java.util.concurrent.Callable;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
+import java.util.concurrent.Future;
|
|
|
import java.util.logging.Logger;
|
|
|
+import org.openide.util.Exceptions;
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @author normenhansen
|
|
|
*/
|
|
|
-public abstract class AbstractCameraController extends AbstractAppState implements ActionListener, AnalogListener, RawInputListener{
|
|
|
+public abstract class AbstractCameraController extends AbstractAppState implements ActionListener, AnalogListener, RawInputListener {
|
|
|
|
|
|
protected boolean leftMouse, rightMouse, middleMouse;
|
|
|
protected float deltaX, deltaY, deltaZ, deltaWheel;
|
|
|
protected int mouseX = 0;
|
|
|
protected int mouseY = 0;
|
|
|
protected Quaternion rot = new Quaternion();
|
|
|
- protected Vector3f vector = new Vector3f(0,0,5);
|
|
|
+ protected Vector3f vector = new Vector3f(0, 0, 5);
|
|
|
protected Vector3f focus = new Vector3f();
|
|
|
protected Camera cam;
|
|
|
protected InputManager inputManager;
|
|
@@ -73,10 +71,13 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|
|
protected boolean movedR = false;
|
|
|
protected boolean buttonDownL = false;
|
|
|
protected boolean buttonDownR = false;
|
|
|
+ protected boolean buttonDownM = false;
|
|
|
protected boolean checkClickL = false;
|
|
|
protected boolean checkClickR = false;
|
|
|
+ protected boolean checkClickM = false;
|
|
|
protected boolean checkReleaseL = false;
|
|
|
protected boolean checkReleaseR = false;
|
|
|
+ protected boolean checkReleaseM = false;
|
|
|
protected boolean checkDragged = false;
|
|
|
protected boolean checkDraggedR = false;
|
|
|
protected boolean checkReleaseLeft = false;
|
|
@@ -84,7 +85,7 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|
|
|
|
|
public AbstractCameraController(Camera cam, InputManager inputManager) {
|
|
|
this.cam = cam;
|
|
|
- this.inputManager=inputManager;
|
|
|
+ this.inputManager = inputManager;
|
|
|
}
|
|
|
|
|
|
public void setMaster(Object component) {
|
|
@@ -158,6 +159,55 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|
|
Vector3f loc = cam.getLocation().clone();
|
|
|
loc.scaleAdd(amount, cam.getDirection(), loc);
|
|
|
cam.setLocation(loc);
|
|
|
+
|
|
|
+ if (cam.isParallelProjection()) {
|
|
|
+ float aspect = (float) cam.getWidth() / cam.getHeight();
|
|
|
+ float h = FastMath.tan(45f * FastMath.DEG_TO_RAD * .5f) * dist;
|
|
|
+ float w = h * aspect;
|
|
|
+ cam.setFrustum(-1000, 1000, -w, w, h, -h);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean toggleOrthoPerspMode() {
|
|
|
+ try {
|
|
|
+ return SceneApplication.getApplication().enqueue(new Callable<Boolean>() {
|
|
|
+
|
|
|
+ public Boolean call() throws Exception {
|
|
|
+ return doToggleOrthoPerspMode();
|
|
|
+ }
|
|
|
+ }).get();
|
|
|
+ } catch (InterruptedException ex) {
|
|
|
+ Exceptions.printStackTrace(ex);
|
|
|
+ } catch (ExecutionException ex) {
|
|
|
+ Exceptions.printStackTrace(ex);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected boolean doToggleOrthoPerspMode() {
|
|
|
+
|
|
|
+ float aspect = (float) cam.getWidth() / cam.getHeight();
|
|
|
+ if (!cam.isParallelProjection()) {
|
|
|
+ cam.setParallelProjection(true);
|
|
|
+ float h = cam.getFrustumTop();
|
|
|
+ float w = cam.getFrustumRight();
|
|
|
+ float dist = cam.getLocation().distance(focus);
|
|
|
+ float fovY = FastMath.atan(h) / (FastMath.DEG_TO_RAD * .5f);
|
|
|
+ h = FastMath.tan(fovY * FastMath.DEG_TO_RAD * .5f) * dist;
|
|
|
+ w = h * aspect;
|
|
|
+ cam.setFrustum(-1000, 1000, -w, w, h, -h);
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ cam.setParallelProjection(false);
|
|
|
+ cam.setFrustumPerspective(45f, aspect, 1, 1000);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/*public void onAction(String string, boolean bln, float f) {
|
|
@@ -198,12 +248,11 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|
|
}
|
|
|
}
|
|
|
}*/
|
|
|
-
|
|
|
public void onAnalog(String string, float f1, float f) {
|
|
|
if ("MouseAxisX".equals(string)) {
|
|
|
moved = true;
|
|
|
movedR = true;
|
|
|
- if (buttonDownL) {
|
|
|
+ if (buttonDownL || buttonDownM) {
|
|
|
rotateCamera(Vector3f.UNIT_Y, -f1 * 2.5f);
|
|
|
}
|
|
|
if (buttonDownR) {
|
|
@@ -212,7 +261,7 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|
|
} else if ("MouseAxisY".equals(string)) {
|
|
|
moved = true;
|
|
|
movedR = true;
|
|
|
- if (buttonDownL) {
|
|
|
+ if (buttonDownL || buttonDownM) {
|
|
|
rotateCamera(cam.getLeft(), -f1 * 2.5f);
|
|
|
}
|
|
|
if (buttonDownR) {
|
|
@@ -221,7 +270,7 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|
|
} else if ("MouseAxisX-".equals(string)) {
|
|
|
moved = true;
|
|
|
movedR = true;
|
|
|
- if (buttonDownL) {
|
|
|
+ if (buttonDownL || buttonDownM) {
|
|
|
rotateCamera(Vector3f.UNIT_Y, f1 * 2.5f);
|
|
|
}
|
|
|
if (buttonDownR) {
|
|
@@ -230,7 +279,7 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|
|
} else if ("MouseAxisY-".equals(string)) {
|
|
|
moved = true;
|
|
|
movedR = true;
|
|
|
- if (buttonDownL) {
|
|
|
+ if (buttonDownL || buttonDownM) {
|
|
|
rotateCamera(cam.getLeft(), f1 * 2.5f);
|
|
|
}
|
|
|
if (buttonDownR) {
|
|
@@ -242,9 +291,11 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|
|
zoomCamera(-.1f);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void onAction(String string, boolean pressed, float f) {
|
|
|
if ("MouseButtonLeft".equals(string)) {
|
|
|
+
|
|
|
+
|
|
|
if (pressed) {
|
|
|
if (!buttonDownL) { // mouse clicked
|
|
|
checkClickL = true;
|
|
@@ -272,6 +323,22 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|
|
}
|
|
|
buttonDownR = pressed;
|
|
|
}
|
|
|
+ if ("MouseButtonMiddle".equals(string)) {
|
|
|
+ if (pressed) {
|
|
|
+ if (!buttonDownM) { // mouse clicked
|
|
|
+ checkClickM = true;
|
|
|
+ checkReleaseM = false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (buttonDownM) { // mouse released
|
|
|
+ checkReleaseM = true;
|
|
|
+ checkClickM = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ buttonDownM = pressed;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public void onJoyAxisEvent(JoyAxisEvent jae) {
|
|
@@ -286,17 +353,29 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|
|
}
|
|
|
|
|
|
public void onMouseButtonEvent(MouseButtonEvent mbe) {
|
|
|
+ //on a click release we request the focus for the top component
|
|
|
+ //this allow netbeans to catch keyEvents and trigger actions according to keymapping
|
|
|
+ if (mbe.isReleased()) {
|
|
|
+ java.awt.EventQueue.invokeLater(new Runnable() {
|
|
|
+
|
|
|
+ public void run() {
|
|
|
+ SceneViewerTopComponent.findInstance().requestActive();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public void onKeyEvent(KeyInputEvent kie) {
|
|
|
}
|
|
|
-
|
|
|
- public void onTouchEvent(TouchEvent evt) {
|
|
|
- }
|
|
|
|
|
|
- /**APPSTATE**/
|
|
|
+ public void onTouchEvent(TouchEvent evt) {
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * APPSTATE*
|
|
|
+ */
|
|
|
private boolean appInit = false;
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void initialize(AppStateManager asm, Application aplctn) {
|
|
|
appInit = true;
|
|
@@ -319,23 +398,32 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|
|
public void update(float f) {
|
|
|
if (moved) {
|
|
|
// moved, check for drags
|
|
|
- if (checkReleaseL || checkReleaseR) {
|
|
|
+ if (checkReleaseL || checkReleaseR || checkReleaseM) {
|
|
|
// drag released
|
|
|
- if (checkReleaseL)
|
|
|
+ if (checkReleaseL) {
|
|
|
checkDragged(0, false);
|
|
|
- if (checkReleaseR)
|
|
|
+ }
|
|
|
+ if (checkReleaseR) {
|
|
|
checkDragged(1, false);
|
|
|
+ }
|
|
|
+ if (checkReleaseM) {
|
|
|
+ checkDragged(2, false);
|
|
|
+ }
|
|
|
checkReleaseL = false;
|
|
|
checkReleaseR = false;
|
|
|
+ checkReleaseM = false;
|
|
|
} else {
|
|
|
- if (buttonDownL)
|
|
|
+ if (buttonDownL) {
|
|
|
checkDragged(0, true);
|
|
|
- else if (buttonDownR)
|
|
|
+ } else if (buttonDownR) {
|
|
|
checkDragged(1, true);
|
|
|
- else
|
|
|
+ } else if (buttonDownM) {
|
|
|
+ checkDragged(2, true);
|
|
|
+ } else {
|
|
|
checkMoved(); // no dragging, just moved
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
moved = false;
|
|
|
} else {
|
|
|
// not moved, check for just clicks
|
|
@@ -355,39 +443,28 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|
|
checkClick(1, false);
|
|
|
checkReleaseR = false;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- /*if (checkDragged || checkDraggedR) {
|
|
|
- if (checkDragged) {
|
|
|
- checkDragged(0);
|
|
|
- checkReleaseLeft = false;
|
|
|
- checkDragged = false;
|
|
|
- checkClick = false;
|
|
|
- checkClickR = false;
|
|
|
- }
|
|
|
- if (checkDraggedR) {
|
|
|
- checkDragged(1);
|
|
|
- checkReleaseRight = false;
|
|
|
- checkDraggedR = false;
|
|
|
- checkClick = false;
|
|
|
- checkClickR = false;
|
|
|
+ if (checkClickM) {
|
|
|
+ checkClick(2, true);
|
|
|
+ checkClickM = false;
|
|
|
}
|
|
|
- } else {
|
|
|
- if (checkClick) {
|
|
|
- checkClick(0, checkReleaseLeft);
|
|
|
- checkReleaseLeft = false;
|
|
|
- checkClick = false;
|
|
|
- checkDragged = false;
|
|
|
- checkDraggedR = false;
|
|
|
+ if (checkReleaseM) {
|
|
|
+ checkClick(2, false);
|
|
|
+ checkReleaseM = false;
|
|
|
}
|
|
|
- if (checkClickR) {
|
|
|
- checkClick(1, checkReleaseRight);
|
|
|
- checkReleaseRight = false;
|
|
|
- checkClickR = false;
|
|
|
- checkDragged = false;
|
|
|
- checkDraggedR = false;
|
|
|
- }
|
|
|
- }*/
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * if (checkDragged || checkDraggedR) { if (checkDragged) {
|
|
|
+ * checkDragged(0); checkReleaseLeft = false; checkDragged = false;
|
|
|
+ * checkClick = false; checkClickR = false; } if (checkDraggedR) {
|
|
|
+ * checkDragged(1); checkReleaseRight = false; checkDraggedR = false;
|
|
|
+ * checkClick = false; checkClickR = false; } } else { if (checkClick) {
|
|
|
+ * checkClick(0, checkReleaseLeft); checkReleaseLeft = false; checkClick
|
|
|
+ * = false; checkDragged = false; checkDraggedR = false; } if
|
|
|
+ * (checkClickR) { checkClick(1, checkReleaseRight); checkReleaseRight =
|
|
|
+ * false; checkClickR = false; checkDragged = false; checkDraggedR =
|
|
|
+ * false; } }
|
|
|
+ */
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -395,14 +472,14 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|
|
* @param pressed true if pressed, false if released
|
|
|
*/
|
|
|
protected abstract void checkClick(int button, boolean pressed);
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Mouse dragged while button is depressed
|
|
|
*/
|
|
|
protected void checkDragged(int button, boolean pressed) {
|
|
|
// override in sub classes
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* The mouse moved, no dragging or buttons pressed
|
|
|
*/
|
|
@@ -427,5 +504,4 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|
|
|
|
|
public void endInput() {
|
|
|
}
|
|
|
-
|
|
|
}
|