aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-extras
diff options
context:
space:
mode:
Diffstat (limited to 'ardor3d-extras')
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/interact/InteractManager.java4
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/AbstractInteractWidget.java127
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MoveMultiPlanarWidget.java72
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MovePlanarWidget.java73
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MoveWidget.java67
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/RotateWidget.java118
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/SimpleScaleWidget.java57
7 files changed, 262 insertions, 256 deletions
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/InteractManager.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/InteractManager.java
index 7974a4b..bbabef3 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/InteractManager.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/InteractManager.java
@@ -216,6 +216,10 @@ public class InteractManager {
}
public void setActiveWidget(final AbstractInteractWidget widget) {
+ if (_activeWidget == widget) {
+ return;
+ }
+
if (_activeWidget != null) {
_activeWidget.lostControl(this);
}
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/AbstractInteractWidget.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/AbstractInteractWidget.java
index 2292ad2..04d7c97 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/AbstractInteractWidget.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/AbstractInteractWidget.java
@@ -16,8 +16,12 @@ import com.ardor3d.bounding.BoundingVolume;
import com.ardor3d.extension.interact.InteractManager;
import com.ardor3d.extension.interact.filter.UpdateFilter;
import com.ardor3d.framework.Canvas;
+import com.ardor3d.input.ButtonState;
import com.ardor3d.input.MouseButton;
+import com.ardor3d.input.MouseState;
import com.ardor3d.input.logical.TwoInputStates;
+import com.ardor3d.intersection.PickData;
+import com.ardor3d.intersection.Pickable;
import com.ardor3d.intersection.PickingUtil;
import com.ardor3d.intersection.PrimitivePickResults;
import com.ardor3d.math.Ray3;
@@ -32,8 +36,10 @@ import com.ardor3d.util.ReadOnlyTimer;
public abstract class AbstractInteractWidget {
+ public static double MIN_SCALE = 0.000001;
+
protected Node _handle;
- protected boolean _flipPickRay, _dragging = false;
+ protected boolean _flipPickRay, _dragging, _mouseOver = false;
protected MouseButton _dragButton = MouseButton.LEFT;
protected boolean _activeInputOnly = true;
@@ -47,6 +53,9 @@ public abstract class AbstractInteractWidget {
protected final Vector3 _calcVec3D = new Vector3();
protected PrimitivePickResults _results = new PrimitivePickResults();
+ protected Spatial _lastDragSpatial = null;
+ protected Spatial _lastMouseOverSpatial = null;
+
protected InteractMatrix _interactMatrix = InteractMatrix.World;
/** List of filters to modify state after applying input. */
@@ -79,13 +88,104 @@ public abstract class AbstractInteractWidget {
_filters.applyFilters(manager);
}
+ protected void checkMouseOver(final Camera camera, final MouseState current, final InteractManager manager) {
+ // If we are dragging, we're in mouseOver state.
+ if (_dragging) {
+ if (!_mouseOver) {
+ mouseEntered(manager);
+ }
+ return;
+ }
+
+ // Make sure we have something to modify
+ if (manager.getSpatialTarget() == null) {
+ if (_mouseOver) {
+ mouseDeparted(manager);
+ }
+ return;
+ }
+
+ final Vector2 currMouse = new Vector2(current.getX(), current.getY());
+ findPick(currMouse, camera);
+ final Vector3 lastPick = getLastPick();
+ if (lastPick == null) {
+ if (_mouseOver) {
+ mouseDeparted(manager);
+ return;
+ }
+ } else if (!_mouseOver) {
+ mouseEntered(manager);
+ }
+ }
+
+ public void mouseEntered(final InteractManager manager) {
+ final PickData pickData = _results.getPickData(0);
+ _lastMouseOverSpatial = (Spatial) pickData.getTarget();
+ _mouseOver = true;
+ targetDataUpdated(manager);
+ }
+
+ public void mouseDeparted(final InteractManager manager) {
+ _lastMouseOverSpatial = null;
+ _mouseOver = false;
+ targetDataUpdated(manager);
+ }
+
+ protected boolean checkShouldDrag(final Camera camera, final MouseState current, final MouseState previous,
+ final AtomicBoolean inputConsumed, final InteractManager manager) {
+ // Make sure we have something to modify
+ if (manager.getSpatialTarget() == null) {
+ return false;
+ }
+
+ // Make sure we are dragging.
+ if (current.getButtonState(_dragButton) != ButtonState.DOWN) {
+ if (_dragging) {
+ endDrag(manager);
+ }
+ return false;
+ }
+ // if we're already dragging, make sure we only act on drags that started with a positive pick.
+ else if (!current.getButtonsPressedSince(previous).contains(_dragButton) && !_dragging) {
+ return false;
+ }
+
+ final Vector2 oldMouse = new Vector2(previous.getX(), previous.getY());
+ // Make sure we are dragging over the handle
+ if (!_dragging) {
+ findPick(oldMouse, camera);
+ final Vector3 lastPick = getLastPick();
+ if (lastPick == null) {
+ _lastDragSpatial = null;
+ return false;
+ } else {
+ beginDrag(manager);
+ }
+ }
+
+ // we've established that our mouse is being held down, and started over our arrow. So consume.
+ inputConsumed.set(true);
+
+ // check if we've moved at all
+ if (current == previous || current.getDx() == 0 && current.getDy() == 0) {
+ return false;
+ }
+
+ return true;
+ }
+
public void beginDrag(final InteractManager manager) {
- _dragging = true;
- _filters.beginDrag(manager);
+ if (_results.getNumber() > 0) {
+ final PickData pickData = _results.getPickData(0);
+ _lastDragSpatial = (Spatial) pickData.getTarget();
+ _dragging = true;
+ _filters.beginDrag(manager);
+ }
}
public void endDrag(final InteractManager manager) {
_dragging = false;
+ _lastDragSpatial = null;
_filters.endDrag(manager);
}
@@ -98,8 +198,8 @@ public abstract class AbstractInteractWidget {
if (target != null && target.getWorldBound() != null) {
final BoundingVolume bound = target.getWorldBound();
final ReadOnlyVector3 trans = target.getWorldTranslation();
- return Math.max(MoveWidget.MIN_SCALE, bound.getRadius()
- + trans.subtract(bound.getCenter(), _calcVec3A).length());
+ return Math.max(AbstractInteractWidget.MIN_SCALE,
+ bound.getRadius() + trans.subtract(bound.getCenter(), _calcVec3A).length());
}
return 1.0;
@@ -107,7 +207,15 @@ public abstract class AbstractInteractWidget {
public void render(final Renderer renderer, final InteractManager manager) { /**/}
- public void targetChanged(final InteractManager manager) { /**/}
+ public void targetChanged(final InteractManager manager) {
+ if (_dragging) {
+ endDrag(manager);
+ }
+ if (_mouseOver) {
+ mouseDeparted(manager);
+ }
+ targetDataUpdated(manager);
+ }
public void targetDataUpdated(final InteractManager manager) { /**/}
@@ -170,6 +278,13 @@ public abstract class AbstractInteractWidget {
return null;
}
+ protected Pickable getLastPickable() {
+ if (_results.getNumber() > 0) {
+ return _results.getPickData(0).getTarget();
+ }
+ return null;
+ }
+
protected void findPick(final Vector2 mouseLoc, final Camera camera) {
getPickRay(mouseLoc, camera);
_results.clear();
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MoveMultiPlanarWidget.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MoveMultiPlanarWidget.java
index 8830456..dc2bebd 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MoveMultiPlanarWidget.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MoveMultiPlanarWidget.java
@@ -15,7 +15,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import com.ardor3d.extension.interact.InteractManager;
import com.ardor3d.framework.Canvas;
-import com.ardor3d.input.ButtonState;
import com.ardor3d.input.MouseState;
import com.ardor3d.input.logical.TwoInputStates;
import com.ardor3d.intersection.PickData;
@@ -43,7 +42,9 @@ import com.ardor3d.scenegraph.shape.Box;
import com.ardor3d.util.geom.BufferUtils;
public class MoveMultiPlanarWidget extends AbstractInteractWidget {
- public static double MIN_SCALE = 0.000001;
+
+ public static double DEFAULT_SCALE = 1.0;
+ public static double MOUSEOVER_SCALE = 1.1;
public MoveMultiPlanarWidget(final IFilterList filterList) {
this(filterList, 0.5);
@@ -94,14 +95,6 @@ public class MoveMultiPlanarWidget extends AbstractInteractWidget {
}
@Override
- public void targetChanged(final InteractManager manager) {
- if (_dragging) {
- endDrag(manager);
- }
- targetDataUpdated(manager);
- }
-
- @Override
public void targetDataUpdated(final InteractManager manager) {
final Spatial target = manager.getSpatialTarget();
if (target == null) {
@@ -121,6 +114,12 @@ public class MoveMultiPlanarWidget extends AbstractInteractWidget {
}
@Override
+ protected double calculateHandleScale(final InteractManager manager) {
+ return super.calculateHandleScale(manager)
+ * (_mouseOver ? MoveMultiPlanarWidget.MOUSEOVER_SCALE : MoveMultiPlanarWidget.DEFAULT_SCALE);
+ }
+
+ @Override
public void render(final Renderer renderer, final InteractManager manager) {
final Spatial spat = manager.getSpatialTarget();
if (spat == null) {
@@ -136,57 +135,30 @@ public class MoveMultiPlanarWidget extends AbstractInteractWidget {
@Override
public void processInput(final Canvas source, final TwoInputStates inputStates, final AtomicBoolean inputConsumed,
final InteractManager manager) {
- // Make sure we have something to modify
- if (manager.getSpatialTarget() == null) {
- return;
- }
- // Make sure we are dragging.
+ final Camera camera = source.getCanvasRenderer().getCamera();
final MouseState current = inputStates.getCurrent().getMouseState();
final MouseState previous = inputStates.getPrevious().getMouseState();
- if (current.getButtonState(_dragButton) != ButtonState.DOWN) {
- if (_dragging) {
- endDrag(manager);
- }
- return;
- }
- // if we're already dragging, make sure we only act on drags that started with a positive pick.
- else if (!current.getButtonsPressedSince(previous).contains(_dragButton) && !_dragging) {
- return;
- }
-
- final Camera camera = source.getCanvasRenderer().getCamera();
- final Vector2 oldMouse = new Vector2(previous.getX(), previous.getY());
- // Make sure we are dragging over the handle
- if (!_dragging) {
- findPick(oldMouse, camera);
- final Vector3 lastPick = getLastPick();
- if (lastPick == null) {
- return;
- } else {
- beginDrag(manager);
- }
- }
-
- // we've established that our mouse is being held down, and started over our arrow. So consume.
- inputConsumed.set(true);
+ // first process mouse over state
+ checkMouseOver(camera, current, manager);
- // check if we've moved at all
- if (current == previous || current.getDx() == 0 && current.getDy() == 0) {
+ // Now check drag status
+ if (!checkShouldDrag(camera, current, previous, inputConsumed, manager)) {
return;
}
// act on drag
- final PickData pickData = _results.getPickData(0);
- final Spatial picked = (Spatial) pickData.getTarget();
- if (picked instanceof Mesh && pickData.getIntersectionRecord().getNumberOfIntersections() > 0) {
+ final PickData pickData = _results.getNumber() > 0 ? _results.getPickData(0) : null;
+ if (pickData != null && _lastDragSpatial instanceof Mesh
+ && pickData.getIntersectionRecord().getNumberOfIntersections() > 0) {
final PrimitiveKey key = pickData.getIntersectionRecord().getIntersectionPrimitive(0);
- ((Mesh) picked).getMeshData().getPrimitiveVertices(key.getPrimitiveIndex(), key.getSection(),
+ ((Mesh) _lastDragSpatial).getMeshData().getPrimitiveVertices(key.getPrimitiveIndex(), key.getSection(),
new Vector3[] { _calcVec3A, _calcVec3B, _calcVec3C });
- picked.localToWorld(_calcVec3A, _calcVec3A);
- picked.localToWorld(_calcVec3B, _calcVec3B);
- picked.localToWorld(_calcVec3C, _calcVec3C);
+ _lastDragSpatial.localToWorld(_calcVec3A, _calcVec3A);
+ _lastDragSpatial.localToWorld(_calcVec3B, _calcVec3B);
+ _lastDragSpatial.localToWorld(_calcVec3C, _calcVec3C);
+ final Vector2 oldMouse = new Vector2(previous.getX(), previous.getY());
final Vector3 loc = getNewOffset(oldMouse, current, camera, manager);
final Transform transform = manager.getSpatialState().getTransform();
transform.setTranslation(loc.addLocal(transform.getTranslation()));
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MovePlanarWidget.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MovePlanarWidget.java
index 3e469be..c5800c3 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MovePlanarWidget.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MovePlanarWidget.java
@@ -14,7 +14,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import com.ardor3d.extension.interact.InteractManager;
import com.ardor3d.framework.Canvas;
-import com.ardor3d.input.ButtonState;
import com.ardor3d.input.MouseState;
import com.ardor3d.input.logical.TwoInputStates;
import com.ardor3d.math.MathUtils;
@@ -35,7 +34,9 @@ import com.ardor3d.scenegraph.Spatial;
import com.ardor3d.scenegraph.shape.Cylinder;
public class MovePlanarWidget extends AbstractInteractWidget {
- public static double MIN_SCALE = 0.000001;
+
+ public static double DEFAULT_SCALE = 1.0;
+ public static double MOUSEOVER_SCALE = 1.1;
protected MovePlane _plane = MovePlane.XZ;
@@ -89,14 +90,6 @@ public class MovePlanarWidget extends AbstractInteractWidget {
}
@Override
- public void targetChanged(final InteractManager manager) {
- if (_dragging) {
- endDrag(manager);
- }
- targetDataUpdated(manager);
- }
-
- @Override
public void targetDataUpdated(final InteractManager manager) {
final Spatial target = manager.getSpatialTarget();
if (target == null) {
@@ -116,6 +109,12 @@ public class MovePlanarWidget extends AbstractInteractWidget {
}
@Override
+ protected double calculateHandleScale(final InteractManager manager) {
+ return super.calculateHandleScale(manager)
+ * (_mouseOver ? MovePlanarWidget.MOUSEOVER_SCALE : MovePlanarWidget.DEFAULT_SCALE);
+ }
+
+ @Override
public void render(final Renderer renderer, final InteractManager manager) {
final Spatial spat = manager.getSpatialTarget();
if (spat == null) {
@@ -131,57 +130,27 @@ public class MovePlanarWidget extends AbstractInteractWidget {
@Override
public void processInput(final Canvas source, final TwoInputStates inputStates, final AtomicBoolean inputConsumed,
final InteractManager manager) {
- // Make sure we have something to modify
- if (manager.getSpatialTarget() == null) {
- return;
- }
- // Make sure we are dragging.
+ final Camera camera = source.getCanvasRenderer().getCamera();
final MouseState current = inputStates.getCurrent().getMouseState();
final MouseState previous = inputStates.getPrevious().getMouseState();
- if (current.getButtonState(_dragButton) != ButtonState.DOWN) {
- if (_dragging) {
- endDrag(manager);
- }
- return;
- }
- // if we're already dragging, make sure we only act on drags that started with a positive pick.
- else if (!current.getButtonsPressedSince(previous).contains(_dragButton) && !_dragging) {
- return;
- }
-
- final Camera camera = source.getCanvasRenderer().getCamera();
- final Vector2 oldMouse = new Vector2(previous.getX(), previous.getY());
- // Make sure we are dragging over the handle
- if (!_dragging) {
- findPick(oldMouse, camera);
- final Vector3 lastPick = getLastPick();
- if (lastPick == null) {
- return;
- } else {
- beginDrag(manager);
- }
- }
-
- // we've established that our mouse is being held down, and started over our arrow. So consume.
- inputConsumed.set(true);
+ // first process mouse over state
+ checkMouseOver(camera, current, manager);
- // check if we've moved at all
- if (current == previous || current.getDx() == 0 && current.getDy() == 0) {
+ // Now check drag status
+ if (!checkShouldDrag(camera, current, previous, inputConsumed, manager)) {
return;
}
// act on drag
- final Spatial picked = (Spatial) _results.getPickData(0).getTarget();
- if (picked != null) {
- final Vector3 loc = getNewOffset(oldMouse, current, camera, manager);
- final Transform transform = manager.getSpatialState().getTransform();
- transform.setTranslation(loc.addLocal(transform.getTranslation()));
-
- // apply our filters, if any, now that we've made updates.
- applyFilters(manager);
- }
+ final Vector2 oldMouse = new Vector2(previous.getX(), previous.getY());
+ final Vector3 loc = getNewOffset(oldMouse, current, camera, manager);
+ final Transform transform = manager.getSpatialState().getTransform();
+ transform.setTranslation(loc.addLocal(transform.getTranslation()));
+
+ // apply our filters, if any, now that we've made updates.
+ applyFilters(manager);
}
protected Vector3 getNewOffset(final Vector2 oldMouse, final MouseState current, final Camera camera,
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MoveWidget.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MoveWidget.java
index fd332a7..8f4a62b 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MoveWidget.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MoveWidget.java
@@ -14,7 +14,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import com.ardor3d.extension.interact.InteractManager;
import com.ardor3d.framework.Canvas;
-import com.ardor3d.input.ButtonState;
import com.ardor3d.input.MouseState;
import com.ardor3d.input.logical.TwoInputStates;
import com.ardor3d.math.ColorRGBA;
@@ -37,7 +36,9 @@ import com.ardor3d.scenegraph.Node;
import com.ardor3d.scenegraph.Spatial;
public class MoveWidget extends AbstractInteractWidget {
- public static double MIN_SCALE = 0.000001;
+
+ public static double DEFAULT_SCALE = 1.0;
+ public static double MOUSEOVER_SCALE = 1.1;
protected InteractArrow _lastArrow = null;
@@ -132,14 +133,6 @@ public class MoveWidget extends AbstractInteractWidget {
}
@Override
- public void targetChanged(final InteractManager manager) {
- if (_dragging) {
- endDrag(manager);
- }
- targetDataUpdated(manager);
- }
-
- @Override
public void targetDataUpdated(final InteractManager manager) {
final Spatial target = manager.getSpatialTarget();
if (target == null) {
@@ -159,6 +152,12 @@ public class MoveWidget extends AbstractInteractWidget {
}
@Override
+ protected double calculateHandleScale(final InteractManager manager) {
+ return super.calculateHandleScale(manager)
+ * (_mouseOver ? MoveWidget.MOUSEOVER_SCALE : MoveWidget.DEFAULT_SCALE);
+ }
+
+ @Override
public void render(final Renderer renderer, final InteractManager manager) {
final Spatial spat = manager.getSpatialTarget();
if (spat == null) {
@@ -174,52 +173,24 @@ public class MoveWidget extends AbstractInteractWidget {
@Override
public void processInput(final Canvas source, final TwoInputStates inputStates, final AtomicBoolean inputConsumed,
final InteractManager manager) {
- // Make sure we have something to modify
- if (manager.getSpatialTarget() == null) {
- return;
- }
- // Make sure we are dragging.
+ final Camera camera = source.getCanvasRenderer().getCamera();
final MouseState current = inputStates.getCurrent().getMouseState();
final MouseState previous = inputStates.getPrevious().getMouseState();
- if (current.getButtonState(_dragButton) != ButtonState.DOWN) {
- if (_dragging) {
- endDrag(manager);
- }
- return;
- }
- // if we're already dragging, make sure we only act on drags that started with a positive pick.
- else if (!current.getButtonsPressedSince(previous).contains(_dragButton) && !_dragging) {
- return;
- }
-
- final Camera camera = source.getCanvasRenderer().getCamera();
- final Vector2 oldMouse = new Vector2(previous.getX(), previous.getY());
- // Make sure we are dragging over the handle
- if (!_dragging) {
- findPick(oldMouse, camera);
- final Vector3 lastPick = getLastPick();
- if (lastPick == null) {
- return;
- } else {
- beginDrag(manager);
- }
- }
-
- // we've established that our mouse is being held down, and started over our arrow. So consume.
- inputConsumed.set(true);
+ // first process mouse over state
+ checkMouseOver(camera, current, manager);
- // check if we've moved at all
- if (current == previous || current.getDx() == 0 && current.getDy() == 0) {
+ // Now check drag status
+ if (!checkShouldDrag(camera, current, previous, inputConsumed, manager)) {
return;
}
// act on drag
- final Spatial picked = (Spatial) _results.getPickData(0).getTarget();
- if (picked != null && picked.getParent() instanceof InteractArrow) {
- final InteractArrow arrow = (InteractArrow) picked.getParent();
+ if (_lastDragSpatial != null && _lastDragSpatial.getParent() instanceof InteractArrow) {
+ final InteractArrow arrow = (InteractArrow) _lastDragSpatial.getParent();
_lastArrow = arrow;
+ final Vector2 oldMouse = new Vector2(previous.getX(), previous.getY());
final Vector3 loc = getNewOffset(arrow, oldMouse, current, camera, manager);
final Transform transform = manager.getSpatialState().getTransform();
transform.setTranslation(loc.addLocal(transform.getTranslation()));
@@ -237,8 +208,8 @@ public class MoveWidget extends AbstractInteractWidget {
_calcVec3B.set(_calcVec3A).addLocal(camera.getLeft());
_calcVec3C.set( //
arrow == _xArrow ? Vector3.UNIT_X : //
- arrow == _yArrow ? Vector3.UNIT_Y : //
- Vector3.UNIT_Z);
+ arrow == _yArrow ? Vector3.UNIT_Y : //
+ Vector3.UNIT_Z);
// rotate to arrow plane
_handle.getRotation().applyPost(_calcVec3C, _calcVec3C);
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/RotateWidget.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/RotateWidget.java
index 953b57c..0348887 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/RotateWidget.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/RotateWidget.java
@@ -15,7 +15,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import com.ardor3d.extension.interact.InteractManager;
import com.ardor3d.framework.Canvas;
import com.ardor3d.image.Texture2D;
-import com.ardor3d.input.ButtonState;
import com.ardor3d.input.MouseState;
import com.ardor3d.input.logical.TwoInputStates;
import com.ardor3d.math.ColorRGBA;
@@ -33,13 +32,14 @@ import com.ardor3d.renderer.Camera;
import com.ardor3d.renderer.Renderer;
import com.ardor3d.renderer.queue.RenderBucketType;
import com.ardor3d.renderer.state.BlendState;
+import com.ardor3d.renderer.state.RenderState.StateType;
import com.ardor3d.renderer.state.ZBufferState;
import com.ardor3d.renderer.state.ZBufferState.TestFunction;
import com.ardor3d.scenegraph.Node;
import com.ardor3d.scenegraph.Spatial;
+import com.ardor3d.scenegraph.visitor.Visitor;
public class RotateWidget extends AbstractInteractWidget {
- public static double MIN_SCALE = 0.000001;
protected Matrix3 _calcMat3 = new Matrix3();
protected Matrix3 _rotateStore = new Matrix3();
@@ -54,10 +54,6 @@ public class RotateWidget extends AbstractInteractWidget {
super(filterList);
_handle = new Node("rotationHandle");
- final BlendState blend = new BlendState();
- blend.setBlendEnabled(true);
- _handle.setRenderState(blend);
-
final ZBufferState zstate = new ZBufferState();
zstate.setFunction(TestFunction.LessThanOrEqualTo);
_handle.setRenderState(zstate);
@@ -84,6 +80,38 @@ public class RotateWidget extends AbstractInteractWidget {
}
}
+ @Override
+ public void mouseEntered(final InteractManager manager) {
+ super.mouseEntered(manager);
+ if (_lastMouseOverSpatial != null) {
+ cleanupBlendStates();
+ final BlendState bs = (BlendState) _lastMouseOverSpatial.getLocalRenderState(StateType.Blend);
+ if (bs != null) {
+ bs.setBlendEnabled(false);
+ }
+ _handle.updateGeometricState(0);
+ }
+ }
+
+ @Override
+ public void mouseDeparted(final InteractManager manager) {
+ super.mouseDeparted(manager);
+ cleanupBlendStates();
+ _handle.updateGeometricState(0);
+ }
+
+ protected void cleanupBlendStates() {
+ _handle.acceptVisitor(new Visitor() {
+ @Override
+ public void visit(final Spatial spatial) {
+ final BlendState bs = (BlendState) spatial.getLocalRenderState(StateType.Blend);
+ if (bs != null) {
+ bs.setBlendEnabled(true);
+ }
+ }
+ }, true);
+ }
+
public RotateWidget withXAxis() {
return withXAxis(new ColorRGBA(1, 0, 0, .65f));
}
@@ -102,6 +130,11 @@ public class RotateWidget extends AbstractInteractWidget {
_xRing.getMeshData().rotatePoints(rotate);
_xRing.getMeshData().rotateNormals(rotate);
_handle.attachChild(_xRing);
+
+ final BlendState blend = new BlendState();
+ blend.setBlendEnabled(true);
+ _xRing.setRenderState(blend);
+
return this;
}
@@ -123,6 +156,11 @@ public class RotateWidget extends AbstractInteractWidget {
_yRing.getMeshData().rotatePoints(rotate);
_yRing.getMeshData().rotateNormals(rotate);
_handle.attachChild(_yRing);
+
+ final BlendState blend = new BlendState();
+ blend.setBlendEnabled(true);
+ _yRing.setRenderState(blend);
+
return this;
}
@@ -141,20 +179,12 @@ public class RotateWidget extends AbstractInteractWidget {
_zRing = new InteractRing("zRotRing", 4, 32, scale, width);
_zRing.setDefaultColor(color);
_handle.attachChild(_zRing);
- return this;
- }
- @Override
- public void targetChanged(final InteractManager manager) {
- if (_dragging) {
- endDrag(manager);
- }
- final Spatial target = manager.getSpatialTarget();
- if (target != null) {
- _handle.setScale(Math.max(RotateWidget.MIN_SCALE, target.getWorldBound().getRadius()
- + target.getWorldTranslation().subtract(target.getWorldBound().getCenter(), _calcVec3A).length()));
- }
- targetDataUpdated(manager);
+ final BlendState blend = new BlendState();
+ blend.setBlendEnabled(true);
+ _zRing.setRenderState(blend);
+
+ return this;
}
protected void setRingRotations(final ReadOnlyMatrix3 rot) {
@@ -207,15 +237,14 @@ public class RotateWidget extends AbstractInteractWidget {
@Override
public void processInput(final Canvas source, final TwoInputStates inputStates, final AtomicBoolean inputConsumed,
final InteractManager manager) {
- // Make sure we have something to modify
- if (manager.getSpatialTarget() == null) {
- return;
- }
- // Make sure we are dragging.
+ final Camera camera = source.getCanvasRenderer().getCamera();
final MouseState current = inputStates.getCurrent().getMouseState();
final MouseState previous = inputStates.getPrevious().getMouseState();
+ // first process mouse over state
+ checkMouseOver(camera, current, manager);
+
if (current.getButtonsReleasedSince(previous).contains(_dragButton)) {
_rotateStore.setIdentity();
if (_interactMatrix != InteractMatrix.Local) {
@@ -223,44 +252,17 @@ public class RotateWidget extends AbstractInteractWidget {
}
}
- if (current.getButtonState(_dragButton) != ButtonState.DOWN) {
- if (_dragging) {
- endDrag(manager);
- }
- return;
- }
- // if we're already dragging, make sure we only act on drags that started with a positive pick.
- else if (!current.getButtonsPressedSince(previous).contains(_dragButton) && !_dragging) {
- return;
- }
-
- final Camera camera = source.getCanvasRenderer().getCamera();
- final Vector2 oldMouse = new Vector2(previous.getX(), previous.getY());
- // Make sure we are dragging over the handle
- if (!_dragging) {
- findPick(oldMouse, camera);
- final Vector3 lastPick = getLastPick();
- if (lastPick == null) {
- return;
- } else {
- beginDrag(manager);
- }
- }
-
- // we've established that our mouse is being held down, and started over our arrow. So consume.
- inputConsumed.set(true);
-
- // check if we've moved at all
- if (current == previous || current.getDx() == 0 && current.getDy() == 0) {
+ // Now check drag status
+ if (!checkShouldDrag(camera, current, previous, inputConsumed, manager)) {
return;
}
// act on drag
- final Spatial picked = (Spatial) _results.getPickData(0).getTarget();
- if (picked instanceof InteractRing) {
- final InteractRing ring = (InteractRing) picked;
- _lastRing = ring;
- final ReadOnlyQuaternion rot = getNewAxisRotation(ring, oldMouse, current, camera, manager);
+ if (_lastDragSpatial instanceof InteractRing) {
+ _lastRing = (InteractRing) _lastDragSpatial;
+
+ final Vector2 oldMouse = new Vector2(previous.getX(), previous.getY());
+ final ReadOnlyQuaternion rot = getNewAxisRotation(_lastRing, oldMouse, current, camera, manager);
final Transform transform = manager.getSpatialState().getTransform();
rot.toRotationMatrix(_calcMat3).multiply(transform.getMatrix(), _calcMat3);
transform.setRotation(_calcMat3);
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/SimpleScaleWidget.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/SimpleScaleWidget.java
index 1cff752..38e4445 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/SimpleScaleWidget.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/SimpleScaleWidget.java
@@ -14,7 +14,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import com.ardor3d.extension.interact.InteractManager;
import com.ardor3d.framework.Canvas;
-import com.ardor3d.input.ButtonState;
import com.ardor3d.input.MouseState;
import com.ardor3d.input.logical.TwoInputStates;
import com.ardor3d.math.ColorRGBA;
@@ -34,7 +33,9 @@ import com.ardor3d.scenegraph.Spatial;
import com.ardor3d.scenegraph.shape.Arrow;
public class SimpleScaleWidget extends AbstractInteractWidget {
- public static double MIN_SCALE = 0.000001;
+
+ public static double DEFAULT_SCALE = 1.0;
+ public static double MOUSEOVER_SCALE = 1.1;
protected ReadOnlyVector3 _arrowDirection;
@@ -75,14 +76,6 @@ public class SimpleScaleWidget extends AbstractInteractWidget {
}
@Override
- public void targetChanged(final InteractManager manager) {
- if (_dragging) {
- endDrag(manager);
- }
- targetDataUpdated(manager);
- }
-
- @Override
public void targetDataUpdated(final InteractManager manager) {
final Spatial target = manager.getSpatialTarget();
if (target != null) {
@@ -93,6 +86,12 @@ public class SimpleScaleWidget extends AbstractInteractWidget {
}
@Override
+ protected double calculateHandleScale(final InteractManager manager) {
+ return super.calculateHandleScale(manager)
+ * (_mouseOver ? SimpleScaleWidget.MOUSEOVER_SCALE : SimpleScaleWidget.DEFAULT_SCALE);
+ }
+
+ @Override
public void render(final Renderer renderer, final InteractManager manager) {
final Spatial spat = manager.getSpatialTarget();
if (spat == null) {
@@ -108,47 +107,21 @@ public class SimpleScaleWidget extends AbstractInteractWidget {
@Override
public void processInput(final Canvas source, final TwoInputStates inputStates, final AtomicBoolean inputConsumed,
final InteractManager manager) {
- // Make sure we have something to modify
- if (manager.getSpatialTarget() == null) {
- return;
- }
- // Make sure we are dragging.
+ final Camera camera = source.getCanvasRenderer().getCamera();
final MouseState current = inputStates.getCurrent().getMouseState();
final MouseState previous = inputStates.getPrevious().getMouseState();
- if (current.getButtonState(_dragButton) != ButtonState.DOWN) {
- if (_dragging) {
- endDrag(manager);
- }
- return;
- }
- // if we're already dragging, make sure we only act on drags that started with a positive pick.
- else if (!current.getButtonsPressedSince(previous).contains(_dragButton) && !_dragging) {
- return;
- }
- final Camera camera = source.getCanvasRenderer().getCamera();
- final Vector2 oldMouse = new Vector2(previous.getX(), previous.getY());
- // Make sure we are dragging over the arrow
- if (!_dragging) {
- findPick(oldMouse, camera);
- final Vector3 lastPick = getLastPick();
- if (lastPick == null) {
- return;
- } else {
- beginDrag(manager);
- }
- }
+ // first process mouse over state
+ checkMouseOver(camera, current, manager);
- // we've established that our mouse is being held down, and started over our arrow. So consume.
- inputConsumed.set(true);
-
- // check if we've moved at all
- if (current == previous || current.getDx() == 0 && current.getDy() == 0) {
+ // Now check drag status
+ if (!checkShouldDrag(camera, current, previous, inputConsumed, manager)) {
return;
}
// act on drag
+ final Vector2 oldMouse = new Vector2(previous.getX(), previous.getY());
final double scale = getNewScale(oldMouse, current, camera, manager);
// Set new scale on spatial state