From 82f031cdff495d70e81b041e1bbd80c0b9dbd110 Mon Sep 17 00:00:00 2001 From: Maselbas Date: Fri, 1 May 2015 19:25:14 +0200 Subject: [PATCH] SDK SceneComposer : fixed the rotate tool, now all works fine, Great Success ! --- .../gde/scenecomposer/tools/PickManager.java | 44 +++++++++++-------- .../gde/scenecomposer/tools/RotateTool.java | 2 +- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/PickManager.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/PickManager.java index fc0032edb..22fa8478a 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/PickManager.java +++ b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/PickManager.java @@ -32,7 +32,7 @@ public class PickManager { private final Node plane; private Spatial spatial; private SceneComposerToolController.TransformationType transformationType; - + protected static final Quaternion PLANE_XY = new Quaternion().fromAngleAxis(0, new Vector3f(1, 0, 0)); protected static final Quaternion PLANE_YZ = new Quaternion().fromAngleAxis(-FastMath.PI / 2, new Vector3f(0, 1, 0));//YAW090 protected static final Quaternion PLANE_XZ = new Quaternion().fromAngleAxis(FastMath.PI / 2, new Vector3f(1, 0, 0)); //PITCH090 @@ -57,13 +57,13 @@ public class PickManager { spatial = selectedSpatial; startSpatialLocation = selectedSpatial.getWorldTranslation().clone(); - setTransformation(planeRotation, type); + setTransformation(planeRotation, type, camera); plane.setLocalTranslation(startSpatialLocation); startPickLoc = SceneEditTool.pickWorldLocation(camera, screenCoord, plane, null); } - public void setTransformation(Quaternion planeRotation, SceneComposerToolController.TransformationType type) { + public void setTransformation(Quaternion planeRotation, SceneComposerToolController.TransformationType type, Camera camera) { Quaternion rot = new Quaternion(); transformationType = type; if (transformationType == SceneComposerToolController.TransformationType.local) { @@ -74,12 +74,18 @@ public class PickManager { rot.set(planeRotation); origineRotation = new Quaternion(Quaternion.IDENTITY); } else if (transformationType == SceneComposerToolController.TransformationType.camera) { - rot.set(planeRotation); - origineRotation = planeRotation.clone(); + rot.set(camera.getRotation()); + origineRotation = camera.getRotation().clone(); } plane.setLocalRotation(rot); } - + + /** + * + * @param camera + * @param screenCoord + * @return true if the the new picked location is set, else return false. + */ public boolean updatePick(Camera camera, Vector2f screenCoord) { if(transformationType == SceneComposerToolController.TransformationType.camera){ origineRotation = camera.getRotation(); @@ -131,23 +137,26 @@ public class PickManager { * @return the Quaternion rotation in the WorldSpace */ public Quaternion getRotation() { - Vector3f v1, v2; - v1 = startPickLoc.subtract(startSpatialLocation).normalize(); - v2 = finalPickLoc.subtract(startSpatialLocation).normalize(); - Vector3f axis = v1.cross(v2); - float angle = v1.angleBetween(v2); - return new Quaternion().fromAngleAxis(angle, axis); + return getRotation(Quaternion.IDENTITY); } /** - * + * * @return the Quaternion rotation in the ToolSpace */ public Quaternion getLocalRotation() { + return getRotation(origineRotation.inverse()); + } + + /** + * Get the Rotation into a specific custom space. + * @param transforme the rotation to the custom space (World to Custom space) + * @return the Rotation in the custom space + */ + public Quaternion getRotation(Quaternion transforme) { Vector3f v1, v2; - Quaternion rot = origineRotation.inverse(); - v1 = rot.mult(startPickLoc.subtract(startSpatialLocation).normalize()); - v2 = rot.mult(finalPickLoc.subtract(startSpatialLocation).normalize()); + v1 = transforme.mult(startPickLoc.subtract(startSpatialLocation).normalize()); + v2 = transforme.mult(finalPickLoc.subtract(startSpatialLocation).normalize()); Vector3f axis = v1.cross(v2); float angle = v1.angleBetween(v2); return new Quaternion().fromAngleAxis(angle, axis); @@ -178,8 +187,7 @@ public class PickManager { * @return */ public Vector3f getLocalTranslation(Vector3f axisConstrainte) { - //return plane.getWorldRotation().inverse().mult(getTranslation(axisConstrainte)); return getTranslation(origineRotation.inverse().mult(axisConstrainte)); } - + } diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/RotateTool.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/RotateTool.java index 58c69f516..21e9a56d8 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/RotateTool.java +++ b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/RotateTool.java @@ -113,7 +113,7 @@ public class RotateTool extends SceneEditTool { } if (pickedMarker.equals(QUAD_XY) || pickedMarker.equals(QUAD_XZ) || pickedMarker.equals(QUAD_YZ)) { - Quaternion rotation = startRotate.mult(pickManager.getLocalRotation()); + Quaternion rotation = startRotate.mult(pickManager.getRotation(startRotate.inverse())); toolController.getSelectedSpatial().setLocalRotation(rotation); lastRotate = rotation; }