diff options
14 files changed, 156 insertions, 44 deletions
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/interact/InteractExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/interact/InteractExample.java index b9fcb60..0fcbf1e 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/interact/InteractExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/interact/InteractExample.java @@ -18,6 +18,7 @@ import com.ardor3d.extension.interact.InteractManager; import com.ardor3d.extension.interact.filter.AllowScaleFilter; import com.ardor3d.extension.interact.filter.MinMaxScaleFilter; import com.ardor3d.extension.interact.filter.PlaneBoundaryFilter; +import com.ardor3d.extension.interact.widget.BasicFilterList; import com.ardor3d.extension.interact.widget.InteractMatrix; import com.ardor3d.extension.interact.widget.MoveWidget; import com.ardor3d.extension.interact.widget.RotateWidget; @@ -160,16 +161,18 @@ public class InteractExample extends ExampleBase { manager = new InteractManager(); manager.setupInput(_canvas, _physicalLayer, _logicalLayer); + final BasicFilterList filterList = new BasicFilterList(); + // add some widgets. - rotateWidget = new RotateWidget().withXAxis().withYAxis().withZAxis(); + rotateWidget = new RotateWidget(filterList).withXAxis().withYAxis().withZAxis(); rotateWidget.setTexture((Texture2D) TextureManager.load("images/tick.png", Texture.MinificationFilter.Trilinear, true)); manager.addWidget(rotateWidget); - scaleWidget = new SimpleScaleWidget().withArrow(Vector3.UNIT_Y); + scaleWidget = new SimpleScaleWidget(filterList).withArrow(Vector3.UNIT_Y); manager.addWidget(scaleWidget); - moveWidget = new MoveWidget().withXAxis().withYAxis().withZAxis(); + moveWidget = new MoveWidget(filterList).withXAxis().withYAxis().withZAxis(); manager.addWidget(moveWidget); // set the default as current diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/data/SpatialState.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/data/SpatialState.java index 4ba58ea..b68bf30 100644 --- a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/data/SpatialState.java +++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/data/SpatialState.java @@ -17,6 +17,13 @@ public class SpatialState { protected Transform _transform = new Transform(); + public SpatialState() {} + + /** copy constructor */ + public SpatialState(final SpatialState toCopy) { + _transform.set(toCopy._transform); + } + public Transform getTransform() { return _transform; } diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/filter/AllowScaleFilter.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/filter/AllowScaleFilter.java index d4707ac..a1eae88 100644 --- a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/filter/AllowScaleFilter.java +++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/filter/AllowScaleFilter.java @@ -37,8 +37,8 @@ public class AllowScaleFilter implements UpdateFilter { } @Override - public void beginDrag(final InteractManager manager) {} + public void beginDrag(final InteractManager manager) { /**/} @Override - public void endDrag(final InteractManager manager) {} + public void endDrag(final InteractManager manager) { /**/} } diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/filter/MinMaxScaleFilter.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/filter/MinMaxScaleFilter.java index f331742..e823403 100644 --- a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/filter/MinMaxScaleFilter.java +++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/filter/MinMaxScaleFilter.java @@ -42,8 +42,8 @@ public class MinMaxScaleFilter implements UpdateFilter { } @Override - public void beginDrag(final InteractManager manager) {} + public void beginDrag(final InteractManager manager) { /**/} @Override - public void endDrag(final InteractManager manager) {} + public void endDrag(final InteractManager manager) { /**/} } diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/filter/PlaneBoundaryFilter.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/filter/PlaneBoundaryFilter.java index cbff414..7be40f4 100644 --- a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/filter/PlaneBoundaryFilter.java +++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/filter/PlaneBoundaryFilter.java @@ -43,8 +43,8 @@ public class PlaneBoundaryFilter implements UpdateFilter { } @Override - public void beginDrag(final InteractManager manager) {} + public void beginDrag(final InteractManager manager) { /**/} @Override - public void endDrag(final InteractManager manager) {} + public void endDrag(final InteractManager manager) { /**/} } 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 af00b28..87ffd1b 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 @@ -10,7 +10,6 @@ package com.ardor3d.extension.interact.widget; -import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import com.ardor3d.extension.interact.InteractManager; @@ -27,7 +26,6 @@ import com.ardor3d.renderer.Camera; import com.ardor3d.renderer.Renderer; import com.ardor3d.scenegraph.Node; import com.ardor3d.util.ReadOnlyTimer; -import com.google.common.collect.Lists; public abstract class AbstractInteractWidget { @@ -48,13 +46,12 @@ public abstract class AbstractInteractWidget { protected InteractMatrix _interactMatrix = InteractMatrix.World; - /** - * List of filters to modify state after applying input. - */ - protected List<UpdateFilter> _filters = Lists.newArrayList(); + /** List of filters to modify state after applying input. */ + protected IFilterList _filters; - public AbstractInteractWidget() { + public AbstractInteractWidget(final IFilterList filterList) { _results.setCheckDistance(true); + _filters = filterList; } /** @@ -73,38 +70,31 @@ public abstract class AbstractInteractWidget { * our interact manager. */ public void processInput(final Canvas source, final TwoInputStates inputStates, final AtomicBoolean inputConsumed, - final InteractManager manager) {} + final InteractManager manager) { /**/} protected void applyFilters(final InteractManager manager) { - // apply any filters to our state - for (final UpdateFilter filter : _filters) { - filter.applyFilter(manager); - } + _filters.applyFilters(manager); } public void beginDrag(final InteractManager manager) { _dragging = true; - for (final UpdateFilter filter : _filters) { - filter.beginDrag(manager); - } + _filters.beginDrag(manager); } public void endDrag(final InteractManager manager) { _dragging = false; - for (final UpdateFilter filter : _filters) { - filter.endDrag(manager); - } + _filters.endDrag(manager); } public void update(final ReadOnlyTimer timer, final InteractManager manager) { _handle.updateGeometricState(timer.getTimePerFrame()); } - public void render(final Renderer renderer, final InteractManager manager) {} + public void render(final Renderer renderer, final InteractManager manager) { /**/} - public void targetChanged(final InteractManager manager) {} + public void targetChanged(final InteractManager manager) { /**/} - public void targetDataUpdated(final InteractManager manager) {} + public void targetDataUpdated(final InteractManager manager) { /**/} public void receivedControl(final InteractManager manager) { if (_dragging) { @@ -112,7 +102,7 @@ public abstract class AbstractInteractWidget { } } - public void lostControl(final InteractManager manager) {} + public void lostControl(final InteractManager manager) { /**/} public boolean isActiveInputOnly() { return _activeInputOnly; diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/BasicFilterList.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/BasicFilterList.java new file mode 100644 index 0000000..3b13b9d --- /dev/null +++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/BasicFilterList.java @@ -0,0 +1,66 @@ +/** + * Copyright (c) 2008-2012 Ardor Labs, Inc. + * + * This file is part of Ardor3D. + * + * Ardor3D is free software: you can redistribute it and/or modify it + * under the terms of its license which may be found in the accompanying + * LICENSE file or at <http://www.ardor3d.com/LICENSE>. + */ + +package com.ardor3d.extension.interact.widget; + +import java.util.Iterator; +import java.util.List; + +import com.ardor3d.extension.interact.InteractManager; +import com.ardor3d.extension.interact.filter.UpdateFilter; +import com.google.common.collect.Lists; + +public class BasicFilterList implements IFilterList { + final List<UpdateFilter> _filters = Lists.newArrayList(); + + public Iterator<UpdateFilter> iterator() { + return _filters.iterator(); + } + + public void applyFilters(final InteractManager manager) { + // apply any filters to our state + for (final UpdateFilter filter : _filters) { + filter.applyFilter(manager); + } + } + + public void beginDrag(final InteractManager manager) { + for (final UpdateFilter filter : _filters) { + filter.beginDrag(manager); + } + } + + public void endDrag(final InteractManager manager) { + for (final UpdateFilter filter : _filters) { + filter.endDrag(manager); + } + } + + public int size() { + return _filters.size(); + } + + public UpdateFilter get(final int index) { + return _filters.get(index); + } + + public boolean add(final UpdateFilter filter) { + return _filters.add(filter); + } + + public boolean remove(final UpdateFilter filter) { + return _filters.remove(filter); + } + + public void clear() { + _filters.clear(); + } + +} diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/CompoundInteractWidget.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/CompoundInteractWidget.java index ea41735..62a9684 100644 --- a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/CompoundInteractWidget.java +++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/CompoundInteractWidget.java @@ -31,6 +31,7 @@ import com.ardor3d.util.ReadOnlyTimer; import com.google.common.collect.Maps; public class CompoundInteractWidget extends AbstractInteractWidget { + private static final String MOVE_KEY = "Move"; private static final String ROTATE_KEY = "Rotate"; private static final String MOVE_PLANAR_KEY = "MovePlanar"; @@ -45,6 +46,7 @@ public class CompoundInteractWidget extends AbstractInteractWidget { protected InteractMatrix _interactMatrix; public CompoundInteractWidget() { + super(new BasicFilterList()); _handle = new Node("handleRoot"); } @@ -177,7 +179,7 @@ public class CompoundInteractWidget extends AbstractInteractWidget { widget.getHandle().removeFromParent(); } - widget = new MoveMultiPlanarWidget(); + widget = new MoveMultiPlanarWidget(_filters); _widgets.put(CompoundInteractWidget.MOVE_MULTIPLANAR_KEY, widget); _handle.attachChild(widget.getHandle()); @@ -191,7 +193,7 @@ public class CompoundInteractWidget extends AbstractInteractWidget { widget.getHandle().removeFromParent(); } - widget = new MoveMultiPlanarWidget(extent); + widget = new MoveMultiPlanarWidget(_filters, extent); _widgets.put(CompoundInteractWidget.MOVE_MULTIPLANAR_KEY, widget); _handle.attachChild(widget.getHandle()); @@ -204,7 +206,7 @@ public class CompoundInteractWidget extends AbstractInteractWidget { widget.getHandle().removeFromParent(); } - widget = new MovePlanarWidget().withPlane(plane).withDefaultHandle(.5, .25, color); + widget = new MovePlanarWidget(_filters).withPlane(plane).withDefaultHandle(.5, .25, color); _widgets.put(CompoundInteractWidget.MOVE_PLANAR_KEY, widget); _handle.attachChild(widget.getHandle()); @@ -218,7 +220,7 @@ public class CompoundInteractWidget extends AbstractInteractWidget { widget.getHandle().removeFromParent(); } - widget = new MovePlanarWidget().withPlane(plane).withDefaultHandle(radius, height, color); + widget = new MovePlanarWidget(_filters).withPlane(plane).withDefaultHandle(radius, height, color); _widgets.put(CompoundInteractWidget.MOVE_PLANAR_KEY, widget); _handle.attachChild(widget.getHandle()); @@ -228,7 +230,7 @@ public class CompoundInteractWidget extends AbstractInteractWidget { private MoveWidget verifyMoveWidget() { MoveWidget moveWidget = (MoveWidget) _widgets.get(CompoundInteractWidget.MOVE_KEY); if (moveWidget == null) { - moveWidget = new MoveWidget(); + moveWidget = new MoveWidget(_filters); _widgets.put(CompoundInteractWidget.MOVE_KEY, moveWidget); _handle.attachChild(moveWidget.getHandle()); } @@ -238,7 +240,7 @@ public class CompoundInteractWidget extends AbstractInteractWidget { private RotateWidget verifyRotateWidget() { RotateWidget rotateWidget = (RotateWidget) _widgets.get(CompoundInteractWidget.ROTATE_KEY); if (rotateWidget == null) { - rotateWidget = new RotateWidget(); + rotateWidget = new RotateWidget(_filters); _widgets.put(CompoundInteractWidget.ROTATE_KEY, rotateWidget); _handle.attachChild(rotateWidget.getHandle()); } diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/IFilterList.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/IFilterList.java new file mode 100644 index 0000000..4f1b0f9 --- /dev/null +++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/IFilterList.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2008-2012 Ardor Labs, Inc. + * + * This file is part of Ardor3D. + * + * Ardor3D is free software: you can redistribute it and/or modify it + * under the terms of its license which may be found in the accompanying + * LICENSE file or at <http://www.ardor3d.com/LICENSE>. + */ + +package com.ardor3d.extension.interact.widget; + +import com.ardor3d.extension.interact.InteractManager; +import com.ardor3d.extension.interact.filter.UpdateFilter; + +/** + * Provides a clean way to capture all of beginDrag, endDrag, and applyFilters. This scheme allows a compound widget to + * implement IFilerList and pass itself to leaf widgets, who can then forward calls to the parent list. + * + */ +public interface IFilterList extends Iterable<UpdateFilter> { + + public void applyFilters(final InteractManager manager); + + public void beginDrag(final InteractManager manager); + + public void endDrag(final InteractManager manager); + + public int size(); + + public UpdateFilter get(int index); + + public boolean add(final UpdateFilter filter); + + public boolean remove(final UpdateFilter filter); + + public void 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 019c3ed..f47be1b 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 @@ -45,11 +45,12 @@ import com.ardor3d.util.geom.BufferUtils; public class MoveMultiPlanarWidget extends AbstractInteractWidget { public static double MIN_SCALE = 0.000001; - public MoveMultiPlanarWidget() { - this(0.5); + public MoveMultiPlanarWidget(final IFilterList filterList) { + this(filterList, 0.5); } - public MoveMultiPlanarWidget(final double extent) { + public MoveMultiPlanarWidget(final IFilterList filterList, final double extent) { + super(filterList); _handle = new Node("moveHandle"); final BlendState blend = new BlendState(); 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 4b551bc..9787ea7 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 @@ -43,7 +43,8 @@ public class MovePlanarWidget extends AbstractInteractWidget { XY, XZ, YZ } - public MovePlanarWidget() { + public MovePlanarWidget(final IFilterList filterList) { + super(filterList); _handle = new Node("moveHandle"); final BlendState blend = new BlendState(); 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 5a6cda9..e03e1bd 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 @@ -51,7 +51,8 @@ public class MoveWidget extends AbstractInteractWidget { protected InteractMatrix _interactMatrix = InteractMatrix.World; - public MoveWidget() { + public MoveWidget(final IFilterList filterList) { + super(filterList); _handle = new Node("moveHandle"); final BlendState blend = new BlendState(); 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 9040208..a684ef7 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 @@ -50,7 +50,8 @@ public class RotateWidget extends AbstractInteractWidget { protected InteractRing _yRing = null; protected InteractRing _zRing = null; - public RotateWidget() { + public RotateWidget(final IFilterList filterList) { + super(filterList); _handle = new Node("rotationHandle"); final BlendState blend = new BlendState(); 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 617c603..ffcc8bb 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 @@ -38,7 +38,9 @@ public class SimpleScaleWidget extends AbstractInteractWidget { protected ReadOnlyVector3 _arrowDirection; - public SimpleScaleWidget() {} + public SimpleScaleWidget(final IFilterList filterList) { + super(filterList); + } public SimpleScaleWidget withArrow(final ReadOnlyVector3 arrowDirection) { return withArrow(arrowDirection, new ColorRGBA(1.0f, 0.0f, 0.0f, 0.4f), 0, 0); |