aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Slack <[email protected]>2017-09-19 21:42:41 -0500
committerJoshua Slack <[email protected]>2017-09-19 21:42:41 -0500
commit1aae3c9d22835dded3f6cc6ba0d2e9cc040a92aa (patch)
tree0e54f3b1cabedd0ccc2fe6f7d2c3a87a14c07fc5
parent0e81102a1660001482dbfeb8da6936081edbe78c (diff)
Added a way for update logic to be attached to, and run by, InteractManager
-rw-r--r--ardor3d-examples/src/main/java/com/ardor3d/example/ui/InteractUIExample.java8
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/interact/InteractManager.java71
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MovePlanarWidget.java5
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MoveWidget.java9
4 files changed, 89 insertions, 4 deletions
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/InteractUIExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/InteractUIExample.java
index e93cf93..2e5dc1d 100644
--- a/ardor3d-examples/src/main/java/com/ardor3d/example/ui/InteractUIExample.java
+++ b/ardor3d-examples/src/main/java/com/ardor3d/example/ui/InteractUIExample.java
@@ -18,6 +18,7 @@ import com.ardor3d.bounding.BoundingBox;
import com.ardor3d.example.ExampleBase;
import com.ardor3d.example.Purpose;
import com.ardor3d.extension.interact.InteractManager;
+import com.ardor3d.extension.interact.InteractManager.UpdateLogic;
import com.ardor3d.extension.interact.data.SpatialState;
import com.ardor3d.extension.interact.filter.PlaneBoundaryFilter;
import com.ardor3d.extension.interact.widget.AbstractInteractWidget;
@@ -133,6 +134,13 @@ public class InteractUIExample extends ExampleBase {
// create a few way-markers to start things off
initPath();
+ manager.addUpdateLogic(new UpdateLogic() {
+
+ @Override
+ public void update(final double time, final InteractManager manager) {
+ manager.fireTargetDataUpdated();
+ }
+ });
}
private void addFloor() {
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 447a226..7974a4b 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
@@ -10,6 +10,7 @@
package com.ardor3d.extension.interact;
+import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -68,6 +69,9 @@ public class InteractManager {
*/
protected List<UpdateFilter> _filters = Lists.newArrayList();
+ /** ArrayList of update logic for this manager. */
+ protected List<UpdateLogic> _updateLogic;
+
public InteractManager() {
_state = new SpatialState();
setupLogicalLayer();
@@ -79,6 +83,7 @@ public class InteractManager {
}
public void update(final ReadOnlyTimer timer) {
+ runUpdateLogic(timer.getTimePerFrame());
for (final AbstractInteractWidget widget : _widgets) {
if (!widget.isActiveUpdateOnly() || widget == _activeWidget) {
widget.update(timer, this);
@@ -251,4 +256,70 @@ public class InteractManager {
return _state;
}
+ public interface UpdateLogic {
+ public void update(double time, InteractManager manager);
+ }
+
+ public void addUpdateLogic(final UpdateLogic logic) {
+ if (_updateLogic == null) {
+ _updateLogic = new ArrayList<UpdateLogic>(1);
+ }
+ _updateLogic.add(logic);
+ }
+
+ public boolean removeUpdateLogic(final UpdateLogic logic) {
+ if (_updateLogic == null) {
+ return false;
+ }
+ return _updateLogic.remove(logic);
+ }
+
+ public UpdateLogic removeUpdateLogic(final int index) {
+ if (_updateLogic == null) {
+ return null;
+ }
+ return _updateLogic.remove(index);
+ }
+
+ public void clearUpdateLogic() {
+ if (_updateLogic != null) {
+ _updateLogic.clear();
+ }
+ }
+
+ public UpdateLogic getUpdateLogic(final int i) {
+ if (_updateLogic == null) {
+ _updateLogic = new ArrayList<UpdateLogic>(1);
+ }
+ return _updateLogic.get(i);
+ }
+
+ public List<UpdateLogic> getUpdateLogic() {
+ if (_updateLogic == null) {
+ _updateLogic = new ArrayList<UpdateLogic>(1);
+ }
+ return _updateLogic;
+ }
+
+ public int getUpdateLogicCount() {
+ if (_updateLogic == null) {
+ return 0;
+ }
+ return _updateLogic.size();
+ }
+
+ public void runUpdateLogic(final double time) {
+ if (_updateLogic != null) {
+ for (int i = 0, gSize = _updateLogic.size(); i < gSize; i++) {
+ try {
+ final UpdateLogic logic = _updateLogic.get(i);
+ if (logic != null) {
+ logic.update(time, this);
+ }
+ } catch (final IndexOutOfBoundsException e) {
+ break;
+ }
+ }
+ }
+ }
}
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 9787ea7..631a906 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
@@ -3,7 +3,7 @@
*
* This file is part of Ardor3D.
*
- * Ardor3D is free software: you can redistribute it and/or modify it
+ * 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>.
*/
@@ -108,6 +108,9 @@ public class MovePlanarWidget extends AbstractInteractWidget {
_handle.setScale(1.0);
_handle.setRotation(Matrix3.IDENTITY);
} else {
+ _handle.setScale(Math.max(MoveWidget.MIN_SCALE, target.getWorldBound().getRadius()
+ + target.getWorldTranslation().subtract(target.getWorldBound().getCenter(), _calcVec3A).length()));
+
// update scale of widget using bounding radius
target.updateGeometricState(0);
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 e03e1bd..bb491b4 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
@@ -3,7 +3,7 @@
*
* This file is part of Ardor3D.
*
- * Ardor3D is free software: you can redistribute it and/or modify it
+ * 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>.
*/
@@ -151,6 +151,9 @@ public class MoveWidget extends AbstractInteractWidget {
_handle.setScale(1.0);
_handle.setRotation(Matrix3.IDENTITY);
} else {
+ _handle.setScale(Math.max(MoveWidget.MIN_SCALE, target.getWorldBound().getRadius()
+ + target.getWorldTranslation().subtract(target.getWorldBound().getCenter(), _calcVec3A).length()));
+
// update scale of widget using bounding radius
target.updateGeometricState(0);
@@ -242,8 +245,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);