From 1aae3c9d22835dded3f6cc6ba0d2e9cc040a92aa Mon Sep 17 00:00:00 2001 From: Joshua Slack Date: Tue, 19 Sep 2017 21:42:41 -0500 Subject: Added a way for update logic to be attached to, and run by, InteractManager --- .../extension/interact/InteractManager.java | 71 ++++++++++++++++++++++ .../interact/widget/MovePlanarWidget.java | 5 +- .../extension/interact/widget/MoveWidget.java | 9 ++- 3 files changed, 81 insertions(+), 4 deletions(-) (limited to 'ardor3d-extras') 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 _filters = Lists.newArrayList(); + /** ArrayList of update logic for this manager. */ + protected List _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(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(1); + } + return _updateLogic.get(i); + } + + public List getUpdateLogic() { + if (_updateLogic == null) { + _updateLogic = new ArrayList(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 . */ @@ -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 . */ @@ -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); -- cgit v1.2.3