- Blender style rotation now rotates objects in world space and parent rotation are correctly taken into account.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9606 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 13 years ago
parent 68e17702e2
commit 3f8d7f0807
  1. 43
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/SelectTool.java

@ -166,6 +166,7 @@ public class SelectTool extends SceneEditTool {
startScale = null; startScale = null;
startMouseCoord = null; startMouseCoord = null;
startSelectedCoord = null; startSelectedCoord = null;
lastRotAngle = 0;
} }
private void recordInitialState(Spatial selected) { private void recordInitialState(Spatial selected) {
@ -229,6 +230,7 @@ public class SelectTool extends SceneEditTool {
actionPerformed(undo); actionPerformed(undo);
toolController.updateSelection(null);// force a re-draw of the bbox shape toolController.updateSelection(null);// force a re-draw of the bbox shape
toolController.updateSelection(selected); toolController.updateSelection(selected);
} }
clearState(false); clearState(false);
} }
@ -286,42 +288,32 @@ public class SelectTool extends SceneEditTool {
private boolean checkAxisKey(KeyInputEvent kie) { private boolean checkAxisKey(KeyInputEvent kie) {
if (kie.getKeyCode() == KeyInput.KEY_X) { if (kie.getKeyCode() == KeyInput.KEY_X) {
currentAxis = Vector3f.UNIT_X; currentAxis = Vector3f.UNIT_X;
MoveManager moveManager = Lookup.getDefault().lookup(MoveManager.class); checkMovePlane(MoveManager.XY, MoveManager.XZ);
Quaternion rot = camera.getRotation().mult(new Quaternion().fromAngleAxis(FastMath.PI, Vector3f.UNIT_Y));
Quaternion planRot = null;
if (rot.dot(MoveManager.XY) < rot.dot(MoveManager.XZ)) {
planRot = MoveManager.XY;
} else {
planRot = MoveManager.XZ;
}
moveManager.updatePlaneRotation(planRot);
return true; return true;
} else if (kie.getKeyCode() == KeyInput.KEY_Y) { } else if (kie.getKeyCode() == KeyInput.KEY_Y) {
currentAxis = Vector3f.UNIT_Y; currentAxis = Vector3f.UNIT_Y;
MoveManager moveManager = Lookup.getDefault().lookup(MoveManager.class); checkMovePlane(MoveManager.XY, MoveManager.YZ);
Quaternion rot = camera.getRotation().mult(new Quaternion().fromAngleAxis(FastMath.PI, Vector3f.UNIT_Y));
Quaternion planRot = null;
if (rot.dot(MoveManager.XY) < rot.dot(MoveManager.YZ)) {
planRot = MoveManager.XY;
} else {
planRot = MoveManager.YZ;
}
moveManager.updatePlaneRotation(planRot);
return true; return true;
} else if (kie.getKeyCode() == KeyInput.KEY_Z) { } else if (kie.getKeyCode() == KeyInput.KEY_Z) {
currentAxis = Vector3f.UNIT_Z; currentAxis = Vector3f.UNIT_Z;
checkMovePlane(MoveManager.XZ, MoveManager.YZ);
return true;
}
return false;
}
private void checkMovePlane(Quaternion rot1, Quaternion rot2) {
if (currentState == State.translate) {
MoveManager moveManager = Lookup.getDefault().lookup(MoveManager.class); MoveManager moveManager = Lookup.getDefault().lookup(MoveManager.class);
Quaternion rot = camera.getRotation().mult(new Quaternion().fromAngleAxis(FastMath.PI, Vector3f.UNIT_Y)); Quaternion rot = camera.getRotation().mult(new Quaternion().fromAngleAxis(FastMath.PI, Vector3f.UNIT_Y));
Quaternion planRot = null; Quaternion planRot = null;
if (rot.dot(MoveManager.XZ) < rot.dot(MoveManager.YZ)) { if (rot.dot(rot1) < rot.dot(rot2)) {
planRot = MoveManager.XZ; planRot = rot1;
} else { } else {
planRot = MoveManager.YZ; planRot = rot2;
} }
moveManager.updatePlaneRotation(planRot); moveManager.updatePlaneRotation(planRot);
return true;
} }
return false;
} }
private boolean checkNumberKey(KeyInputEvent kie) { private boolean checkNumberKey(KeyInputEvent kie) {
@ -619,10 +611,9 @@ public class SelectTool extends SceneEditTool {
Quaternion rotate = new Quaternion(); Quaternion rotate = new Quaternion();
if (axis != Vector3f.UNIT_XYZ) { if (axis != Vector3f.UNIT_XYZ) {
rotate = rotate.fromAngleAxis(newRotAngle, axis); rotate = rotate.fromAngleAxis(newRotAngle, selected.getWorldRotation().inverse().mult(axis));
} else { } else {
//Vector3f screen = getCamera().getLocation().subtract(selected.getWorldTranslation()).normalize(); rotate = rotate.fromAngleAxis(newRotAngle, selected.getWorldRotation().inverse().mult(getCamera().getDirection().mult(-1).normalizeLocal()));
rotate = rotate.fromAngleAxis(newRotAngle, getCamera().getDirection());
} }
selected.setLocalRotation(selected.getLocalRotation().mult(rotate)); selected.setLocalRotation(selected.getLocalRotation().mult(rotate));

Loading…
Cancel
Save