• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Main repository of MikuMikuStudio


Commit MetaInfo

Revision311625528413f17188511c08118346c421de6a29 (tree)
Time2003-09-11 05:32:59
Authormojomonkey <mojomonkey@75d0...>
Commitermojomonkey

Log Message

Testing bounding volumes, all now pass checks.

git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@88 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

Change Summary

Incremental Difference

--- a/src/jme/entity/Entity.java
+++ b/src/jme/entity/Entity.java
@@ -65,22 +65,10 @@ import org.lwjgl.opengl.Window;
6565 * <code>Entity</code> to represent something abstract.
6666 *
6767 * @author Mark Powell
68- * @version $Id: Entity.java,v 1.8 2003-09-08 20:29:28 mojomonkey Exp $
68+ * @version $Id: Entity.java,v 1.9 2003-09-10 20:32:59 mojomonkey Exp $
6969 */
7070 public class Entity implements EntityInterface {
71- /**
72- * Defines using simple point tests for visibility calculations.
73- */
74- public static final int VISIBILITY_POINT = 0;
75- /**
76- * Defines using sphere tests for visibility calculations.
77- */
78- public static final int VISIBILITY_SPHERE = 1;
79- /**
80- * Defines using cube tests for visibility calculations.
81- */
82- public static final int VISIBILITY_CUBE = 2;
83-
71+
8472 //The id of the entity
8573 private int id = 0;
8674
@@ -105,8 +93,7 @@ public class Entity implements EntityInterface {
10593 //visibility
10694 private boolean hasMoved;
10795 private boolean isVisible = true;
108- private int visibilityType;
109-
96+
11097 //physics
11198 private PhysicsModule physics;
11299
@@ -202,7 +189,8 @@ public class Entity implements EntityInterface {
202189 */
203190 public boolean hasCollision(Entity ent) {
204191 if(null != boundingVolume) {
205- return boundingVolume.hasCollision(ent.getBoundingVolume());
192+ return boundingVolume.hasCollision(position,
193+ ent.getBoundingVolume(), ent.getPosition());
206194 } else {
207195 return false;
208196 }
@@ -217,7 +205,8 @@ public class Entity implements EntityInterface {
217205 */
218206 public float distance(Entity ent) {
219207 if(null != boundingVolume) {
220- return boundingVolume.distance(ent.getBoundingVolume());
208+ return boundingVolume.distance(position, ent.getBoundingVolume(),
209+ ent.getPosition());
221210 } else {
222211 return -1.0f;
223212 }
@@ -377,30 +366,13 @@ public class Entity implements EntityInterface {
377366 */
378367 public void checkVisibility(Frustum frustum) {
379368 if(null != boundingVolume) {
380- isVisible = boundingVolume.isVisible(frustum);
369+ isVisible = boundingVolume.isVisible(position, frustum);
381370 } else {
382371 isVisible = true;
383372 }
384373 }
385374
386375 /**
387- * <code>setVisibilityType</code> sets what type of visibility check will
388- * be used for this entity. Valid parameters are: VISIBILITY_POINT,
389- * VISIBILITY_SPHERE, and VISIBILITY_CUBE.
390- * @param type what type of test to make for visibilty.
391- * @throws MonkeyRuntimeException if the visibilty flag is not valid.
392- */
393- public void setVisibilityType(int type) {
394- if (type != VISIBILITY_POINT
395- && type != VISIBILITY_SPHERE
396- && type != VISIBILITY_CUBE) {
397-
398- throw new MonkeyRuntimeException("Invalid visibility type.");
399- }
400- this.visibilityType = type;
401- }
402-
403- /**
404376 * <code>toString</code> creates a string representation of the
405377 * <code>Entity</code> object. The format is as follows:<br><br>
406378 *
--- a/src/jme/geometry/bounding/BoundingBox.java
+++ b/src/jme/geometry/bounding/BoundingBox.java
@@ -40,12 +40,13 @@ import jme.math.Vector;
4040 * all vertices that make up the geometry.
4141 *
4242 * @author Mark Powell
43- * @version $Id: BoundingBox.java,v 1.6 2003-09-08 20:29:28 mojomonkey Exp $
43+ * @version $Id: BoundingBox.java,v 1.7 2003-09-10 20:32:59 mojomonkey Exp $
4444 */
4545 public class BoundingBox implements BoundingVolume {
4646 private Vector center;
4747 private Vector minPoint;
4848 private Vector maxPoint;
49+ private float collisionBuffer;
4950
5051 /**
5152 * Default constructor instantiates a new <code>BoundingBox</code>
@@ -93,8 +94,12 @@ public class BoundingBox implements BoundingVolume {
9394 * @param points the list of points to contain.
9495 */
9596 public void axisAligned(Vector[] points) {
96- minPoint = points[0];
97- maxPoint = minPoint;
97+ minPoint.x = points[0].x;
98+ minPoint.y = points[0].y;
99+ minPoint.z = points[0].z;
100+ maxPoint.x = minPoint.x;
101+ maxPoint.y = minPoint.y;
102+ maxPoint.z = minPoint.z;
98103
99104 for (int i = 1; i < points.length; i++) {
100105 if (points[i].x < minPoint.x)
@@ -112,6 +117,10 @@ public class BoundingBox implements BoundingVolume {
112117 else if (points[i].z > maxPoint.z)
113118 maxPoint.z = points[i].z;
114119 }
120+
121+ center.x = (maxPoint.x + minPoint.x) / 2;
122+ center.y = (maxPoint.y + minPoint.y) / 2;
123+ center.z = (maxPoint.z + minPoint.z) / 2;
115124 }
116125
117126 /**
@@ -166,15 +175,36 @@ public class BoundingBox implements BoundingVolume {
166175 this.maxPoint = maxPoint;
167176 }
168177
169- public boolean hasCollision(BoundingVolume volume) {
178+ /**
179+ * <code>hasCollision</code> will determine if this volume is colliding
180+ * (touching in any way) with another volume.
181+ * @param sourceOffset defines the position of the entity containing
182+ * this volume, if null it is ignored.
183+ * @param volume the bounding volume to compare.
184+ * @param targetOffset defines the position of the entity containing
185+ * the target volume, if null it is ignored.
186+ * @return true if there is a collision, false otherwise.
187+ */
188+ public boolean hasCollision(Vector sourceOffset, BoundingVolume volume,
189+ Vector targetOffset) {
170190 return false;
171191 }
172192
173- public float distance(BoundingVolume volume) {
193+ /**
194+ * <code>setCollisionBuffer</code> sets the value that must be reached to
195+ * consider bounding volumes colliding. By default this value is 0.
196+ * @param buffer the collision buffer.
197+ */
198+ public void setCollisionBuffer(float buffer) {
199+ collisionBuffer = buffer;
200+ }
201+
202+ public float distance(Vector sourceOffset, BoundingVolume volume,
203+ Vector targetOffset) {
174204 return -1.0f;
175205 }
176206
177- public boolean isVisible(Frustum frustum) {
207+ public boolean isVisible(Vector offsetPosition, Frustum frustum) {
178208 return true;
179209 }
180210
--- a/src/jme/geometry/bounding/BoundingCapsule.java
+++ b/src/jme/geometry/bounding/BoundingCapsule.java
@@ -43,11 +43,12 @@ import jme.math.Vector;
4343 * thought of as a cylinder with domed caps.
4444 *
4545 * @author Mark Powell
46- * @version $Id: BoundingCapsule.java,v 1.5 2003-09-08 20:29:28 mojomonkey Exp $
46+ * @version $Id: BoundingCapsule.java,v 1.6 2003-09-10 20:32:59 mojomonkey Exp $
4747 */
4848 public class BoundingCapsule implements BoundingVolume {
4949 private Line lineSegment;
5050 private float radius;
51+ private float collisionBuffer;
5152
5253 /**
5354 * Default constructor instantiates an empty bounding capsule. Both the
@@ -105,8 +106,7 @@ public class BoundingCapsule implements BoundingVolume {
105106 * @param points the points to contain.
106107 */
107108 public void leastSquaresFit(Vector[] points) {
108-
109- Line line = Approximation.orthogonalLineFit(points);
109+ Line line = Approximation.orthogonalLineFit(points);
110110
111111 float maxRadiusSqr = 0.0f;
112112
@@ -154,17 +154,38 @@ public class BoundingCapsule implements BoundingVolume {
154154 }
155155
156156 radius = (float) Math.sqrt(maxRadiusSqr);
157- }
157+ }
158158
159- public boolean hasCollision(BoundingVolume volume) {
159+ /**
160+ * <code>hasCollision</code> will determine if this volume is colliding
161+ * (touching in any way) with another volume.
162+ * @param sourceOffset defines the position of the entity containing
163+ * this volume, if null it is ignored.
164+ * @param volume the bounding volume to compare.
165+ * @param targetOffset defines the position of the entity containing
166+ * the target volume, if null it is ignored.
167+ * @return true if there is a collision, false otherwise.
168+ */
169+ public boolean hasCollision(Vector sourceOffset, BoundingVolume volume,
170+ Vector targetOffset) {
160171 return false;
161172 }
173+
174+ /**
175+ * <code>setCollisionBuffer</code> sets the value that must be reached to
176+ * consider bounding volumes colliding. By default this value is 0.
177+ * @param buffer the collision buffer.
178+ */
179+ public void setCollisionBuffer(float buffer) {
180+ collisionBuffer = buffer;
181+ }
162182
163- public float distance(BoundingVolume volume) {
183+ public float distance(Vector sourceOffset, BoundingVolume volume,
184+ Vector targetOffset) {
164185 return -1.0f;
165186 }
166187
167- public boolean isVisible(Frustum frustum) {
188+ public boolean isVisible(Vector offsetPosition, Frustum frustum) {
168189 return true;
169190 }
170191 }
--- a/src/jme/geometry/bounding/BoundingCylinder.java
+++ b/src/jme/geometry/bounding/BoundingCylinder.java
@@ -44,7 +44,7 @@ import jme.math.Vector;
4444 * also defined by the equation Xi = P + RYi where R = [U V D], and U V causes
4545 * R to be orthonormal.
4646 * @author Mark Powell
47- * @version $Id: BoundingCylinder.java,v 1.3 2003-09-08 20:29:28 mojomonkey Exp $
47+ * @version $Id: BoundingCylinder.java,v 1.4 2003-09-10 20:32:59 mojomonkey Exp $
4848 */
4949 public class BoundingCylinder implements BoundingVolume {
5050 private Vector center; //P
@@ -53,6 +53,63 @@ public class BoundingCylinder implements BoundingVolume {
5353 private Vector v;
5454 private float height;
5555 private float radius;
56+ private float collisionBuffer;
57+
58+ /**
59+ * @return
60+ */
61+ public Vector getCenter() {
62+ return center;
63+ }
64+
65+ /**
66+ * @param center
67+ */
68+ public void setCenter(Vector center) {
69+ this.center = center;
70+ }
71+
72+ /**
73+ * @return
74+ */
75+ public Vector getDirection() {
76+ return direction;
77+ }
78+
79+ /**
80+ * @param direction
81+ */
82+ public void setDirection(Vector direction) {
83+ this.direction = direction;
84+ }
85+
86+ /**
87+ * @return
88+ */
89+ public float getHeight() {
90+ return height;
91+ }
92+
93+ /**
94+ * @param height
95+ */
96+ public void setHeight(float height) {
97+ this.height = height;
98+ }
99+
100+ /**
101+ * @return
102+ */
103+ public float getRadius() {
104+ return radius;
105+ }
106+
107+ /**
108+ * @param radius
109+ */
110+ public void setRadius(float radius) {
111+ this.radius = radius;
112+ }
56113
57114 /**
58115 * Constructor instantiates a new <code>BoundingCylinder</code> with
@@ -143,15 +200,36 @@ public class BoundingCylinder implements BoundingVolume {
143200
144201 }
145202
146- public boolean hasCollision(BoundingVolume volume) {
203+ /**
204+ * <code>setCollisionBuffer</code> sets the value that must be reached to
205+ * consider bounding volumes colliding. By default this value is 0.
206+ * @param buffer the collision buffer.
207+ */
208+ public void setCollisionBuffer(float buffer) {
209+ collisionBuffer = buffer;
210+ }
211+
212+ /**
213+ * <code>hasCollision</code> will determine if this volume is colliding
214+ * (touching in any way) with another volume.
215+ * @param sourceOffset defines the position of the entity containing
216+ * this volume, if null it is ignored.
217+ * @param volume the bounding volume to compare.
218+ * @param targetOffset defines the position of the entity containing
219+ * the target volume, if null it is ignored.
220+ * @return true if there is a collision, false otherwise.
221+ */
222+ public boolean hasCollision(Vector sourceOffset, BoundingVolume volume,
223+ Vector targetOffset) {
147224 return false;
148225 }
149226
150- public float distance(BoundingVolume volume) {
227+ public float distance(Vector sourceOffset, BoundingVolume volume,
228+ Vector targetOffset) {
151229 return -1.0f;
152230 }
153231
154- public boolean isVisible(Frustum frustum) {
232+ public boolean isVisible(Vector offsetPosition, Frustum frustum) {
155233 return true;
156234 }
157235
--- a/src/jme/geometry/bounding/BoundingEllipsoid.java
+++ b/src/jme/geometry/bounding/BoundingEllipsoid.java
@@ -41,13 +41,42 @@ import jme.math.Vector;
4141 * with a center of (0, 0, 0). The ellipsoid can also be expressed as the
4242 * center matrix form (and will be in this class) as: (X-C)^T A (X-C) = 1.
4343 * @author Mark Powell
44- * @version $Id: BoundingEllipsoid.java,v 1.3 2003-09-08 20:29:28 mojomonkey Exp $
44+ * @version $Id: BoundingEllipsoid.java,v 1.4 2003-09-10 20:32:59 mojomonkey Exp $
4545 *
4646 */
4747 public class BoundingEllipsoid implements BoundingVolume {
4848 private Vector center;
4949 private Matrix a;
5050 private Matrix inverseA;
51+ private float collisionBuffer;
52+
53+ /**
54+ * @return
55+ */
56+ public Matrix getA() {
57+ return a;
58+ }
59+
60+ /**
61+ * @param a
62+ */
63+ public void setA(Matrix a) {
64+ this.a = a;
65+ }
66+
67+ /**
68+ * @return
69+ */
70+ public Vector getCenter() {
71+ return center;
72+ }
73+
74+ /**
75+ * @param center
76+ */
77+ public void setCenter(Vector center) {
78+ this.center = center;
79+ }
5180
5281 /**
5382 * Constructor instantiates a new <code>BoundingEllipsoid</code> with default
@@ -81,9 +110,11 @@ public class BoundingEllipsoid implements BoundingVolume {
81110 */
82111 public void gaussianDistribution(Vector[] points) {
83112 Vector[] axis = new Vector[3];
113+ for(int i = 0; i < 3; i++) {
114+ axis[i] = new Vector();
115+ }
84116 float[] d = new float[3];
85117 Approximation.gaussPointsFit(points, center, axis, d);
86-
87118 float maxValue = 0.0f;
88119 for (int i = 0; i < points.length; i++) {
89120 Vector diff = points[i].subtract(center);
@@ -104,6 +135,9 @@ public class BoundingEllipsoid implements BoundingVolume {
104135 }
105136
106137 Matrix[] tensor = new Matrix[3];
138+ for(int i = 0; i < 3; i++) {
139+ tensor[i] = new Matrix();
140+ }
107141 tensor[0].tensorProduct(axis[0], axis[0]);
108142 tensor[1].tensorProduct(axis[1], axis[1]);
109143 tensor[2].tensorProduct(axis[2], axis[2]);
@@ -118,15 +152,36 @@ public class BoundingEllipsoid implements BoundingVolume {
118152
119153 }
120154
121- public boolean hasCollision(BoundingVolume volume) {
155+ /**
156+ * <code>setCollisionBuffer</code> sets the value that must be reached to
157+ * consider bounding volumes colliding. By default this value is 0.
158+ * @param buffer the collision buffer.
159+ */
160+ public void setCollisionBuffer(float buffer) {
161+ collisionBuffer = buffer;
162+ }
163+
164+ /**
165+ * <code>hasCollision</code> will determine if this volume is colliding
166+ * (touching in any way) with another volume.
167+ * @param sourceOffset defines the position of the entity containing
168+ * this volume, if null it is ignored.
169+ * @param volume the bounding volume to compare.
170+ * @param targetOffset defines the position of the entity containing
171+ * the target volume, if null it is ignored.
172+ * @return true if there is a collision, false otherwise.
173+ */
174+ public boolean hasCollision(Vector sourceOffset, BoundingVolume volume,
175+ Vector targetOffset) {
122176 return false;
123177 }
124178
125- public float distance(BoundingVolume volume) {
179+ public float distance(Vector sourceOffset, BoundingVolume volume,
180+ Vector targetOffset) {
126181 return -1.0f;
127182 }
128183
129- public boolean isVisible(Frustum frustum) {
184+ public boolean isVisible(Vector offsetPosition, Frustum frustum) {
130185 return true;
131186 }
132187 }
--- a/src/jme/geometry/bounding/BoundingLozenge.java
+++ b/src/jme/geometry/bounding/BoundingLozenge.java
@@ -43,11 +43,40 @@ import jme.math.Vector;
4343 * <br><br>
4444 * <b>NOTE:</b> See 3D Game Engine Design. David H. Eberly.
4545 * @author Mark Powell
46- * @version $Id: BoundingLozenge.java,v 1.4 2003-09-08 20:29:28 mojomonkey Exp $
46+ * @version $Id: BoundingLozenge.java,v 1.5 2003-09-10 20:32:59 mojomonkey Exp $
4747 */
4848 public class BoundingLozenge implements BoundingVolume {
4949 private Rectangle rectangle;
5050 private float radius;
51+ private float collisionBuffer;
52+
53+ /**
54+ * @return
55+ */
56+ public float getRadius() {
57+ return radius;
58+ }
59+
60+ /**
61+ * @param radius
62+ */
63+ public void setRadius(float radius) {
64+ this.radius = radius;
65+ }
66+
67+ /**
68+ * @return
69+ */
70+ public Rectangle getRectangle() {
71+ return rectangle;
72+ }
73+
74+ /**
75+ * @param rectangle
76+ */
77+ public void setRectangle(Rectangle rectangle) {
78+ this.rectangle = rectangle;
79+ }
5180
5281 /**
5382 * Constructor instantiates a new <code>BoundingLozenge</code> object.
@@ -69,14 +98,17 @@ public class BoundingLozenge implements BoundingVolume {
6998 }
7099
71100 /**
72- * <code>guassianDistribution</code> calculates the average of the points,
101+ * <code>gaussianDistribution</code> calculates the average of the points,
73102 * and a covariance matrix to determine the rectangle of the lozenge. The
74103 * radius is than calculated to best fit all the points.
75104 * @param points the list of points to contain.
76105 */
77- public void guassianDistribution(Vector[] points) {
106+ public void gaussianDistribution(Vector[] points) {
78107 Vector center = new Vector();
79108 Vector[] axis = new Vector[3];
109+ for(int i = 0; i < axis.length; i++) {
110+ axis[i] = new Vector();
111+ }
80112 float[] extent = new float[3];
81113 Approximation.gaussPointsFit(points, center, axis, extent);
82114
@@ -234,15 +266,36 @@ public class BoundingLozenge implements BoundingVolume {
234266
235267 }
236268
237- public boolean hasCollision(BoundingVolume volume) {
269+ /**
270+ * <code>setCollisionBuffer</code> sets the value that must be reached to
271+ * consider bounding volumes colliding. By default this value is 0.
272+ * @param buffer the collision buffer.
273+ */
274+ public void setCollisionBuffer(float buffer) {
275+ collisionBuffer = buffer;
276+ }
277+
278+ /**
279+ * <code>hasCollision</code> will determine if this volume is colliding
280+ * (touching in any way) with another volume.
281+ * @param sourceOffset defines the position of the entity containing
282+ * this volume, if null it is ignored.
283+ * @param volume the bounding volume to compare.
284+ * @param targetOffset defines the position of the entity containing
285+ * the target volume, if null it is ignored.
286+ * @return true if there is a collision, false otherwise.
287+ */
288+ public boolean hasCollision(Vector sourceOffset, BoundingVolume volume,
289+ Vector targetOffset) {
238290 return false;
239291 }
240292
241- public float distance(BoundingVolume volume) {
293+ public float distance(Vector sourceOffset, BoundingVolume volume,
294+ Vector targetOffset) {
242295 return -1.0f;
243296 }
244297
245- public boolean isVisible(Frustum frustum) {
298+ public boolean isVisible(Vector offsetPosition, Frustum frustum) {
246299 return true;
247300 }
248301 }
--- a/src/jme/geometry/bounding/BoundingSphere.java
+++ b/src/jme/geometry/bounding/BoundingSphere.java
@@ -33,6 +33,7 @@
3333 package jme.geometry.bounding;
3434
3535 import jme.entity.camera.Frustum;
36+import jme.math.Distance;
3637 import jme.math.Vector;
3738
3839 /**
@@ -46,12 +47,13 @@ import jme.math.Vector;
4647 *
4748 *
4849 * @author Mark Powell
49- * @version $Id: BoundingSphere.java,v 1.5 2003-09-08 20:29:28 mojomonkey Exp $
50+ * @version $Id: BoundingSphere.java,v 1.6 2003-09-10 20:32:59 mojomonkey Exp $
5051 */
5152 public class BoundingSphere implements BoundingVolume {
5253 private float radius;
5354 private Vector center;
54-
55+ private float collisionBuffer;
56+
5557 /**
5658 * Default contstructor instantiates a new <code>BoundingSphere</code>
5759 * object.
@@ -114,8 +116,8 @@ public class BoundingSphere implements BoundingVolume {
114116 * @param points the list of points.
115117 */
116118 public void containAABB(Vector[] points) {
117- Vector min = points[0];
118- Vector max = min;
119+ Vector min = new Vector(points[0].x,points[0].y,points[0].z);
120+ Vector max = new Vector(min.x, min.y, min.z);
119121 for (int i = 1; i < points.length; i++) {
120122 if (points[i].x < min.x)
121123 min.x = points[i].x;
@@ -166,15 +168,83 @@ public class BoundingSphere implements BoundingVolume {
166168
167169 }
168170
169- public boolean hasCollision(BoundingVolume volume) {
170- return false;
171+ /**
172+ * <code>setCollisionBuffer</code> sets the value that must be reached to
173+ * consider bounding volumes colliding. By default this value is 0.
174+ * @param buffer the collision buffer.
175+ */
176+ public void setCollisionBuffer(float buffer) {
177+ collisionBuffer = buffer;
178+ }
179+
180+ /**
181+ * <code>hasCollision</code> returns true if an collision is occuring with
182+ * the given bounding volume and this volume. Offsets are given to allow
183+ * for positional representations of the volumes.
184+ * @param sourceOffset defines the position of the entity containing
185+ * this volume, if null it is ignored.
186+ * @param volume the bounding volume to compare.
187+ * @param targetOffset defines the position of the entity containing
188+ * the target volume, if null it is ignored.
189+ * @return true if a collision has occured, false otherwise.
190+ */
191+ public boolean hasCollision(Vector sourceOffset, BoundingVolume volume,
192+ Vector targetOffset) {
193+
194+ float distance = distance(sourceOffset, volume, targetOffset);
195+ System.out.println(distance);
196+ if(distance <= collisionBuffer && distance != -1.0f) {
197+ return true;
198+ } else {
199+ return false;
200+ }
171201 }
172202
173- public float distance(BoundingVolume volume) {
174- return -1.0f;
203+ /**
204+ * <code>distance</code> returns the distance between this volume and
205+ * a given volume. Offsets are used to represent positions of the
206+ * entities that may be contained by the volume.
207+ * @param sourceOffset defines the position of the entity containing
208+ * this volume, if null it is ignored.
209+ * @param volume the bounding volume to compare.
210+ * @param targetOffset defines the position of the entity containing
211+ * the target volume, if null it is ignored.
212+ * @return the distance between the two bounding volumes. -1 if there is
213+ * a problem.
214+ */
215+ public float distance(Vector sourceOffset, BoundingVolume volume,
216+ Vector targetOffset) {
217+ float rad = ((BoundingSphere)volume).radius + radius;
218+ System.out.println(((BoundingSphere)volume).radius + " + " + radius + " = " + rad);
219+ float dis = Distance.distancePointPoint(sourceOffset, targetOffset);
220+ if(dis < 0) {
221+ return 0;
222+ } else {
223+ return dis;
224+ }
175225 }
176226
177- public boolean isVisible(Frustum frustum) {
178- return true;
227+ /**
228+ * <code>isVisible</code> calculates whether or not this bounding volume
229+ * is within a view frustum. The location of the sphere can be modified
230+ * with an offset position to allow for movement of any entity that the
231+ * volume is attached to.
232+ * @param offsetPosition the offset for the center of the volume.
233+ * @param frustum the view frustum to check against.
234+ * @return true if the volume is in the volume, false otherwise.
235+ */
236+ public boolean isVisible(Vector offsetPosition, Frustum frustum) {
237+ if(null != frustum) {
238+ if(offsetPosition != null) {
239+ Vector finalCenter = offsetPosition.add(center);
240+ return frustum.containsSphere(finalCenter.x, finalCenter.y,
241+ finalCenter.z, radius);
242+ } else {
243+ return frustum.containsSphere(center.x, center.y, center.z,
244+ radius);
245+ }
246+ } else {
247+ return true;
248+ }
179249 }
180250 }
--- a/src/jme/geometry/bounding/BoundingVolume.java
+++ b/src/jme/geometry/bounding/BoundingVolume.java
@@ -32,15 +32,56 @@
3232 package jme.geometry.bounding;
3333
3434 import jme.entity.camera.Frustum;
35+import jme.math.Vector;
3536
3637 /**
3738 * <code>BoundingVolume</code> defines an interface for dealing with containment
3839 * of a collection of points.
3940 * @author Mark Powell
40- * @version $Id: BoundingVolume.java,v 1.2 2003-09-08 20:29:28 mojomonkey Exp $
41+ * @version $Id: BoundingVolume.java,v 1.3 2003-09-10 20:32:59 mojomonkey Exp $
4142 */
4243 public interface BoundingVolume {
43- public boolean hasCollision(BoundingVolume volume);
44- public float distance(BoundingVolume distance);
45- public boolean isVisible(Frustum frustum);
44+ /**
45+ * <code>hasCollision</code> will determine if this volume is colliding
46+ * (touching in any way) with another volume.
47+ * @param sourceOffset defines the position of the entity containing
48+ * this volume, if null it is ignored.
49+ * @param volume the bounding volume to compare.
50+ * @param targetOffset defines the position of the entity containing
51+ * the target volume, if null it is ignored.
52+ * @return true if there is a collision, false otherwise.
53+ */
54+ public boolean hasCollision(Vector sourceOffset, BoundingVolume volume,
55+ Vector targetOffset);
56+
57+ /**
58+ * <code>distance</code> calculates the distance between this volume and
59+ * a given volume. If there is a problem, a distance of -1 is returned.
60+ * @param sourceOffset defines the position of the entity containing
61+ * this volume, if null it is ignored.
62+ * @param volume the bounding volume to compare.
63+ * @param targetOffset defines the position of the entity containing
64+ * the target volume, if null it is ignored.
65+ * @return the distance between this volume and a given volume.
66+ */
67+ public float distance(Vector sourceOffset, BoundingVolume volume,
68+ Vector targetOffset);
69+
70+ /**
71+ * <code>isVisible</code> determines if the bounding volume is visible
72+ * within a viewing frustum. A offset is used to modify the center of
73+ * the bounding volume with the position of the entity to be checked.
74+ * @param offsetPosition the position of the entity that may contain the
75+ * bounding volume. If null is passed, offset is ignored.
76+ * @param frustum the view frustum.
77+ * @return true if the object is visible, false otherwise.
78+ */
79+ public boolean isVisible(Vector offsetPosition, Frustum frustum);
80+
81+ /**
82+ * <code>setCollisionBuffer</code> sets the value that must be reached to
83+ * consider bounding volumes colliding. By default this value is 0.
84+ * @param buffer the collision buffer.
85+ */
86+ public void setCollisionBuffer(float buffer);
4687 }
--- a/src/jme/geometry/model/md3/Md3Model.java
+++ b/src/jme/geometry/model/md3/Md3Model.java
@@ -96,7 +96,7 @@ import org.lwjgl.opengl.Window;
9696 *
9797 *
9898 * @author Mark Powell
99- * @version $Id: Md3Model.java,v 1.10 2003-09-09 14:13:10 mojomonkey Exp $
99+ * @version $Id: Md3Model.java,v 1.11 2003-09-10 20:32:59 mojomonkey Exp $
100100 */
101101 public class Md3Model implements Geometry {
102102 /**
@@ -743,6 +743,7 @@ public class Md3Model implements Geometry {
743743
744744 // Seek to the start of the vertex/face index information, then read it in.
745745 buffer.position(meshOffset + meshHeader.vertexStart);
746+ Vector temp = new Vector();
746747 for (i = 0;
747748 i < meshHeader.numMeshFrames * meshHeader.numVertices;
748749 i++) {
@@ -751,8 +752,10 @@ public class Md3Model implements Geometry {
751752 vertices[i].vertex[0] = buffer.getShort();
752753 vertices[i].vertex[1] = buffer.getShort();
753754 vertices[i].vertex[2] = buffer.getShort();
754- points.add(new Vector(vertices[i].vertex[0],
755- vertices[i].vertex[1], vertices[i].vertex[2]));
755+ temp.x = vertices[i].vertex[0];
756+ temp.y = vertices[i].vertex[1];
757+ temp.z = vertices[i].vertex[2];
758+ points.add(temp);
756759 vertices[i].normal[0] = buffer.get();
757760 vertices[i].normal[1] = buffer.get();
758761 }
--- a/src/jme/math/Approximation.java
+++ b/src/jme/math/Approximation.java
@@ -38,7 +38,7 @@ package jme.math;
3838 * <br><br>
3939 * <b>NOTE:</b> See 3D Game Engine Design. David H. Eberly.
4040 * @author Mark Powell
41- * @version $Id: Approximation.java,v 1.2 2003-08-27 21:05:42 mojomonkey Exp $
41+ * @version $Id: Approximation.java,v 1.3 2003-09-10 20:32:59 mojomonkey Exp $
4242 *
4343 */
4444 public class Approximation {
@@ -112,21 +112,25 @@ public class Approximation {
112112 * @param extent storage for the length of the rectangle.
113113 */
114114 public static void gaussPointsFit(
115+
115116 Vector[] points,
116117 Vector center,
117118 Vector[] axis,
118119 float[] extent) {
119120
120121 // compute mean of points
121- center = points[0];
122+ center.x = points[0].x;
123+ center.y = points[0].y;
124+ center.z = points[0].z;
122125
123126 for (int i = 1; i < points.length; i++) {
124- center = center.add(points[i]);
127+ center.addToThis(points[i]);
125128 }
126129
130+
127131 float inverseQuantity = 1.0f / points.length;
128- center = center.mult(inverseQuantity);
129-
132+ center.multThis(inverseQuantity);
133+
130134 // compute covariances of points
131135 float sumXX = 0.0f;
132136 float sumXY = 0.0f;
@@ -177,7 +181,7 @@ public class Approximation {
177181 axis[2].x = eigen.getEigenvector(0, 2);
178182 axis[2].y = eigen.getEigenvector(1, 2);
179183 axis[2].z = eigen.getEigenvector(2, 2);
180-
184+
181185 extent[0] = eigen.getRealEigenvalue(0);
182186 extent[1] = eigen.getRealEigenvalue(1);
183187 extent[2] = eigen.getRealEigenvalue(2);
--- a/src/jme/math/Distance.java
+++ b/src/jme/math/Distance.java
@@ -51,7 +51,10 @@ public class Distance {
5151 * @return the distance between point1 and point2.
5252 */
5353 public static float distancePointPoint(Vector point1, Vector point2) {
54- return (float) Math.sqrt(distancePointPointSquared(point1, point2));
54+ System.out.println("Checking: " + point1 + " " + point2);
55+ float value = (float) Math.sqrt(distancePointPointSquared(point1, point2));
56+ System.out.println("RETURNING " + value);
57+ return value;
5558 }
5659
5760 /**
--- a/src/jme/math/Vector.java
+++ b/src/jme/math/Vector.java
@@ -36,7 +36,7 @@ import jme.exception.MonkeyRuntimeException;
3636 /**
3737 * <code>Vector</code> defines a three dimensional vector of (x,y,z).
3838 * @author Mark Powell
39- * @version $Id: Vector.java,v 1.8 2003-09-04 21:17:51 mojomonkey Exp $
39+ * @version $Id: Vector.java,v 1.9 2003-09-10 20:32:59 mojomonkey Exp $
4040 */
4141 public class Vector {
4242 public float x;
@@ -48,7 +48,7 @@ public class Vector {
4848 * (0, 0, 0).
4949 */
5050 public Vector() {
51- x = 0;
51+ x = 0;
5252 y = 0;
5353 z = 0;
5454 }
@@ -119,6 +119,17 @@ public class Vector {
119119 public Vector mult(float scalar) {
120120 return new Vector(x * scalar, y * scalar, z * scalar);
121121 }
122+
123+ /**
124+ * <code>multThis</code> multiplies this vector by a given scalar.
125+ *
126+ * @param scalar the scalar to multiply by.
127+ */
128+ public void multThis(float scalar) {
129+ x *= scalar;
130+ y *= scalar;
131+ z *= scalar;
132+ }
122133
123134 /**
124135 * <code>add</code> adds the values of this vector by another
@@ -130,6 +141,16 @@ public class Vector {
130141 public Vector add(Vector v) {
131142 return new Vector(x + v.x, y + v.y, z + v.z);
132143 }
144+
145+ /**
146+ * <code>addToThis</code> adds a vector to this vector.
147+ * @param v the vector to add to this.
148+ */
149+ public void addToThis(Vector v) {
150+ x += v.x;
151+ y += v.y;
152+ z += v.z;
153+ }
133154
134155 /**
135156 * <code>subtract</code> subtracts the values of this vector by
@@ -196,6 +217,12 @@ public class Vector {
196217 return out;
197218 }
198219
220+ /**
221+ * <code>inverseRotate</code> rotates this vector inversly by a rotation
222+ * matrix. A new Vector is returned.
223+ * @param m the rotational matrix.
224+ * @return the new vector.
225+ */
199226 public Vector inverseRotate(Matrix m) {
200227 Vector out = new Vector();
201228 out.x = x * m.matrix[0][0] + y * m.matrix[1][0] + z * m.matrix[2][0];
--- a/src/jme/system/DisplaySystem.java
+++ b/src/jme/system/DisplaySystem.java
@@ -76,10 +76,10 @@ import org.lwjgl.opengl.Window;
7676 * and create a new system.
7777 *
7878 * @author Mark Powell
79- * @version $Id: DisplaySystem.java,v 1.10 2003-09-08 20:29:28 mojomonkey Exp $
79+ * @version $Id: DisplaySystem.java,v 1.11 2003-09-10 20:32:59 mojomonkey Exp $
8080 */
8181 public class DisplaySystem {
82- private static String VERSION = "jME version 0.1.0";
82+ private static String VERSION = "jME version 0.1.1";
8383 //Singleton reference.
8484 private static DisplaySystem instance = null;
8585
--- /dev/null
+++ b/src/test/bounding/KeyController.java
@@ -0,0 +1,65 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
3+ * All rights reserved.
4+ *
5+ * Redistribution and use in source and binary forms, with or without
6+ * modification, are permitted provided that the following conditions are met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+
33+package test.bounding;
34+
35+import org.lwjgl.input.Keyboard;
36+import jme.controller.BaseFPSController;
37+import jme.entity.*;
38+import jme.entity.camera.Camera;
39+import jme.system.DisplaySystem;
40+
41+public class KeyController extends BaseFPSController {
42+
43+ public KeyController(Entity entity) {
44+ super((Camera)entity);
45+ setAccuracy(150);
46+ setKeys();
47+ }
48+
49+ public void setKeys() {
50+ key.set("screenshot", Keyboard.KEY_P);
51+ }
52+
53+ protected boolean checkAdditionalKeys() {
54+
55+ if(isKeyDown("exit")) {
56+ return false;
57+ }
58+
59+ if(isKeyDown("screenshot")) {
60+ DisplaySystem.getDisplaySystem().takeScreenShot("test");
61+ return true;
62+ }
63+ return true;
64+ }
65+}
\ No newline at end of file
--- /dev/null
+++ b/src/test/bounding/TestBoundingBox.java
@@ -0,0 +1,203 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
3+ * All rights reserved.
4+ *
5+ * Redistribution and use in source and binary forms, with or without
6+ * modification, are permitted provided that the following conditions are met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+package test.bounding;
33+
34+import org.lwjgl.Display;
35+import org.lwjgl.opengl.GL;
36+import org.lwjgl.opengl.GLU;
37+import org.lwjgl.opengl.Window;
38+
39+import jme.AbstractGame;
40+import jme.entity.camera.Camera;
41+import jme.geometry.bounding.BoundingBox;
42+import jme.geometry.hud.text.Font2D;
43+import jme.math.Vector;
44+import jme.system.DisplaySystem;
45+import jme.utility.Timer;
46+
47+/**
48+ * @author Mark Powell
49+ */
50+public class TestBoundingBox extends AbstractGame {
51+ private Timer timer;
52+ private Camera camera;
53+ private KeyController controller;
54+ private Vector[] points;
55+ private BoundingBox bb;
56+ private Font2D font;
57+
58+ /* (non-Javadoc)
59+ * @see jme.AbstractGame#update()
60+ */
61+ protected void update() {
62+ if(!controller.update(timer.getFrameRate())) {
63+ finish();
64+ }
65+ timer.update();
66+
67+ }
68+
69+ /* (non-Javadoc)
70+ * @see jme.AbstractGame#render()
71+ */
72+ protected void render() {
73+ GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
74+ GL.glLoadIdentity();
75+ controller.render();
76+
77+ GL.glBegin(GL.GL_LINES);
78+ GL.glColor3f(0.0f, 1.0f, 0.0f);
79+ for(int i = 0; i < points.length; i++) {
80+ GL.glVertex3f(points[i].x, points[i].y, points[i].z);
81+ }
82+
83+
84+ GL.glEnd();
85+
86+ GL.glBegin(GL.GL_POINTS);
87+ GL.glColor3f(1.0f,0.0f,0.0f);
88+ GL.glVertex3f(bb.getCenter().x,bb.getCenter().y,bb.getCenter().z);
89+ GL.glEnd();
90+
91+ GL.glBegin(GL.GL_LINES);
92+ GL.glColor3f(0.0f,0.0f,1.0f);
93+ GL.glVertex3f(bb.getMinPoint().x,bb.getMinPoint().y,bb.getMinPoint().z);
94+ GL.glVertex3f(bb.getMinPoint().x,bb.getMaxPoint().y,bb.getMinPoint().z);
95+ GL.glVertex3f(bb.getMinPoint().x,bb.getMaxPoint().y,bb.getMinPoint().z);
96+ GL.glVertex3f(bb.getMaxPoint().x,bb.getMaxPoint().y,bb.getMinPoint().z);
97+ GL.glVertex3f(bb.getMaxPoint().x,bb.getMaxPoint().y,bb.getMinPoint().z);
98+ GL.glVertex3f(bb.getMaxPoint().x,bb.getMinPoint().y,bb.getMinPoint().z);
99+ GL.glVertex3f(bb.getMaxPoint().x,bb.getMinPoint().y,bb.getMinPoint().z);
100+ GL.glVertex3f(bb.getMinPoint().x,bb.getMinPoint().y,bb.getMinPoint().z);
101+
102+ GL.glVertex3f(bb.getMinPoint().x,bb.getMinPoint().y,bb.getMaxPoint().z);
103+ GL.glVertex3f(bb.getMinPoint().x,bb.getMaxPoint().y,bb.getMaxPoint().z);
104+ GL.glVertex3f(bb.getMinPoint().x,bb.getMaxPoint().y,bb.getMaxPoint().z);
105+ GL.glVertex3f(bb.getMaxPoint().x,bb.getMaxPoint().y,bb.getMaxPoint().z);
106+ GL.glVertex3f(bb.getMaxPoint().x,bb.getMaxPoint().y,bb.getMaxPoint().z);
107+ GL.glVertex3f(bb.getMaxPoint().x,bb.getMinPoint().y,bb.getMaxPoint().z);
108+ GL.glVertex3f(bb.getMaxPoint().x,bb.getMinPoint().y,bb.getMaxPoint().z);
109+ GL.glVertex3f(bb.getMinPoint().x,bb.getMinPoint().y,bb.getMaxPoint().z);
110+
111+ GL.glVertex3f(bb.getMinPoint().x,bb.getMinPoint().y,bb.getMinPoint().z);
112+ GL.glVertex3f(bb.getMinPoint().x,bb.getMinPoint().y,bb.getMaxPoint().z);
113+ GL.glVertex3f(bb.getMinPoint().x,bb.getMaxPoint().y,bb.getMinPoint().z);
114+ GL.glVertex3f(bb.getMinPoint().x,bb.getMaxPoint().y,bb.getMaxPoint().z);
115+ GL.glVertex3f(bb.getMaxPoint().x,bb.getMaxPoint().y,bb.getMinPoint().z);
116+ GL.glVertex3f(bb.getMaxPoint().x,bb.getMaxPoint().y,bb.getMaxPoint().z);
117+ GL.glVertex3f(bb.getMaxPoint().x,bb.getMinPoint().y,bb.getMinPoint().z);
118+ GL.glVertex3f(bb.getMaxPoint().x,bb.getMinPoint().y,bb.getMaxPoint().z);
119+
120+ GL.glEnd();
121+
122+ font.print(1, 30,"Box - " + bb.getCenter(), 0);
123+ font.print(1, 15, "min " + bb.getMinPoint(), 0);
124+ font.print(1, 1, "max " + bb.getMaxPoint(), 0);
125+
126+
127+ }
128+
129+ /* (non-Javadoc)
130+ * @see jme.AbstractGame#initSystem()
131+ */
132+ protected void initSystem() {
133+ DisplaySystem.createDisplaySystem(
134+ "TestApplication",
135+ "data/Images/Monkey.jpg",
136+ true);
137+ GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
138+
139+ GL.glMatrixMode(GL.GL_PROJECTION);
140+ GL.glLoadIdentity();
141+
142+ // Calculate the aspect ratio
143+ GLU.gluPerspective(
144+ 45.0f,
145+ (float) Display.getWidth() / (float) Display.getHeight(),
146+ 0.01f,
147+ 750.0f);
148+
149+ GL.glMatrixMode(GL.GL_MODELVIEW);
150+ GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
151+ GL.glDepthFunc(GL.GL_LEQUAL);
152+ GL.glEnable(GL.GL_DEPTH_TEST);
153+ GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
154+ }
155+
156+ /* (non-Javadoc)
157+ * @see jme.AbstractGame#initGame()
158+ */
159+ protected void initGame() {
160+ timer = Timer.getTimer();
161+ camera = new Camera(1,0,0,10,0,0,0,0,1,0);
162+ controller = new KeyController(camera);
163+ font = new Font2D("data/Font/font.png");
164+
165+ points = new Vector[100];
166+ for(int i = 0; i < points.length; i++) {
167+ points[i] = new Vector((float)Math.random() * 20 - 10,
168+ (float)Math.random() * 20 - 10,
169+ (float)Math.random() * 20 - 10);
170+ System.out.println(points[i]);
171+ }
172+
173+ bb = new BoundingBox();
174+ bb.axisAligned(points);
175+
176+ }
177+
178+ /* (non-Javadoc)
179+ * @see jme.AbstractGame#reinit()
180+ */
181+ protected void reinit() {
182+ //not needed
183+
184+ }
185+
186+ /* (non-Javadoc)
187+ * @see jme.AbstractGame#cleanup()
188+ */
189+ protected void cleanup() {
190+ Window.destroy();
191+
192+ }
193+
194+ /**
195+ * <code>main</code> entry point for application.
196+ * @param args comman line arguments, none used.
197+ */
198+ public static void main(String[] args) {
199+ TestBoundingBox testApp = new TestBoundingBox();
200+ testApp.start();
201+ }
202+
203+}
--- /dev/null
+++ b/src/test/bounding/TestBoundingCapsule.java
@@ -0,0 +1,169 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
3+ * All rights reserved.
4+ *
5+ * Redistribution and use in source and binary forms, with or without
6+ * modification, are permitted provided that the following conditions are met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+package test.bounding;
33+
34+import org.lwjgl.Display;
35+import org.lwjgl.opengl.GL;
36+import org.lwjgl.opengl.GLU;
37+import org.lwjgl.opengl.Window;
38+
39+import jme.AbstractGame;
40+import jme.entity.camera.Camera;
41+import jme.geometry.bounding.BoundingCapsule;
42+import jme.geometry.hud.text.Font2D;
43+import jme.math.Vector;
44+import jme.system.DisplaySystem;
45+import jme.utility.Timer;
46+
47+/**
48+ * @author Mark Powell
49+ */
50+public class TestBoundingCapsule extends AbstractGame {
51+ private Timer timer;
52+ private Camera camera;
53+ private KeyController controller;
54+ private Vector[] points;
55+ private BoundingCapsule bc;
56+ private Font2D font;
57+
58+ /* (non-Javadoc)
59+ * @see jme.AbstractGame#update()
60+ */
61+ protected void update() {
62+ if(!controller.update(timer.getFrameRate())) {
63+ finish();
64+ }
65+ timer.update();
66+ }
67+
68+ /* (non-Javadoc)
69+ * @see jme.AbstractGame#render()
70+ */
71+ protected void render() {
72+ GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
73+ GL.glLoadIdentity();
74+ controller.render();
75+
76+ GL.glBegin(GL.GL_LINES);
77+ GL.glColor3f(0.0f, 1.0f, 0.0f);
78+ for(int i = 0; i < points.length; i++) {
79+ GL.glVertex3f(points[i].x, points[i].y, points[i].z);
80+ }
81+ GL.glEnd();
82+
83+ GL.glBegin(GL.GL_LINES);
84+ GL.glColor3f(1.0f, 0.0f, 0.0f);
85+ GL.glVertex3f(bc.getOrigin().x, bc.getOrigin().y, bc.getOrigin().z);
86+ GL.glVertex3f(bc.getDirection().x, bc.getDirection().y, bc.getDirection().z);
87+ GL.glEnd();
88+
89+ font.print(1, 30,"Capsule - " + bc.getOrigin(), 0);
90+ font.print(1, 15, " to " + bc.getDirection(),0);
91+ font.print(1, 1, "radius " + bc.getRadius(), 0);
92+
93+
94+ }
95+
96+ /* (non-Javadoc)
97+ * @see jme.AbstractGame#initSystem()
98+ */
99+ protected void initSystem() {
100+ DisplaySystem.createDisplaySystem(
101+ "TestApplication",
102+ "data/Images/Monkey.jpg",
103+ true);
104+ GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
105+
106+ GL.glMatrixMode(GL.GL_PROJECTION);
107+ GL.glLoadIdentity();
108+
109+ // Calculate the aspect ratio
110+ GLU.gluPerspective(
111+ 45.0f,
112+ (float) Display.getWidth() / (float) Display.getHeight(),
113+ 0.01f,
114+ 750.0f);
115+
116+ GL.glMatrixMode(GL.GL_MODELVIEW);
117+ GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
118+ GL.glDepthFunc(GL.GL_LEQUAL);
119+ GL.glEnable(GL.GL_DEPTH_TEST);
120+ GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
121+
122+ }
123+
124+ /* (non-Javadoc)
125+ * @see jme.AbstractGame#initGame()
126+ */
127+ protected void initGame() {
128+ timer = Timer.getTimer();
129+ camera = new Camera(1,0,0,10,0,0,0,0,1,0);
130+ controller = new KeyController(camera);
131+ font = new Font2D("data/Font/font.png");
132+
133+ points = new Vector[100];
134+ for(int i = 0; i < points.length; i++) {
135+ points[i] = new Vector((float)Math.random() * 20 - 10,
136+ (float)Math.random() * 40 - 10,
137+ (float)Math.random() * 20 - 10);
138+ }
139+
140+ bc = new BoundingCapsule();
141+ bc.leastSquaresFit(points);
142+ }
143+
144+ /* (non-Javadoc)
145+ * @see jme.AbstractGame#reinit()
146+ */
147+ protected void reinit() {
148+ //not needed
149+
150+ }
151+
152+ /* (non-Javadoc)
153+ * @see jme.AbstractGame#cleanup()
154+ */
155+ protected void cleanup() {
156+ Window.destroy();
157+
158+ }
159+
160+ /**
161+ * <code>main</code> entry point for application.
162+ * @param args comman line arguments, none used.
163+ */
164+ public static void main(String[] args) {
165+ TestBoundingCapsule testApp = new TestBoundingCapsule();
166+ testApp.start();
167+ }
168+
169+}
--- /dev/null
+++ b/src/test/bounding/TestBoundingCylinder.java
@@ -0,0 +1,171 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
3+ * All rights reserved.
4+ *
5+ * Redistribution and use in source and binary forms, with or without
6+ * modification, are permitted provided that the following conditions are met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+package test.bounding;
33+
34+import org.lwjgl.Display;
35+import org.lwjgl.opengl.GL;
36+import org.lwjgl.opengl.GLU;
37+import org.lwjgl.opengl.Window;
38+
39+import jme.AbstractGame;
40+import jme.entity.camera.Camera;
41+import jme.geometry.bounding.BoundingCylinder;
42+import jme.geometry.hud.text.Font2D;
43+import jme.math.Vector;
44+import jme.system.DisplaySystem;
45+import jme.utility.Timer;
46+
47+/**
48+ * @author Mark Powell
49+ */
50+public class TestBoundingCylinder extends AbstractGame {
51+ private Timer timer;
52+ private Camera camera;
53+ private KeyController controller;
54+ private Vector[] points;
55+ private BoundingCylinder bc;
56+ private Font2D font;
57+
58+ /* (non-Javadoc)
59+ * @see jme.AbstractGame#update()
60+ */
61+ protected void update() {
62+ if(!controller.update(timer.getFrameRate())) {
63+ finish();
64+ }
65+ timer.update();
66+ }
67+
68+ /* (non-Javadoc)
69+ * @see jme.AbstractGame#render()
70+ */
71+ protected void render() {
72+ GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
73+ GL.glLoadIdentity();
74+ controller.render();
75+
76+ GL.glBegin(GL.GL_LINES);
77+ GL.glColor3f(0.0f, 1.0f, 0.0f);
78+ for(int i = 0; i < points.length; i++) {
79+ GL.glVertex3f(points[i].x, points[i].y, points[i].z);
80+ }
81+ GL.glEnd();
82+
83+ GL.glBegin(GL.GL_LINES);
84+ GL.glColor3f(1.0f, 0.0f, 0.0f);
85+ GL.glVertex3f(bc.getCenter().x, bc.getCenter().y, bc.getCenter().z);
86+ GL.glVertex3f(bc.getDirection().x, bc.getDirection().y, bc.getDirection().z);
87+ GL.glEnd();
88+
89+ font.print(1, 45, "Height - " + bc.getHeight(), 0);
90+ font.print(1, 30,"Capsule - " + bc.getCenter(), 0);
91+ font.print(1, 15, " to " + bc.getDirection(),0);
92+ font.print(1, 1, "radius " + bc.getRadius(), 0);
93+
94+
95+ }
96+
97+ /* (non-Javadoc)
98+ * @see jme.AbstractGame#initSystem()
99+ */
100+ protected void initSystem() {
101+ DisplaySystem.createDisplaySystem(
102+ "TestApplication",
103+ "data/Images/Monkey.jpg",
104+ true);
105+ GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
106+
107+ GL.glMatrixMode(GL.GL_PROJECTION);
108+ GL.glLoadIdentity();
109+
110+ // Calculate the aspect ratio
111+ GLU.gluPerspective(
112+ 45.0f,
113+ (float) Display.getWidth() / (float) Display.getHeight(),
114+ 0.01f,
115+ 750.0f);
116+
117+ GL.glMatrixMode(GL.GL_MODELVIEW);
118+ GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
119+ GL.glDepthFunc(GL.GL_LEQUAL);
120+ GL.glEnable(GL.GL_DEPTH_TEST);
121+ GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
122+
123+ }
124+
125+ /* (non-Javadoc)
126+ * @see jme.AbstractGame#initGame()
127+ */
128+ protected void initGame() {
129+ timer = Timer.getTimer();
130+ camera = new Camera(1,0,0,10,0,0,0,0,1,0);
131+ controller = new KeyController(camera);
132+ font = new Font2D("data/Font/font.png");
133+
134+ points = new Vector[100];
135+ for(int i = 0; i < points.length; i++) {
136+ points[i] = new Vector((float)Math.random() * 20 - 10,
137+ (float)Math.random() * 40 - 10,
138+ (float)Math.random() * 20 - 10);
139+ }
140+
141+ bc = new BoundingCylinder();
142+ bc.leastSquaresFit(points);
143+ }
144+
145+ /* (non-Javadoc)
146+ * @see jme.AbstractGame#reinit()
147+ */
148+ protected void reinit() {
149+ //not needed
150+
151+ }
152+
153+ /* (non-Javadoc)
154+ * @see jme.AbstractGame#cleanup()
155+ */
156+ protected void cleanup() {
157+ Window.destroy();
158+
159+ }
160+
161+ /**
162+ * <code>main</code> entry point for application.
163+ * @param args comman line arguments, none used.
164+ */
165+ public static void main(String[] args) {
166+ TestBoundingCylinder testApp = new TestBoundingCylinder();
167+ testApp.start();
168+ }
169+
170+}
171+
--- /dev/null
+++ b/src/test/bounding/TestBoundingEllipsoid.java
@@ -0,0 +1,168 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
3+ * All rights reserved.
4+ *
5+ * Redistribution and use in source and binary forms, with or without
6+ * modification, are permitted provided that the following conditions are met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+package test.bounding;
33+
34+import org.lwjgl.Display;
35+import org.lwjgl.opengl.GL;
36+import org.lwjgl.opengl.GLU;
37+import org.lwjgl.opengl.Window;
38+
39+import jme.AbstractGame;
40+import jme.entity.camera.Camera;
41+import jme.geometry.bounding.BoundingEllipsoid;
42+import jme.geometry.hud.text.Font2D;
43+import jme.math.Vector;
44+import jme.system.DisplaySystem;
45+import jme.utility.Timer;
46+
47+/**
48+ * @author Mark Powell
49+ */
50+public class TestBoundingEllipsoid extends AbstractGame {
51+ private Timer timer;
52+ private Camera camera;
53+ private KeyController controller;
54+ private Vector[] points;
55+ private BoundingEllipsoid be;
56+ private Font2D font;
57+
58+ /* (non-Javadoc)
59+ * @see jme.AbstractGame#update()
60+ */
61+ protected void update() {
62+ if(!controller.update(timer.getFrameRate())) {
63+ finish();
64+ }
65+ timer.update();
66+ }
67+
68+ /* (non-Javadoc)
69+ * @see jme.AbstractGame#render()
70+ */
71+ protected void render() {
72+ GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
73+ GL.glLoadIdentity();
74+ controller.render();
75+
76+ GL.glBegin(GL.GL_LINES);
77+ GL.glColor3f(0.0f, 1.0f, 0.0f);
78+ for(int i = 0; i < points.length; i++) {
79+ GL.glVertex3f(points[i].x, points[i].y, points[i].z);
80+ }
81+ GL.glEnd();
82+
83+ GL.glBegin(GL.GL_POINTS);
84+ GL.glColor3f(1.0f, 0.0f, 0.0f);
85+ GL.glVertex3f(be.getCenter().x, be.getCenter().y, be.getCenter().z);
86+ GL.glEnd();
87+
88+
89+ font.print(1, 30,"Ellipsoid - " + be.getCenter(), 0);
90+
91+
92+ }
93+
94+ /* (non-Javadoc)
95+ * @see jme.AbstractGame#initSystem()
96+ */
97+ protected void initSystem() {
98+ DisplaySystem.createDisplaySystem(
99+ "TestApplication",
100+ "data/Images/Monkey.jpg",
101+ true);
102+ GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
103+
104+ GL.glMatrixMode(GL.GL_PROJECTION);
105+ GL.glLoadIdentity();
106+
107+ // Calculate the aspect ratio
108+ GLU.gluPerspective(
109+ 45.0f,
110+ (float) Display.getWidth() / (float) Display.getHeight(),
111+ 0.01f,
112+ 750.0f);
113+
114+ GL.glMatrixMode(GL.GL_MODELVIEW);
115+ GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
116+ GL.glDepthFunc(GL.GL_LEQUAL);
117+ GL.glEnable(GL.GL_DEPTH_TEST);
118+ GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
119+
120+ }
121+
122+ /* (non-Javadoc)
123+ * @see jme.AbstractGame#initGame()
124+ */
125+ protected void initGame() {
126+ timer = Timer.getTimer();
127+ camera = new Camera(1,0,0,10,0,0,0,0,1,0);
128+ controller = new KeyController(camera);
129+ font = new Font2D("data/Font/font.png");
130+
131+ points = new Vector[100];
132+ for(int i = 0; i < points.length; i++) {
133+ points[i] = new Vector((float)Math.random() * 20 - 10,
134+ (float)Math.random() * 40 - 10,
135+ (float)Math.random() * 20 - 10);
136+ }
137+
138+ be = new BoundingEllipsoid();
139+ be.gaussianDistribution(points);
140+
141+ }
142+
143+ /* (non-Javadoc)
144+ * @see jme.AbstractGame#reinit()
145+ */
146+ protected void reinit() {
147+ //not needed
148+
149+ }
150+
151+ /* (non-Javadoc)
152+ * @see jme.AbstractGame#cleanup()
153+ */
154+ protected void cleanup() {
155+ Window.destroy();
156+
157+ }
158+
159+ /**
160+ * <code>main</code> entry point for application.
161+ * @param args comman line arguments, none used.
162+ */
163+ public static void main(String[] args) {
164+ TestBoundingEllipsoid testApp = new TestBoundingEllipsoid();
165+ testApp.start();
166+ }
167+
168+}
--- /dev/null
+++ b/src/test/bounding/TestBoundingLozenge.java
@@ -0,0 +1,174 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
3+ * All rights reserved.
4+ *
5+ * Redistribution and use in source and binary forms, with or without
6+ * modification, are permitted provided that the following conditions are met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+package test.bounding;
33+
34+import org.lwjgl.Display;
35+import org.lwjgl.opengl.GL;
36+import org.lwjgl.opengl.GLU;
37+import org.lwjgl.opengl.Window;
38+
39+import jme.AbstractGame;
40+import jme.entity.camera.Camera;
41+import jme.geometry.bounding.BoundingLozenge;
42+import jme.geometry.hud.text.Font2D;
43+import jme.math.Vector;
44+import jme.system.DisplaySystem;
45+import jme.utility.Timer;
46+
47+/**
48+ * @author Mark Powell
49+ */
50+public class TestBoundingLozenge extends AbstractGame {
51+ private Timer timer;
52+ private Camera camera;
53+ private KeyController controller;
54+ private Vector[] points;
55+ private BoundingLozenge bl;
56+ private Font2D font;
57+
58+ /* (non-Javadoc)
59+ * @see jme.AbstractGame#update()
60+ */
61+ protected void update() {
62+ if(!controller.update(timer.getFrameRate())) {
63+ finish();
64+ }
65+ timer.update();
66+ }
67+
68+ /* (non-Javadoc)
69+ * @see jme.AbstractGame#render()
70+ */
71+ protected void render() {
72+ GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
73+ GL.glLoadIdentity();
74+ controller.render();
75+
76+ GL.glBegin(GL.GL_LINES);
77+ GL.glColor3f(0.0f, 1.0f, 0.0f);
78+ for(int i = 0; i < points.length; i++) {
79+ GL.glVertex3f(points[i].x, points[i].y, points[i].z);
80+ }
81+ GL.glEnd();
82+
83+ GL.glBegin(GL.GL_LINES);
84+ GL.glColor3f(1.0f, 0.0f, 0.0f);
85+ GL.glVertex3f(bl.getRectangle().getOrigin().x,bl.getRectangle().getOrigin().y,bl.getRectangle().getOrigin().z);
86+ GL.glVertex3f(bl.getRectangle().getFirstEdge().x,bl.getRectangle().getFirstEdge().y,bl.getRectangle().getFirstEdge().z);
87+ GL.glVertex3f(bl.getRectangle().getOrigin().x,bl.getRectangle().getOrigin().y,bl.getRectangle().getOrigin().z);
88+ GL.glVertex3f(bl.getRectangle().getSecondEdge().x,bl.getRectangle().getSecondEdge().y,bl.getRectangle().getSecondEdge().z);
89+
90+ GL.glEnd();
91+
92+ font.print(1, 45,"Lozenge - " + bl.getRadius(), 0);
93+ font.print(1, 30, "Origin - " + bl.getRectangle().getOrigin(),0);
94+ font.print(1, 15, "first edge - " + bl.getRectangle().getFirstEdge(),0);
95+ font.print(1, 1, "second edge - " + bl.getRectangle().getSecondEdge(),0);
96+
97+
98+ }
99+
100+ /* (non-Javadoc)
101+ * @see jme.AbstractGame#initSystem()
102+ */
103+ protected void initSystem() {
104+ DisplaySystem.createDisplaySystem(
105+ "TestApplication",
106+ "data/Images/Monkey.jpg",
107+ true);
108+ GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
109+
110+ GL.glMatrixMode(GL.GL_PROJECTION);
111+ GL.glLoadIdentity();
112+
113+ // Calculate the aspect ratio
114+ GLU.gluPerspective(
115+ 45.0f,
116+ (float) Display.getWidth() / (float) Display.getHeight(),
117+ 0.01f,
118+ 750.0f);
119+
120+ GL.glMatrixMode(GL.GL_MODELVIEW);
121+ GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
122+ GL.glDepthFunc(GL.GL_LEQUAL);
123+ GL.glEnable(GL.GL_DEPTH_TEST);
124+ GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
125+
126+ }
127+
128+ /* (non-Javadoc)
129+ * @see jme.AbstractGame#initGame()
130+ */
131+ protected void initGame() {
132+ timer = Timer.getTimer();
133+ camera = new Camera(1,0,0,10,0,0,0,0,1,0);
134+ controller = new KeyController(camera);
135+ font = new Font2D("data/Font/font.png");
136+
137+ points = new Vector[100];
138+ for(int i = 0; i < points.length; i++) {
139+ points[i] = new Vector((float)Math.random() * 20 - 10,
140+ (float)Math.random() * 40 - 10,
141+ (float)Math.random() * 20 - 10);
142+ }
143+
144+ bl = new BoundingLozenge();
145+ bl.gaussianDistribution(points);
146+
147+ }
148+
149+ /* (non-Javadoc)
150+ * @see jme.AbstractGame#reinit()
151+ */
152+ protected void reinit() {
153+ //not needed
154+
155+ }
156+
157+ /* (non-Javadoc)
158+ * @see jme.AbstractGame#cleanup()
159+ */
160+ protected void cleanup() {
161+ Window.destroy();
162+
163+ }
164+
165+ /**
166+ * <code>main</code> entry point for application.
167+ * @param args comman line arguments, none used.
168+ */
169+ public static void main(String[] args) {
170+ TestBoundingLozenge testApp = new TestBoundingLozenge();
171+ testApp.start();
172+ }
173+
174+}
--- /dev/null
+++ b/src/test/bounding/TestBoundingSphere.java
@@ -0,0 +1,205 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
3+ * All rights reserved.
4+ *
5+ * Redistribution and use in source and binary forms, with or without
6+ * modification, are permitted provided that the following conditions are met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+package test.bounding;
33+
34+import org.lwjgl.Display;
35+import org.lwjgl.input.Keyboard;
36+import org.lwjgl.opengl.GL;
37+import org.lwjgl.opengl.GLU;
38+import org.lwjgl.opengl.Window;
39+
40+import jme.AbstractGame;
41+import jme.entity.camera.Camera;
42+import jme.geometry.bounding.BoundingSphere;
43+import jme.geometry.hud.text.Font2D;
44+import jme.math.Vector;
45+import jme.system.DisplaySystem;
46+import jme.system.KeyBindingManager;
47+import jme.utility.Timer;
48+
49+/**
50+ * @author Mark Powell
51+ */
52+public class TestBoundingSphere extends AbstractGame {
53+ private Timer timer;
54+ private Camera camera;
55+ private KeyController controller;
56+ private Vector[] points;
57+ private BoundingSphere bs;
58+ private Font2D font;
59+ private String type;
60+
61+ /* (non-Javadoc)
62+ * @see jme.AbstractGame#update()
63+ */
64+ protected void update() {
65+ if(!controller.update(timer.getFrameRate())) {
66+ finish();
67+ }
68+ timer.update();
69+
70+
71+ if(KeyBindingManager.getKeyBindingManager().isValidCommand(
72+ "average")) {
73+ bs.averagePoints(points);
74+ type = "Average Points";
75+ }
76+
77+ if(KeyBindingManager.getKeyBindingManager().isValidCommand(
78+ "axisAligned")) {
79+ bs.containAABB(points);
80+ type = "Axis Aligned";
81+ }
82+
83+ }
84+
85+ /* (non-Javadoc)
86+ * @see jme.AbstractGame#render()
87+ */
88+ protected void render() {
89+ GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
90+ GL.glLoadIdentity();
91+ controller.render();
92+
93+ GL.glBegin(GL.GL_LINES);
94+ GL.glColor3f(0.0f, 1.0f, 0.0f);
95+ for(int i = 0; i < points.length; i++) {
96+ GL.glVertex3f(points[i].x, points[i].y, points[i].z);
97+ }
98+
99+ GL.glEnd();
100+
101+ GL.glBegin(GL.GL_LINES);
102+ GL.glColor3f(1.0f,0.0f,0.0f);
103+ GL.glVertex3f(bs.getCenter().x, bs.getCenter().y, bs.getCenter().z);
104+ GL.glVertex3f(bs.getCenter().x + bs.getRadius(), bs.getCenter().y, bs.getCenter().z);
105+ GL.glVertex3f(bs.getCenter().x, bs.getCenter().y, bs.getCenter().z);
106+ GL.glVertex3f(bs.getCenter().x, bs.getCenter().y + bs.getRadius(), bs.getCenter().z);
107+ GL.glVertex3f(bs.getCenter().x, bs.getCenter().y, bs.getCenter().z);
108+ GL.glVertex3f(bs.getCenter().x, bs.getCenter().y, bs.getCenter().z+bs.getRadius());
109+ GL.glVertex3f(bs.getCenter().x, bs.getCenter().y, bs.getCenter().z);
110+ GL.glVertex3f(bs.getCenter().x-bs.getRadius(), bs.getCenter().y, bs.getCenter().z);
111+ GL.glVertex3f(bs.getCenter().x, bs.getCenter().y, bs.getCenter().z);
112+ GL.glVertex3f(bs.getCenter().x, bs.getCenter().y-bs.getRadius(), bs.getCenter().z);
113+ GL.glVertex3f(bs.getCenter().x, bs.getCenter().y, bs.getCenter().z);
114+ GL.glVertex3f(bs.getCenter().x, bs.getCenter().y, bs.getCenter().z-bs.getRadius());
115+
116+
117+ GL.glEnd();
118+
119+
120+
121+ font.print(1, 30,"Sphere - " + bs.getCenter(), 0);
122+ font.print(1, 15, "radius " + bs.getRadius(), 0);
123+ font.print(1,1, "TYPE " + type, 0);
124+
125+
126+ }
127+
128+ /* (non-Javadoc)
129+ * @see jme.AbstractGame#initSystem()
130+ */
131+ protected void initSystem() {
132+ DisplaySystem.createDisplaySystem(
133+ "TestApplication",
134+ "data/Images/Monkey.jpg",
135+ true);
136+ GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
137+
138+ GL.glMatrixMode(GL.GL_PROJECTION);
139+ GL.glLoadIdentity();
140+
141+ // Calculate the aspect ratio
142+ GLU.gluPerspective(
143+ 45.0f,
144+ (float) Display.getWidth() / (float) Display.getHeight(),
145+ 0.01f,
146+ 750.0f);
147+
148+ GL.glMatrixMode(GL.GL_MODELVIEW);
149+ GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
150+ GL.glDepthFunc(GL.GL_LEQUAL);
151+ GL.glEnable(GL.GL_DEPTH_TEST);
152+ GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
153+
154+ }
155+
156+ /* (non-Javadoc)
157+ * @see jme.AbstractGame#initGame()
158+ */
159+ protected void initGame() {
160+ timer = Timer.getTimer();
161+ camera = new Camera(1,0,0,10,0,0,0,0,1,0);
162+ controller = new KeyController(camera);
163+ font = new Font2D("data/Font/font.png");
164+
165+ points = new Vector[100];
166+ for(int i = 0; i < points.length; i++) {
167+ points[i] = new Vector((float)Math.random() * 20 - 10,
168+ (float)Math.random() * 20 - 10,
169+ (float)Math.random() * 20 - 10);
170+ }
171+
172+ KeyBindingManager.getKeyBindingManager().set("axisAligned", Keyboard.KEY_1);
173+ KeyBindingManager.getKeyBindingManager().set("average", Keyboard.KEY_2);
174+
175+ bs = new BoundingSphere();
176+ bs.containAABB(points);
177+ type = "Axis Aligned";
178+ }
179+
180+ /* (non-Javadoc)
181+ * @see jme.AbstractGame#reinit()
182+ */
183+ protected void reinit() {
184+ //not needed
185+
186+ }
187+
188+ /* (non-Javadoc)
189+ * @see jme.AbstractGame#cleanup()
190+ */
191+ protected void cleanup() {
192+ Window.destroy();
193+
194+ }
195+
196+ /**
197+ * <code>main</code> entry point for application.
198+ * @param args comman line arguments, none used.
199+ */
200+ public static void main(String[] args) {
201+ TestBoundingSphere testApp = new TestBoundingSphere();
202+ testApp.start();
203+ }
204+
205+}
--- a/src/test/general/TestMain.java
+++ b/src/test/general/TestMain.java
@@ -47,6 +47,7 @@ import jme.AbstractGame;
4747 import jme.entity.Entity;
4848 import jme.geometry.model.md3.Md3Model;
4949 import jme.geometry.primitive.Pyramid;
50+import jme.geometry.bounding.BoundingSphere;
5051 import jme.geometry.hud.SplashScreen;
5152 import jme.geometry.hud.text.Font2D;
5253 import jme.lighting.SlopeLighting;
@@ -81,10 +82,12 @@ public class TestMain extends AbstractGame {
8182 private Font2D font = null;
8283 private Pyramid object;
8384 Entity e;
85+ Entity[] elist;
8486 private TestController cc = null;
8587 protected Logger log = null;
8688 private Timer timer;
8789 SplashScreen ss;
90+ boolean collision = false;
8891
8992 static {
9093 if (GLCaps.WGL_EXT_swap_control) {
@@ -155,6 +158,8 @@ public class TestMain extends AbstractGame {
155158 + 8;
156159
157160 }
161+
162+
158163
159164 // update animation....
160165 if (physics.getCurrentVelocity() < -1 && currentAnimation != 4) {
@@ -217,6 +222,7 @@ public class TestMain extends AbstractGame {
217222 + " / "
218223 + world.getTotalEntities(),
219224 0);
225+
220226
221227 }
222228 private void initLogger() {
@@ -345,16 +351,18 @@ public class TestMain extends AbstractGame {
345351 new Md3Model("data/model/Paladin", "Paladin", "railgun");
346352 msmodel.setTorsoAnimation("TORSO_STAND");
347353 msmodel.setLegsAnimation("LEGS_IDLE");
348-
354+ BoundingSphere ebs = new BoundingSphere();
355+ ebs.averagePoints(msmodel.getPoints());
356+
349357 msmodel.setScale(new Vector(0.15f, 0.15f, 0.15f));
350358
351359 e.setGeometry(msmodel);
360+ e.setBoundingVolume(ebs);
352361 e.setPosition(
353362 new Vector(
354- 1000,
355- hm1.getScaledHeightAtPoint(1000 / 4, 1000 / 4),
356- 1000));
357- e.setVisibilityType(Entity.VISIBILITY_SPHERE);
363+ 400,
364+ hm1.getScaledHeightAtPoint(400 / 4, 400 / 4),
365+ 400));
358366 camera.setView(e.getPosition());
359367
360368 //Move to app specific
@@ -384,18 +392,19 @@ public class TestMain extends AbstractGame {
384392 object.setColor(0.5f, 0.85f, 0.5f, 0.5f);
385393 object.setTexture("data/texture/plants15.jpg");
386394 object.useDisplayList(true);
395+ BoundingSphere bs = new BoundingSphere();
396+ bs.averagePoints(object.getPoints());
387397
388398 //object = new MilkshapeModel("data/tree.ms3d");
389399
390- Entity[] elist = new Entity[1000];
400+ elist = new Entity[1];
391401 float x, z;
392- for (int i = 0; i < 1000; i++) {
402+ for (int i = 0; i < 1; i++) {
393403 elist[i] = new Entity(i + 1);
394404 elist[i].setGeometry(object);
395- elist[i].setVisibilityType(Entity.VISIBILITY_POINT);
396405 do {
397- x = (float) Math.random() * 2000;
398- z = (float) Math.random() * 2000;
406+ x = 500;
407+ z = 500;
399408 } while (
400409 hm1.getInterpolatedHeight(x / 2, z / 2) < 75
401410 || hm1.getInterpolatedHeight(x / 4, z / 4) > 200);
@@ -404,8 +413,8 @@ public class TestMain extends AbstractGame {
404413 x,
405414 hm1.getInterpolatedHeight(x / 4, z / 4) + 1,
406415 z));
416+ elist[i].setBoundingVolume(bs);
407417 world.addEntity(elist[i]);
408- elist[i].setVisibilityType(Entity.VISIBILITY_SPHERE);
409418 }
410419 cc = new TestController(camera, e, this);
411420 cc.setTrackingDistance(30f);
--- a/src/test/keycontroller/TestKeyController.java
+++ b/src/test/keycontroller/TestKeyController.java
@@ -195,7 +195,6 @@ public class TestKeyController extends AbstractGame {
195195
196196 // initialize the pyramid entity
197197 entity1 = new Entity(entity_1);
198- entity1.setVisibilityType(Entity.VISIBILITY_CUBE);
199198 entity1.setPosition(new Vector(0.0f, 0.0f, 0.0f));
200199 entity1.setGeometry(triangle);
201200 }