SDK:
- fix threading in AbstractCameraController git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8641 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
e291dc9906
commit
a2c9d066d8
@ -355,17 +355,17 @@ public class SceneApplication extends Application implements LookupProvider {
|
|||||||
}
|
}
|
||||||
setHelpContext(request.getHelpCtx());
|
setHelpContext(request.getHelpCtx());
|
||||||
setWindowTitle(request.getWindowTitle());
|
setWindowTitle(request.getWindowTitle());
|
||||||
|
if (request.getRequester() instanceof SceneApplication) {
|
||||||
|
camController.enable();
|
||||||
|
} else {
|
||||||
|
camController.disable();
|
||||||
|
}
|
||||||
enqueue(new Callable() {
|
enqueue(new Callable() {
|
||||||
|
|
||||||
public Object call() throws Exception {
|
public Object call() throws Exception {
|
||||||
if (request.getManager() != null) {
|
if (request.getManager() != null) {
|
||||||
assetManager = request.getManager();
|
assetManager = request.getManager();
|
||||||
}
|
}
|
||||||
if (request.getRequester() instanceof SceneApplication) {
|
|
||||||
camController.enable();
|
|
||||||
} else {
|
|
||||||
camController.disable();
|
|
||||||
}
|
|
||||||
Spatial model = request.getRootNode();
|
Spatial model = request.getRootNode();
|
||||||
if (model == null) {
|
if (model == null) {
|
||||||
StatusDisplayer.getDefault().setStatusText("could not load Spatial from request: " + getCurrentSceneRequest().getWindowTitle());
|
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");
|
setWindowTitle("OpenGL Window");
|
||||||
setHelpContext(null);
|
setHelpContext(null);
|
||||||
}
|
}
|
||||||
|
if (oldRequest.getRequester() instanceof SceneApplication) {
|
||||||
|
camController.disable();
|
||||||
|
}
|
||||||
enqueue(new Callable() {
|
enqueue(new Callable() {
|
||||||
|
|
||||||
public Object call() throws Exception {
|
public Object call() throws Exception {
|
||||||
if (oldRequest.getRequester() instanceof SceneApplication) {
|
|
||||||
camController.disable();
|
|
||||||
}
|
|
||||||
if (physicsState != null) {
|
if (physicsState != null) {
|
||||||
physicsState.getPhysicsSpace().removeAll(rootNode);
|
physicsState.getPhysicsSpace().removeAll(rootNode);
|
||||||
getStateManager().detach(physicsState);
|
getStateManager().detach(physicsState);
|
||||||
|
@ -95,17 +95,24 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void enable() {
|
public void enable() {
|
||||||
inputManager.addRawInputListener(this);
|
|
||||||
inputManager.addListener(this, "MouseAxisX", "MouseAxisY", "MouseAxisX-", "MouseAxisY-", "MouseWheel", "MouseWheel-", "MouseButtonLeft", "MouseButtonMiddle", "MouseButtonRight");
|
|
||||||
SceneApplication.getApplication().getStateManager().attach(this);
|
SceneApplication.getApplication().getStateManager().attach(this);
|
||||||
AbstractCameraController cc = SceneApplication.getApplication().getActiveCameraController();
|
final AbstractCameraController cc = SceneApplication.getApplication().getActiveCameraController();
|
||||||
if (cc != null) {
|
|
||||||
cam.setLocation(cc.cam.getLocation());
|
|
||||||
focus.set(cc.focus);
|
|
||||||
}
|
|
||||||
|
|
||||||
SceneApplication.getApplication().setActiveCameraController(this);
|
SceneApplication.getApplication().setActiveCameraController(this);
|
||||||
addAdditionnalToolbar();
|
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() {
|
private void addAdditionnalToolbar() {
|
||||||
@ -126,12 +133,19 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void disable() {
|
public void disable() {
|
||||||
inputManager.removeRawInputListener(this);
|
|
||||||
inputManager.removeListener(this);
|
|
||||||
SceneApplication.getApplication().getStateManager().detach(this);
|
SceneApplication.getApplication().getStateManager().detach(this);
|
||||||
if (SceneApplication.getApplication().getActiveCameraController() == this) {
|
if (SceneApplication.getApplication().getActiveCameraController() == this) {
|
||||||
removeAdditionnalToolbar();
|
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) {
|
public void setCamFocus(final Vector3f focus) {
|
||||||
@ -153,7 +167,7 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|||||||
/*
|
/*
|
||||||
* methods to move camera
|
* methods to move camera
|
||||||
*/
|
*/
|
||||||
protected void rotateCamera(Vector3f axis, float amount) {
|
protected void doRotateCamera(Vector3f axis, float amount) {
|
||||||
if (axis.equals(cam.getLeft())) {
|
if (axis.equals(cam.getLeft())) {
|
||||||
float elevation = -FastMath.asin(cam.getDirection().y);
|
float elevation = -FastMath.asin(cam.getDirection().y);
|
||||||
amount = Math.min(Math.max(elevation + amount,
|
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);
|
cam.getLeft().mult(left, vector);
|
||||||
vector.scaleAdd(up, cam.getUp(), vector);
|
vector.scaleAdd(up, cam.getUp(), vector);
|
||||||
vector.multLocal(cam.getLocation().distance(focus));
|
vector.multLocal(cam.getLocation().distance(focus));
|
||||||
@ -188,12 +202,12 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|||||||
focus.addLocal(vector);
|
focus.addLocal(vector);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void moveCamera(float forward) {
|
protected void doMoveCamera(float forward) {
|
||||||
cam.getDirection().mult(forward, vector);
|
cam.getDirection().mult(forward, vector);
|
||||||
cam.setLocation(cam.getLocation().add(vector));
|
cam.setLocation(cam.getLocation().add(vector));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void zoomCamera(float amount) {
|
protected void doZoomCamera(float amount) {
|
||||||
amount = cam.getLocation().distance(focus) * amount;
|
amount = cam.getLocation().distance(focus) * amount;
|
||||||
float dist = cam.getLocation().distance(focus);
|
float dist = cam.getLocation().distance(focus);
|
||||||
amount = dist - Math.max(0f, dist - amount);
|
amount = dist - Math.max(0f, dist - amount);
|
||||||
@ -294,10 +308,10 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|||||||
movedR = true;
|
movedR = true;
|
||||||
|
|
||||||
if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) {
|
if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) {
|
||||||
rotateCamera(Vector3f.UNIT_Y, -f1 * 2.5f);
|
doRotateCamera(Vector3f.UNIT_Y, -f1 * 2.5f);
|
||||||
}
|
}
|
||||||
if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) {
|
if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) {
|
||||||
panCamera(f1 * 2.5f, 0);
|
doPanCamera(f1 * 2.5f, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ("MouseAxisY".equals(string)) {
|
} else if ("MouseAxisY".equals(string)) {
|
||||||
@ -305,10 +319,10 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|||||||
movedR = true;
|
movedR = true;
|
||||||
|
|
||||||
if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) {
|
if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) {
|
||||||
rotateCamera(cam.getLeft(), -f1 * 2.5f);
|
doRotateCamera(cam.getLeft(), -f1 * 2.5f);
|
||||||
}
|
}
|
||||||
if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) {
|
if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) {
|
||||||
panCamera(0, -f1 * 2.5f);
|
doPanCamera(0, -f1 * 2.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ("MouseAxisX-".equals(string)) {
|
} else if ("MouseAxisX-".equals(string)) {
|
||||||
@ -316,10 +330,10 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|||||||
movedR = true;
|
movedR = true;
|
||||||
|
|
||||||
if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) {
|
if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) {
|
||||||
rotateCamera(Vector3f.UNIT_Y, f1 * 2.5f);
|
doRotateCamera(Vector3f.UNIT_Y, f1 * 2.5f);
|
||||||
}
|
}
|
||||||
if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) {
|
if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) {
|
||||||
panCamera(-f1 * 2.5f, 0);
|
doPanCamera(-f1 * 2.5f, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ("MouseAxisY-".equals(string)) {
|
} else if ("MouseAxisY-".equals(string)) {
|
||||||
@ -327,16 +341,16 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
|
|||||||
movedR = true;
|
movedR = true;
|
||||||
|
|
||||||
if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) {
|
if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) {
|
||||||
rotateCamera(cam.getLeft(), f1 * 2.5f);
|
doRotateCamera(cam.getLeft(), f1 * 2.5f);
|
||||||
}
|
}
|
||||||
if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) {
|
if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) {
|
||||||
panCamera(0, f1 * 2.5f);
|
doPanCamera(0, f1 * 2.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ("MouseWheel".equals(string)) {
|
} else if ("MouseWheel".equals(string)) {
|
||||||
zoomCamera(.1f);
|
doZoomCamera(.1f);
|
||||||
} else if ("MouseWheel-".equals(string)) {
|
} else if ("MouseWheel-".equals(string)) {
|
||||||
zoomCamera(-.1f);
|
doZoomCamera(-.1f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user