SDK : MoveTool fixed imports and formatted the file
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9599 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
458ce63d15
commit
25efcd4f7b
@ -21,7 +21,6 @@ import com.jme3.scene.Geometry;
|
|||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
import com.jme3.scene.Spatial;
|
import com.jme3.scene.Spatial;
|
||||||
import com.jme3.scene.shape.Quad;
|
import com.jme3.scene.shape.Quad;
|
||||||
import com.jme3.util.TempVars;
|
|
||||||
import org.openide.loaders.DataObject;
|
import org.openide.loaders.DataObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,10 +41,9 @@ public class MoveTool extends SceneEditTool {
|
|||||||
private Vector3f offset;
|
private Vector3f offset;
|
||||||
private Node plane;
|
private Node plane;
|
||||||
Material pinkMat;
|
Material pinkMat;
|
||||||
private final Quaternion XY = new Quaternion().fromAngleAxis(0, new Vector3f(1,0,0));
|
private final Quaternion XY = new Quaternion().fromAngleAxis(0, new Vector3f(1, 0, 0));
|
||||||
private final Quaternion YZ = new Quaternion().fromAngleAxis(-FastMath.PI/2, new Vector3f(0,1,0));
|
private final Quaternion YZ = new Quaternion().fromAngleAxis(-FastMath.PI / 2, new Vector3f(0, 1, 0));
|
||||||
private final Quaternion XZ = new Quaternion().fromAngleAxis(FastMath.PI/2, new Vector3f(1,0,0));
|
private final Quaternion XZ = new Quaternion().fromAngleAxis(FastMath.PI / 2, new Vector3f(1, 0, 0));
|
||||||
|
|
||||||
//temp vars
|
//temp vars
|
||||||
private Quaternion rot = new Quaternion();
|
private Quaternion rot = new Quaternion();
|
||||||
private Vector3f newPos = new Vector3f();
|
private Vector3f newPos = new Vector3f();
|
||||||
@ -56,7 +54,7 @@ public class MoveTool extends SceneEditTool {
|
|||||||
|
|
||||||
float size = 1000;
|
float size = 1000;
|
||||||
Geometry g = new Geometry("plane", new Quad(size, size));
|
Geometry g = new Geometry("plane", new Quad(size, size));
|
||||||
g.setLocalTranslation(-size/2, -size/2, 0);
|
g.setLocalTranslation(-size / 2, -size / 2, 0);
|
||||||
plane = new Node();
|
plane = new Node();
|
||||||
plane.attachChild(g);
|
plane.attachChild(g);
|
||||||
|
|
||||||
@ -69,10 +67,6 @@ public class MoveTool extends SceneEditTool {
|
|||||||
displayPlanes();
|
displayPlanes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) {
|
public void actionPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) {
|
||||||
if (!pressed) {
|
if (!pressed) {
|
||||||
@ -88,15 +82,13 @@ public class MoveTool extends SceneEditTool {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) {
|
public void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseMoved(Vector2f screenCoord, JmeNode rootNode, DataObject currentDataObject, JmeSpatial selectedSpatial) {
|
public void mouseMoved(Vector2f screenCoord, JmeNode rootNode, DataObject currentDataObject, JmeSpatial selectedSpatial) {
|
||||||
if (pickedPlane == null) {
|
if (pickedPlane == null) {
|
||||||
highlightAxisMarker(camera, screenCoord, axisPickType);
|
highlightAxisMarker(camera, screenCoord, axisPickType);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
pickedPlane = null;
|
pickedPlane = null;
|
||||||
offset = null;
|
offset = null;
|
||||||
}
|
}
|
||||||
@ -115,26 +107,29 @@ public class MoveTool extends SceneEditTool {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toolController.getSelectedSpatial() == null)
|
if (toolController.getSelectedSpatial() == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (pickedPlane == null) {
|
if (pickedPlane == null) {
|
||||||
pickedPlane = pickAxisMarker(camera, screenCoord, axisPickType);
|
pickedPlane = pickAxisMarker(camera, screenCoord, axisPickType);
|
||||||
if (pickedPlane == null)
|
if (pickedPlane == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
startLoc = toolController.getSelectedSpatial().getLocalTranslation().clone();
|
startLoc = toolController.getSelectedSpatial().getLocalTranslation().clone();
|
||||||
rot = rot.set(toolController.getSelectedSpatial().getWorldRotation());
|
rot = rot.set(toolController.getSelectedSpatial().getWorldRotation());
|
||||||
if (pickedPlane.equals(new Vector3f(1,1,0)))
|
if (pickedPlane.equals(new Vector3f(1, 1, 0))) {
|
||||||
plane.setLocalRotation(rot.multLocal(XY));
|
plane.setLocalRotation(rot.multLocal(XY));
|
||||||
else if (pickedPlane.equals(new Vector3f(1,0,1)))
|
} else if (pickedPlane.equals(new Vector3f(1, 0, 1))) {
|
||||||
plane.setLocalRotation(rot.multLocal(XZ));
|
plane.setLocalRotation(rot.multLocal(XZ));
|
||||||
else if (pickedPlane.equals(new Vector3f(0,1,1)))
|
} else if (pickedPlane.equals(new Vector3f(0, 1, 1))) {
|
||||||
plane.setLocalRotation(rot.multLocal(YZ));
|
plane.setLocalRotation(rot.multLocal(YZ));
|
||||||
|
}
|
||||||
plane.setLocalTranslation(startLoc);
|
plane.setLocalTranslation(startLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3f planeHit = pickWorldLocation(camera, screenCoord, plane, null);
|
Vector3f planeHit = pickWorldLocation(camera, screenCoord, plane, null);
|
||||||
if (planeHit == null){
|
if (planeHit == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,19 +137,19 @@ public class MoveTool extends SceneEditTool {
|
|||||||
Spatial parent = selected.getParent();
|
Spatial parent = selected.getParent();
|
||||||
|
|
||||||
|
|
||||||
if( parent == null ){
|
if (parent == null) {
|
||||||
//we are moving the root node, move is computed in local translation
|
//we are moving the root node, move is computed in local translation
|
||||||
if (offset == null){
|
if (offset == null) {
|
||||||
offset = planeHit.subtract(startLoc); // get the offset when we start so it doesn't jump
|
offset = planeHit.subtract(startLoc); // get the offset when we start so it doesn't jump
|
||||||
}
|
}
|
||||||
|
|
||||||
newPos.set(planeHit).subtractLocal(offset);
|
newPos.set(planeHit).subtractLocal(offset);
|
||||||
lastLoc.set(newPos);
|
lastLoc.set(newPos);
|
||||||
selected.setLocalTranslation(newPos);
|
selected.setLocalTranslation(newPos);
|
||||||
}else{
|
} else {
|
||||||
|
|
||||||
//offset in world space
|
//offset in world space
|
||||||
if (offset == null){
|
if (offset == null) {
|
||||||
offset = planeHit.subtract(selected.getWorldTranslation()); // get the offset when we start so it doesn't jump
|
offset = planeHit.subtract(selected.getWorldTranslation()); // get the offset when we start so it doesn't jump
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,13 +178,12 @@ public class MoveTool extends SceneEditTool {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) {
|
public void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MoveUndo extends AbstractUndoableSceneEdit {
|
private class MoveUndo extends AbstractUndoableSceneEdit {
|
||||||
|
|
||||||
private Spatial spatial;
|
private Spatial spatial;
|
||||||
private Vector3f before,after;
|
private Vector3f before, after;
|
||||||
|
|
||||||
MoveUndo(Spatial spatial, Vector3f before, Vector3f after) {
|
MoveUndo(Spatial spatial, Vector3f before, Vector3f after) {
|
||||||
this.spatial = spatial;
|
this.spatial = spatial;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user