Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -57,13 +57,13 @@ public void initiatePick(Spatial selectedSpatial, Quaternion planeRotation, Scen
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) {
Expand All @@ -74,12 +74,18 @@ public void setTransformation(Quaternion planeRotation, SceneComposerToolControl
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();
Expand Down Expand Up @@ -131,23 +137,26 @@ public float getAngle() {
* @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);
Expand Down Expand Up @@ -178,8 +187,7 @@ public Vector3f getTranslation(Vector3f axisConstrainte) {
* @return
*/
public Vector3f getLocalTranslation(Vector3f axisConstrainte) {
//return plane.getWorldRotation().inverse().mult(getTranslation(axisConstrainte));
return getTranslation(origineRotation.inverse().mult(axisConstrainte));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void draggedPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNo
}

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;
}
Expand Down