- fix threading in AbstractCameraController

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8641 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 13 years ago
parent e291dc9906
commit a2c9d066d8
  1. 16
      sdk/jme3-core/src/com/jme3/gde/core/scene/SceneApplication.java
  2. 60
      sdk/jme3-core/src/com/jme3/gde/core/scene/controller/AbstractCameraController.java

@ -355,17 +355,17 @@ public class SceneApplication extends Application implements LookupProvider {
}
setHelpContext(request.getHelpCtx());
setWindowTitle(request.getWindowTitle());
if (request.getRequester() instanceof SceneApplication) {
camController.enable();
} else {
camController.disable();
}
enqueue(new Callable() {
public Object call() throws Exception {
if (request.getManager() != null) {
assetManager = request.getManager();
}
if (request.getRequester() instanceof SceneApplication) {
camController.enable();
} else {
camController.disable();
}
Spatial model = request.getRootNode();
if (model == null) {
StatusDisplayer.getDefault().setStatusText("could not load Spatial from request: " + getCurrentSceneRequest().getWindowTitle());
@ -412,12 +412,12 @@ public class SceneApplication extends Application implements LookupProvider {
setWindowTitle("OpenGL Window");
setHelpContext(null);
}
if (oldRequest.getRequester() instanceof SceneApplication) {
camController.disable();
}
enqueue(new Callable() {
public Object call() throws Exception {
if (oldRequest.getRequester() instanceof SceneApplication) {
camController.disable();
}
if (physicsState != null) {
physicsState.getPhysicsSpace().removeAll(rootNode);
getStateManager().detach(physicsState);

@ -95,17 +95,24 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
}
public void enable() {
inputManager.addRawInputListener(this);
inputManager.addListener(this, "MouseAxisX", "MouseAxisY", "MouseAxisX-", "MouseAxisY-", "MouseWheel", "MouseWheel-", "MouseButtonLeft", "MouseButtonMiddle", "MouseButtonRight");
SceneApplication.getApplication().getStateManager().attach(this);
AbstractCameraController cc = SceneApplication.getApplication().getActiveCameraController();
if (cc != null) {
cam.setLocation(cc.cam.getLocation());
focus.set(cc.focus);
}
final AbstractCameraController cc = SceneApplication.getApplication().getActiveCameraController();
SceneApplication.getApplication().setActiveCameraController(this);
addAdditionnalToolbar();
final AbstractCameraController me = this;
SceneApplication.getApplication().enqueue(new Callable<Object>() {
public Object call() throws Exception {
if (cc != null) {
cam.setLocation(cc.cam.getLocation());
focus.set(cc.focus);
}
inputManager.addRawInputListener(me);
inputManager.addListener(me, "MouseAxisX", "MouseAxisY", "MouseAxisX-", "MouseAxisY-", "MouseWheel", "MouseWheel-", "MouseButtonLeft", "MouseButtonMiddle", "MouseButtonRight");
return null;
}
});
}
private void addAdditionnalToolbar() {
@ -126,12 +133,19 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
}
public void disable() {
inputManager.removeRawInputListener(this);
inputManager.removeListener(this);
SceneApplication.getApplication().getStateManager().detach(this);
if (SceneApplication.getApplication().getActiveCameraController() == this) {
removeAdditionnalToolbar();
}
final AbstractCameraController me = this;
SceneApplication.getApplication().enqueue(new Callable<Object>() {
public Object call() throws Exception {
inputManager.removeRawInputListener(me);
inputManager.removeListener(me);
return null;
}
});
}
public void setCamFocus(final Vector3f focus) {
@ -153,7 +167,7 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
/*
* methods to move camera
*/
protected void rotateCamera(Vector3f axis, float amount) {
protected void doRotateCamera(Vector3f axis, float amount) {
if (axis.equals(cam.getLeft())) {
float elevation = -FastMath.asin(cam.getDirection().y);
amount = Math.min(Math.max(elevation + amount,
@ -180,7 +194,7 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
});
}
protected void panCamera(float left, float up) {
protected void doPanCamera(float left, float up) {
cam.getLeft().mult(left, vector);
vector.scaleAdd(up, cam.getUp(), vector);
vector.multLocal(cam.getLocation().distance(focus));
@ -188,12 +202,12 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
focus.addLocal(vector);
}
protected void moveCamera(float forward) {
protected void doMoveCamera(float forward) {
cam.getDirection().mult(forward, vector);
cam.setLocation(cam.getLocation().add(vector));
}
protected void zoomCamera(float amount) {
protected void doZoomCamera(float amount) {
amount = cam.getLocation().distance(focus) * amount;
float dist = cam.getLocation().distance(focus);
amount = dist - Math.max(0f, dist - amount);
@ -294,10 +308,10 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
movedR = true;
if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) {
rotateCamera(Vector3f.UNIT_Y, -f1 * 2.5f);
doRotateCamera(Vector3f.UNIT_Y, -f1 * 2.5f);
}
if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) {
panCamera(f1 * 2.5f, 0);
doPanCamera(f1 * 2.5f, 0);
}
} else if ("MouseAxisY".equals(string)) {
@ -305,10 +319,10 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
movedR = true;
if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) {
rotateCamera(cam.getLeft(), -f1 * 2.5f);
doRotateCamera(cam.getLeft(), -f1 * 2.5f);
}
if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) {
panCamera(0, -f1 * 2.5f);
doPanCamera(0, -f1 * 2.5f);
}
} else if ("MouseAxisX-".equals(string)) {
@ -316,10 +330,10 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
movedR = true;
if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) {
rotateCamera(Vector3f.UNIT_Y, f1 * 2.5f);
doRotateCamera(Vector3f.UNIT_Y, f1 * 2.5f);
}
if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) {
panCamera(-f1 * 2.5f, 0);
doPanCamera(-f1 * 2.5f, 0);
}
} else if ("MouseAxisY-".equals(string)) {
@ -327,16 +341,16 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
movedR = true;
if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) {
rotateCamera(cam.getLeft(), f1 * 2.5f);
doRotateCamera(cam.getLeft(), f1 * 2.5f);
}
if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) {
panCamera(0, f1 * 2.5f);
doPanCamera(0, f1 * 2.5f);
}
} else if ("MouseWheel".equals(string)) {
zoomCamera(.1f);
doZoomCamera(.1f);
} else if ("MouseWheel-".equals(string)) {
zoomCamera(-.1f);
doZoomCamera(-.1f);
}
}

Loading…
Cancel
Save