aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-extras
diff options
context:
space:
mode:
authorJoshua Slack <[email protected]>2017-10-27 14:34:02 -0500
committerJoshua Slack <[email protected]>2017-10-27 14:34:02 -0500
commit08a7ce14a2cd408bc64f035e8bf076cfa159b003 (patch)
treeafadc7fac07b6d77513a3655e9caa4936af1a880 /ardor3d-extras
parentd1fcf4cdaca9d5fb922eee1e6dedc4b0c53014f8 (diff)
Fixed some redundant scaling code and pulled widget scale calculation out into a place easily extended by subclasses.
Diffstat (limited to 'ardor3d-extras')
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/AbstractInteractWidget.java19
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MoveMultiPlanarWidget.java11
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MovePlanarWidget.java12
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/MoveWidget.java12
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/RotateWidget.java8
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/interact/widget/SimpleScaleWidget.java10
6 files changed, 33 insertions, 39 deletions
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 87ffd1b..2292ad2 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
@@ -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>.
*/
@@ -12,6 +12,7 @@ package com.ardor3d.extension.interact.widget;
import java.util.concurrent.atomic.AtomicBoolean;
+import com.ardor3d.bounding.BoundingVolume;
import com.ardor3d.extension.interact.InteractManager;
import com.ardor3d.extension.interact.filter.UpdateFilter;
import com.ardor3d.framework.Canvas;
@@ -22,9 +23,11 @@ import com.ardor3d.intersection.PrimitivePickResults;
import com.ardor3d.math.Ray3;
import com.ardor3d.math.Vector2;
import com.ardor3d.math.Vector3;
+import com.ardor3d.math.type.ReadOnlyVector3;
import com.ardor3d.renderer.Camera;
import com.ardor3d.renderer.Renderer;
import com.ardor3d.scenegraph.Node;
+import com.ardor3d.scenegraph.Spatial;
import com.ardor3d.util.ReadOnlyTimer;
public abstract class AbstractInteractWidget {
@@ -57,7 +60,7 @@ public abstract class AbstractInteractWidget {
/**
* Use the given inputstates to determine if and how to activate this widget. If the widget uses the given input,
* inputConsumed should be set to "true" and applyFilters should be called by this method.
- *
+ *
* @param source
* the canvas that is our input source.
* @param inputStates
@@ -90,6 +93,18 @@ public abstract class AbstractInteractWidget {
_handle.updateGeometricState(timer.getTimePerFrame());
}
+ protected double calculateHandleScale(final InteractManager manager) {
+ final Spatial target = manager.getSpatialTarget();
+ 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 1.0;
+ }
+
public void render(final Renderer renderer, final InteractManager manager) { /**/}
public void targetChanged(final InteractManager manager) { /**/}
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 f47be1b..8830456 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
@@ -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>.
*/
@@ -98,11 +98,6 @@ public class MoveMultiPlanarWidget extends AbstractInteractWidget {
if (_dragging) {
endDrag(manager);
}
- final Spatial target = manager.getSpatialTarget();
- if (target != null) {
- _handle.setScale(Math.max(MoveMultiPlanarWidget.MIN_SCALE, target.getWorldBound().getRadius()
- + target.getWorldTranslation().subtract(target.getWorldBound().getCenter(), _calcVec3A).length()));
- }
targetDataUpdated(manager);
}
@@ -110,10 +105,8 @@ public class MoveMultiPlanarWidget extends AbstractInteractWidget {
public void targetDataUpdated(final InteractManager manager) {
final Spatial target = manager.getSpatialTarget();
if (target == null) {
- _handle.setScale(1.0);
_handle.setRotation(Matrix3.IDENTITY);
} else {
- // update scale of widget using bounding radius
target.updateGeometricState(0);
// update arrow rotations from target
@@ -123,6 +116,8 @@ public class MoveMultiPlanarWidget extends AbstractInteractWidget {
_handle.setRotation(Matrix3.IDENTITY);
}
}
+
+ _handle.setScale(calculateHandleScale(manager));
}
@Override
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 631a906..3e469be 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
@@ -93,11 +93,6 @@ public class MovePlanarWidget extends AbstractInteractWidget {
if (_dragging) {
endDrag(manager);
}
- final Spatial target = manager.getSpatialTarget();
- if (target != null) {
- _handle.setScale(Math.max(MovePlanarWidget.MIN_SCALE, target.getWorldBound().getRadius()
- + target.getWorldTranslation().subtract(target.getWorldBound().getCenter(), _calcVec3A).length()));
- }
targetDataUpdated(manager);
}
@@ -105,13 +100,8 @@ public class MovePlanarWidget extends AbstractInteractWidget {
public void targetDataUpdated(final InteractManager manager) {
final Spatial target = manager.getSpatialTarget();
if (target == null) {
- _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);
// update arrow rotations from target
@@ -121,6 +111,8 @@ public class MovePlanarWidget extends AbstractInteractWidget {
_handle.setRotation(Matrix3.IDENTITY);
}
}
+
+ _handle.setScale(calculateHandleScale(manager));
}
@Override
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 bb491b4..fd332a7 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
@@ -136,11 +136,6 @@ public class MoveWidget extends AbstractInteractWidget {
if (_dragging) {
endDrag(manager);
}
- final Spatial target = manager.getSpatialTarget();
- if (target != null) {
- _handle.setScale(Math.max(MoveWidget.MIN_SCALE, target.getWorldBound().getRadius()
- + target.getWorldTranslation().subtract(target.getWorldBound().getCenter(), _calcVec3A).length()));
- }
targetDataUpdated(manager);
}
@@ -148,13 +143,8 @@ public class MoveWidget extends AbstractInteractWidget {
public void targetDataUpdated(final InteractManager manager) {
final Spatial target = manager.getSpatialTarget();
if (target == null) {
- _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);
// update arrow rotations from target
@@ -164,6 +154,8 @@ public class MoveWidget extends AbstractInteractWidget {
_handle.setRotation(Matrix3.IDENTITY);
}
}
+
+ _handle.setScale(calculateHandleScale(manager));
}
@Override
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 a684ef7..953b57c 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
@@ -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>.
*/
@@ -68,7 +68,7 @@ public class RotateWidget extends AbstractInteractWidget {
/**
* Call this after creating the rings you want to use.
- *
+ *
* @param texture
* @return
*/
@@ -173,10 +173,8 @@ public class RotateWidget extends AbstractInteractWidget {
public void targetDataUpdated(final InteractManager manager) {
final Spatial target = manager.getSpatialTarget();
if (target == null) {
- _handle.setScale(1.0);
setRingRotations(Matrix3.IDENTITY);
} else {
- // update scale of widget using bounding radius
target.updateGeometricState(0);
// update ring rotations from target
@@ -189,6 +187,8 @@ public class RotateWidget extends AbstractInteractWidget {
}
}
}
+
+ _handle.setScale(calculateHandleScale(manager));
}
@Override
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 ffcc8bb..1cff752 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
@@ -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>.
*/
@@ -85,11 +85,11 @@ public class SimpleScaleWidget extends AbstractInteractWidget {
@Override
public void targetDataUpdated(final InteractManager manager) {
final Spatial target = manager.getSpatialTarget();
- if (target == null) {
- _handle.setScale(1.0);
- } else {
- _handle.setScale(Math.max(SimpleScaleWidget.MIN_SCALE, target.getWorldBound().getRadius()));
+ if (target != null) {
+ target.updateGeometricState(0);
}
+
+ _handle.setScale(calculateHandleScale(manager));
}
@Override