aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-core
diff options
context:
space:
mode:
authorrenanse <[email protected]>2012-12-19 17:30:45 -0600
committerrenanse <[email protected]>2012-12-19 17:30:45 -0600
commit4b6c4a6bf432616460bbeb42f79b9e1d308055dc (patch)
tree0abe13157d06fa0bfc5631a57ec75b6369a77b41 /ardor3d-core
parent580b097cb031ee97180849736f66b1c60fe515e1 (diff)
parent76c6a1ff4ce5d8bf5394e7851744a598982a47a1 (diff)
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'ardor3d-core')
-rw-r--r--ardor3d-core/src/main/java/com/ardor3d/bounding/BoundingBox.java27
-rw-r--r--ardor3d-core/src/main/java/com/ardor3d/bounding/BoundingSphere.java48
-rw-r--r--ardor3d-core/src/main/java/com/ardor3d/bounding/BoundingVolume.java9
-rw-r--r--ardor3d-core/src/main/java/com/ardor3d/bounding/OrientedBoundingBox.java26
-rw-r--r--ardor3d-core/src/main/java/com/ardor3d/renderer/Camera.java2
5 files changed, 100 insertions, 12 deletions
diff --git a/ardor3d-core/src/main/java/com/ardor3d/bounding/BoundingBox.java b/ardor3d-core/src/main/java/com/ardor3d/bounding/BoundingBox.java
index d488d81..c7de5dc 100644
--- a/ardor3d-core/src/main/java/com/ardor3d/bounding/BoundingBox.java
+++ b/ardor3d-core/src/main/java/com/ardor3d/bounding/BoundingBox.java
@@ -426,6 +426,33 @@ public class BoundingBox extends BoundingVolume {
}
}
+ @Override
+ public BoundingVolume asType(final Type newType) {
+ if (newType == null) {
+ return null;
+ }
+
+ switch (newType) {
+ case AABB: {
+ return this.clone(null);
+ }
+
+ case Sphere: {
+ final BoundingSphere sphere = new BoundingSphere(0, _center);
+ return sphere.merge(this);
+ }
+
+ case OBB: {
+ final OrientedBoundingBox obb = new OrientedBoundingBox();
+ obb.setCenter(_center);
+ return obb.merge(this);
+ }
+
+ default:
+ return null;
+ }
+ }
+
/**
* Merges this AABB with the given OBB.
*
diff --git a/ardor3d-core/src/main/java/com/ardor3d/bounding/BoundingSphere.java b/ardor3d-core/src/main/java/com/ardor3d/bounding/BoundingSphere.java
index 9bf81b8..675a53c 100644
--- a/ardor3d-core/src/main/java/com/ardor3d/bounding/BoundingSphere.java
+++ b/ardor3d-core/src/main/java/com/ardor3d/bounding/BoundingSphere.java
@@ -20,10 +20,10 @@ import com.ardor3d.math.MathUtils;
import com.ardor3d.math.Plane;
import com.ardor3d.math.Vector3;
import com.ardor3d.math.type.ReadOnlyPlane;
+import com.ardor3d.math.type.ReadOnlyPlane.Side;
import com.ardor3d.math.type.ReadOnlyRay3;
import com.ardor3d.math.type.ReadOnlyTransform;
import com.ardor3d.math.type.ReadOnlyVector3;
-import com.ardor3d.math.type.ReadOnlyPlane.Side;
import com.ardor3d.scenegraph.MeshData;
import com.ardor3d.util.export.InputCapsule;
import com.ardor3d.util.export.OutputCapsule;
@@ -103,6 +103,7 @@ public class BoundingSphere extends BoundingVolume {
*
* @return the radius of the bounding sphere.
*/
+ @Override
public double getRadius() {
return _radius;
}
@@ -269,9 +270,9 @@ public class BoundingSphere extends BoundingVolume {
_center.set(0, 0, 0);
setRadius(0);
} else {
- final Vector3 o = a.cross(b, null).multiplyLocal(c.lengthSquared()).addLocal(
- c.cross(a, null).multiplyLocal(b.lengthSquared())).addLocal(
- b.cross(c, null).multiplyLocal(a.lengthSquared())).divideLocal(Denominator);
+ final Vector3 o = a.cross(b, null).multiplyLocal(c.lengthSquared())
+ .addLocal(c.cross(a, null).multiplyLocal(b.lengthSquared()))
+ .addLocal(b.cross(c, null).multiplyLocal(a.lengthSquared())).divideLocal(Denominator);
setRadius(o.length() * radiusEpsilon);
O.add(o, _center);
@@ -301,8 +302,8 @@ public class BoundingSphere extends BoundingVolume {
setRadius(0);
} else {
- final Vector3 o = acrossB.cross(a, null).multiplyLocal(b.lengthSquared()).addLocal(
- b.cross(acrossB, null).multiplyLocal(a.lengthSquared())).divideLocal(Denominator);
+ final Vector3 o = acrossB.cross(a, null).multiplyLocal(b.lengthSquared())
+ .addLocal(b.cross(acrossB, null).multiplyLocal(a.lengthSquared())).divideLocal(Denominator);
setRadius(o.length() * radiusEpsilon);
O.add(o, _center);
}
@@ -562,6 +563,33 @@ public class BoundingSphere extends BoundingVolume {
return store;
}
+ @Override
+ public BoundingVolume asType(final Type newType) {
+ if (newType == null) {
+ return null;
+ }
+
+ switch (newType) {
+ case AABB: {
+ final BoundingBox box = new BoundingBox(_center, 0, 0, 0);
+ return box.merge(this);
+ }
+
+ case Sphere: {
+ return this.clone(null);
+ }
+
+ case OBB: {
+ final OrientedBoundingBox obb = new OrientedBoundingBox();
+ obb.setCenter(_center);
+ return obb.merge(this);
+ }
+
+ default:
+ return null;
+ }
+ }
+
/**
* <code>clone</code> creates a new BoundingSphere object containing the same data as this one.
*
@@ -662,8 +690,8 @@ public class BoundingSphere extends BoundingVolume {
discr = (a1 * a1) - a;
root = Math.sqrt(discr);
final double[] distances = new double[] { root - a1 };
- final Vector3[] points = new Vector3[] { ray.getDirection().multiply(distances[0], new Vector3()).addLocal(
- ray.getOrigin()) };
+ final Vector3[] points = new Vector3[] { ray.getDirection().multiply(distances[0], new Vector3())
+ .addLocal(ray.getOrigin()) };
return new IntersectionRecord(distances, points);
}
@@ -687,8 +715,8 @@ public class BoundingSphere extends BoundingVolume {
}
final double[] distances = new double[] { -a1 };
- final Vector3[] points = new Vector3[] { ray.getDirection().multiply(distances[0], new Vector3()).addLocal(
- ray.getOrigin()) };
+ final Vector3[] points = new Vector3[] { ray.getDirection().multiply(distances[0], new Vector3())
+ .addLocal(ray.getOrigin()) };
return new IntersectionRecord(distances, points);
}
diff --git a/ardor3d-core/src/main/java/com/ardor3d/bounding/BoundingVolume.java b/ardor3d-core/src/main/java/com/ardor3d/bounding/BoundingVolume.java
index 5c0ba3d..19a9822 100644
--- a/ardor3d-core/src/main/java/com/ardor3d/bounding/BoundingVolume.java
+++ b/ardor3d-core/src/main/java/com/ardor3d/bounding/BoundingVolume.java
@@ -241,6 +241,15 @@ public abstract class BoundingVolume implements Serializable, Savable {
*/
public abstract boolean contains(ReadOnlyVector3 point);
+ /**
+ * Convert this bounding volume to another, given bounding type.
+ *
+ * @param newType
+ * the type of bounding volume to convert to.
+ * @return a new bounding volume of the given type, containing this bounding volume.
+ */
+ public abstract BoundingVolume asType(Type newType);
+
public void write(final OutputCapsule capsule) throws IOException {
capsule.write(_center, "center", new Vector3(Vector3.ZERO));
}
diff --git a/ardor3d-core/src/main/java/com/ardor3d/bounding/OrientedBoundingBox.java b/ardor3d-core/src/main/java/com/ardor3d/bounding/OrientedBoundingBox.java
index e3e77b0..20dd515 100644
--- a/ardor3d-core/src/main/java/com/ardor3d/bounding/OrientedBoundingBox.java
+++ b/ardor3d-core/src/main/java/com/ardor3d/bounding/OrientedBoundingBox.java
@@ -191,6 +191,32 @@ public class OrientedBoundingBox extends BoundingVolume {
}
}
+ @Override
+ public BoundingVolume asType(final Type newType) {
+ if (newType == null) {
+ return null;
+ }
+
+ switch (newType) {
+ case AABB: {
+ final BoundingBox box = new BoundingBox(_center, 0, 0, 0);
+ return box.merge(this);
+ }
+
+ case Sphere: {
+ final BoundingSphere sphere = new BoundingSphere(0, _center);
+ return sphere.merge(this);
+ }
+
+ case OBB: {
+ return this.clone(null);
+ }
+
+ default:
+ return null;
+ }
+ }
+
private BoundingVolume mergeSphere(final BoundingSphere volume) {
// check for infinite bounds to prevent NaN values
if (Vector3.isInfinite(getExtent()) || Double.isInfinite(volume.getRadius())) {
diff --git a/ardor3d-core/src/main/java/com/ardor3d/renderer/Camera.java b/ardor3d-core/src/main/java/com/ardor3d/renderer/Camera.java
index f281735..3b72a92 100644
--- a/ardor3d-core/src/main/java/com/ardor3d/renderer/Camera.java
+++ b/ardor3d-core/src/main/java/com/ardor3d/renderer/Camera.java
@@ -1386,8 +1386,6 @@ public class Camera implements Savable, Externalizable {
*/
private void checkModelViewProjection() {
if (_updateMVPMatrix) {
- checkModelView();
- checkProjection();
_modelViewProjection.set(getModelViewMatrix()).multiplyLocal(getProjectionMatrix());
_updateMVPMatrix = false;
}