Main repository of MikuMikuStudio
Revision | 311625528413f17188511c08118346c421de6a29 (tree) |
---|---|
Time | 2003-09-11 05:32:59 |
Author | mojomonkey <mojomonkey@75d0...> |
Commiter | mojomonkey |
Testing bounding volumes, all now pass checks.
git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@88 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
@@ -65,22 +65,10 @@ import org.lwjgl.opengl.Window; | ||
65 | 65 | * <code>Entity</code> to represent something abstract. |
66 | 66 | * |
67 | 67 | * @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 $ | |
69 | 69 | */ |
70 | 70 | 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 | + | |
84 | 72 | //The id of the entity |
85 | 73 | private int id = 0; |
86 | 74 |
@@ -105,8 +93,7 @@ public class Entity implements EntityInterface { | ||
105 | 93 | //visibility |
106 | 94 | private boolean hasMoved; |
107 | 95 | private boolean isVisible = true; |
108 | - private int visibilityType; | |
109 | - | |
96 | + | |
110 | 97 | //physics |
111 | 98 | private PhysicsModule physics; |
112 | 99 |
@@ -202,7 +189,8 @@ public class Entity implements EntityInterface { | ||
202 | 189 | */ |
203 | 190 | public boolean hasCollision(Entity ent) { |
204 | 191 | if(null != boundingVolume) { |
205 | - return boundingVolume.hasCollision(ent.getBoundingVolume()); | |
192 | + return boundingVolume.hasCollision(position, | |
193 | + ent.getBoundingVolume(), ent.getPosition()); | |
206 | 194 | } else { |
207 | 195 | return false; |
208 | 196 | } |
@@ -217,7 +205,8 @@ public class Entity implements EntityInterface { | ||
217 | 205 | */ |
218 | 206 | public float distance(Entity ent) { |
219 | 207 | if(null != boundingVolume) { |
220 | - return boundingVolume.distance(ent.getBoundingVolume()); | |
208 | + return boundingVolume.distance(position, ent.getBoundingVolume(), | |
209 | + ent.getPosition()); | |
221 | 210 | } else { |
222 | 211 | return -1.0f; |
223 | 212 | } |
@@ -377,30 +366,13 @@ public class Entity implements EntityInterface { | ||
377 | 366 | */ |
378 | 367 | public void checkVisibility(Frustum frustum) { |
379 | 368 | if(null != boundingVolume) { |
380 | - isVisible = boundingVolume.isVisible(frustum); | |
369 | + isVisible = boundingVolume.isVisible(position, frustum); | |
381 | 370 | } else { |
382 | 371 | isVisible = true; |
383 | 372 | } |
384 | 373 | } |
385 | 374 | |
386 | 375 | /** |
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 | - /** | |
404 | 376 | * <code>toString</code> creates a string representation of the |
405 | 377 | * <code>Entity</code> object. The format is as follows:<br><br> |
406 | 378 | * |
@@ -40,12 +40,13 @@ import jme.math.Vector; | ||
40 | 40 | * all vertices that make up the geometry. |
41 | 41 | * |
42 | 42 | * @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 $ | |
44 | 44 | */ |
45 | 45 | public class BoundingBox implements BoundingVolume { |
46 | 46 | private Vector center; |
47 | 47 | private Vector minPoint; |
48 | 48 | private Vector maxPoint; |
49 | + private float collisionBuffer; | |
49 | 50 | |
50 | 51 | /** |
51 | 52 | * Default constructor instantiates a new <code>BoundingBox</code> |
@@ -93,8 +94,12 @@ public class BoundingBox implements BoundingVolume { | ||
93 | 94 | * @param points the list of points to contain. |
94 | 95 | */ |
95 | 96 | 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; | |
98 | 103 | |
99 | 104 | for (int i = 1; i < points.length; i++) { |
100 | 105 | if (points[i].x < minPoint.x) |
@@ -112,6 +117,10 @@ public class BoundingBox implements BoundingVolume { | ||
112 | 117 | else if (points[i].z > maxPoint.z) |
113 | 118 | maxPoint.z = points[i].z; |
114 | 119 | } |
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; | |
115 | 124 | } |
116 | 125 | |
117 | 126 | /** |
@@ -166,15 +175,36 @@ public class BoundingBox implements BoundingVolume { | ||
166 | 175 | this.maxPoint = maxPoint; |
167 | 176 | } |
168 | 177 | |
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) { | |
170 | 190 | return false; |
171 | 191 | } |
172 | 192 | |
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) { | |
174 | 204 | return -1.0f; |
175 | 205 | } |
176 | 206 | |
177 | - public boolean isVisible(Frustum frustum) { | |
207 | + public boolean isVisible(Vector offsetPosition, Frustum frustum) { | |
178 | 208 | return true; |
179 | 209 | } |
180 | 210 |
@@ -43,11 +43,12 @@ import jme.math.Vector; | ||
43 | 43 | * thought of as a cylinder with domed caps. |
44 | 44 | * |
45 | 45 | * @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 $ | |
47 | 47 | */ |
48 | 48 | public class BoundingCapsule implements BoundingVolume { |
49 | 49 | private Line lineSegment; |
50 | 50 | private float radius; |
51 | + private float collisionBuffer; | |
51 | 52 | |
52 | 53 | /** |
53 | 54 | * Default constructor instantiates an empty bounding capsule. Both the |
@@ -105,8 +106,7 @@ public class BoundingCapsule implements BoundingVolume { | ||
105 | 106 | * @param points the points to contain. |
106 | 107 | */ |
107 | 108 | public void leastSquaresFit(Vector[] points) { |
108 | - | |
109 | - Line line = Approximation.orthogonalLineFit(points); | |
109 | + Line line = Approximation.orthogonalLineFit(points); | |
110 | 110 | |
111 | 111 | float maxRadiusSqr = 0.0f; |
112 | 112 |
@@ -154,17 +154,38 @@ public class BoundingCapsule implements BoundingVolume { | ||
154 | 154 | } |
155 | 155 | |
156 | 156 | radius = (float) Math.sqrt(maxRadiusSqr); |
157 | - } | |
157 | + } | |
158 | 158 | |
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) { | |
160 | 171 | return false; |
161 | 172 | } |
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 | + } | |
162 | 182 | |
163 | - public float distance(BoundingVolume volume) { | |
183 | + public float distance(Vector sourceOffset, BoundingVolume volume, | |
184 | + Vector targetOffset) { | |
164 | 185 | return -1.0f; |
165 | 186 | } |
166 | 187 | |
167 | - public boolean isVisible(Frustum frustum) { | |
188 | + public boolean isVisible(Vector offsetPosition, Frustum frustum) { | |
168 | 189 | return true; |
169 | 190 | } |
170 | 191 | } |
@@ -44,7 +44,7 @@ import jme.math.Vector; | ||
44 | 44 | * also defined by the equation Xi = P + RYi where R = [U V D], and U V causes |
45 | 45 | * R to be orthonormal. |
46 | 46 | * @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 $ | |
48 | 48 | */ |
49 | 49 | public class BoundingCylinder implements BoundingVolume { |
50 | 50 | private Vector center; //P |
@@ -53,6 +53,63 @@ public class BoundingCylinder implements BoundingVolume { | ||
53 | 53 | private Vector v; |
54 | 54 | private float height; |
55 | 55 | 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 | + } | |
56 | 113 | |
57 | 114 | /** |
58 | 115 | * Constructor instantiates a new <code>BoundingCylinder</code> with |
@@ -143,15 +200,36 @@ public class BoundingCylinder implements BoundingVolume { | ||
143 | 200 | |
144 | 201 | } |
145 | 202 | |
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) { | |
147 | 224 | return false; |
148 | 225 | } |
149 | 226 | |
150 | - public float distance(BoundingVolume volume) { | |
227 | + public float distance(Vector sourceOffset, BoundingVolume volume, | |
228 | + Vector targetOffset) { | |
151 | 229 | return -1.0f; |
152 | 230 | } |
153 | 231 | |
154 | - public boolean isVisible(Frustum frustum) { | |
232 | + public boolean isVisible(Vector offsetPosition, Frustum frustum) { | |
155 | 233 | return true; |
156 | 234 | } |
157 | 235 |
@@ -41,13 +41,42 @@ import jme.math.Vector; | ||
41 | 41 | * with a center of (0, 0, 0). The ellipsoid can also be expressed as the |
42 | 42 | * center matrix form (and will be in this class) as: (X-C)^T A (X-C) = 1. |
43 | 43 | * @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 $ | |
45 | 45 | * |
46 | 46 | */ |
47 | 47 | public class BoundingEllipsoid implements BoundingVolume { |
48 | 48 | private Vector center; |
49 | 49 | private Matrix a; |
50 | 50 | 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 | + } | |
51 | 80 | |
52 | 81 | /** |
53 | 82 | * Constructor instantiates a new <code>BoundingEllipsoid</code> with default |
@@ -81,9 +110,11 @@ public class BoundingEllipsoid implements BoundingVolume { | ||
81 | 110 | */ |
82 | 111 | public void gaussianDistribution(Vector[] points) { |
83 | 112 | Vector[] axis = new Vector[3]; |
113 | + for(int i = 0; i < 3; i++) { | |
114 | + axis[i] = new Vector(); | |
115 | + } | |
84 | 116 | float[] d = new float[3]; |
85 | 117 | Approximation.gaussPointsFit(points, center, axis, d); |
86 | - | |
87 | 118 | float maxValue = 0.0f; |
88 | 119 | for (int i = 0; i < points.length; i++) { |
89 | 120 | Vector diff = points[i].subtract(center); |
@@ -104,6 +135,9 @@ public class BoundingEllipsoid implements BoundingVolume { | ||
104 | 135 | } |
105 | 136 | |
106 | 137 | Matrix[] tensor = new Matrix[3]; |
138 | + for(int i = 0; i < 3; i++) { | |
139 | + tensor[i] = new Matrix(); | |
140 | + } | |
107 | 141 | tensor[0].tensorProduct(axis[0], axis[0]); |
108 | 142 | tensor[1].tensorProduct(axis[1], axis[1]); |
109 | 143 | tensor[2].tensorProduct(axis[2], axis[2]); |
@@ -118,15 +152,36 @@ public class BoundingEllipsoid implements BoundingVolume { | ||
118 | 152 | |
119 | 153 | } |
120 | 154 | |
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) { | |
122 | 176 | return false; |
123 | 177 | } |
124 | 178 | |
125 | - public float distance(BoundingVolume volume) { | |
179 | + public float distance(Vector sourceOffset, BoundingVolume volume, | |
180 | + Vector targetOffset) { | |
126 | 181 | return -1.0f; |
127 | 182 | } |
128 | 183 | |
129 | - public boolean isVisible(Frustum frustum) { | |
184 | + public boolean isVisible(Vector offsetPosition, Frustum frustum) { | |
130 | 185 | return true; |
131 | 186 | } |
132 | 187 | } |
@@ -43,11 +43,40 @@ import jme.math.Vector; | ||
43 | 43 | * <br><br> |
44 | 44 | * <b>NOTE:</b> See 3D Game Engine Design. David H. Eberly. |
45 | 45 | * @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 $ | |
47 | 47 | */ |
48 | 48 | public class BoundingLozenge implements BoundingVolume { |
49 | 49 | private Rectangle rectangle; |
50 | 50 | 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 | + } | |
51 | 80 | |
52 | 81 | /** |
53 | 82 | * Constructor instantiates a new <code>BoundingLozenge</code> object. |
@@ -69,14 +98,17 @@ public class BoundingLozenge implements BoundingVolume { | ||
69 | 98 | } |
70 | 99 | |
71 | 100 | /** |
72 | - * <code>guassianDistribution</code> calculates the average of the points, | |
101 | + * <code>gaussianDistribution</code> calculates the average of the points, | |
73 | 102 | * and a covariance matrix to determine the rectangle of the lozenge. The |
74 | 103 | * radius is than calculated to best fit all the points. |
75 | 104 | * @param points the list of points to contain. |
76 | 105 | */ |
77 | - public void guassianDistribution(Vector[] points) { | |
106 | + public void gaussianDistribution(Vector[] points) { | |
78 | 107 | Vector center = new Vector(); |
79 | 108 | Vector[] axis = new Vector[3]; |
109 | + for(int i = 0; i < axis.length; i++) { | |
110 | + axis[i] = new Vector(); | |
111 | + } | |
80 | 112 | float[] extent = new float[3]; |
81 | 113 | Approximation.gaussPointsFit(points, center, axis, extent); |
82 | 114 |
@@ -234,15 +266,36 @@ public class BoundingLozenge implements BoundingVolume { | ||
234 | 266 | |
235 | 267 | } |
236 | 268 | |
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) { | |
238 | 290 | return false; |
239 | 291 | } |
240 | 292 | |
241 | - public float distance(BoundingVolume volume) { | |
293 | + public float distance(Vector sourceOffset, BoundingVolume volume, | |
294 | + Vector targetOffset) { | |
242 | 295 | return -1.0f; |
243 | 296 | } |
244 | 297 | |
245 | - public boolean isVisible(Frustum frustum) { | |
298 | + public boolean isVisible(Vector offsetPosition, Frustum frustum) { | |
246 | 299 | return true; |
247 | 300 | } |
248 | 301 | } |
@@ -33,6 +33,7 @@ | ||
33 | 33 | package jme.geometry.bounding; |
34 | 34 | |
35 | 35 | import jme.entity.camera.Frustum; |
36 | +import jme.math.Distance; | |
36 | 37 | import jme.math.Vector; |
37 | 38 | |
38 | 39 | /** |
@@ -46,12 +47,13 @@ import jme.math.Vector; | ||
46 | 47 | * |
47 | 48 | * |
48 | 49 | * @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 $ | |
50 | 51 | */ |
51 | 52 | public class BoundingSphere implements BoundingVolume { |
52 | 53 | private float radius; |
53 | 54 | private Vector center; |
54 | - | |
55 | + private float collisionBuffer; | |
56 | + | |
55 | 57 | /** |
56 | 58 | * Default contstructor instantiates a new <code>BoundingSphere</code> |
57 | 59 | * object. |
@@ -114,8 +116,8 @@ public class BoundingSphere implements BoundingVolume { | ||
114 | 116 | * @param points the list of points. |
115 | 117 | */ |
116 | 118 | 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); | |
119 | 121 | for (int i = 1; i < points.length; i++) { |
120 | 122 | if (points[i].x < min.x) |
121 | 123 | min.x = points[i].x; |
@@ -166,15 +168,83 @@ public class BoundingSphere implements BoundingVolume { | ||
166 | 168 | |
167 | 169 | } |
168 | 170 | |
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 | + } | |
171 | 201 | } |
172 | 202 | |
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 | + } | |
175 | 225 | } |
176 | 226 | |
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 | + } | |
179 | 249 | } |
180 | 250 | } |
@@ -32,15 +32,56 @@ | ||
32 | 32 | package jme.geometry.bounding; |
33 | 33 | |
34 | 34 | import jme.entity.camera.Frustum; |
35 | +import jme.math.Vector; | |
35 | 36 | |
36 | 37 | /** |
37 | 38 | * <code>BoundingVolume</code> defines an interface for dealing with containment |
38 | 39 | * of a collection of points. |
39 | 40 | * @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 $ | |
41 | 42 | */ |
42 | 43 | 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); | |
46 | 87 | } |
@@ -96,7 +96,7 @@ import org.lwjgl.opengl.Window; | ||
96 | 96 | * |
97 | 97 | * |
98 | 98 | * @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 $ | |
100 | 100 | */ |
101 | 101 | public class Md3Model implements Geometry { |
102 | 102 | /** |
@@ -743,6 +743,7 @@ public class Md3Model implements Geometry { | ||
743 | 743 | |
744 | 744 | // Seek to the start of the vertex/face index information, then read it in. |
745 | 745 | buffer.position(meshOffset + meshHeader.vertexStart); |
746 | + Vector temp = new Vector(); | |
746 | 747 | for (i = 0; |
747 | 748 | i < meshHeader.numMeshFrames * meshHeader.numVertices; |
748 | 749 | i++) { |
@@ -751,8 +752,10 @@ public class Md3Model implements Geometry { | ||
751 | 752 | vertices[i].vertex[0] = buffer.getShort(); |
752 | 753 | vertices[i].vertex[1] = buffer.getShort(); |
753 | 754 | 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); | |
756 | 759 | vertices[i].normal[0] = buffer.get(); |
757 | 760 | vertices[i].normal[1] = buffer.get(); |
758 | 761 | } |
@@ -38,7 +38,7 @@ package jme.math; | ||
38 | 38 | * <br><br> |
39 | 39 | * <b>NOTE:</b> See 3D Game Engine Design. David H. Eberly. |
40 | 40 | * @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 $ | |
42 | 42 | * |
43 | 43 | */ |
44 | 44 | public class Approximation { |
@@ -112,21 +112,25 @@ public class Approximation { | ||
112 | 112 | * @param extent storage for the length of the rectangle. |
113 | 113 | */ |
114 | 114 | public static void gaussPointsFit( |
115 | + | |
115 | 116 | Vector[] points, |
116 | 117 | Vector center, |
117 | 118 | Vector[] axis, |
118 | 119 | float[] extent) { |
119 | 120 | |
120 | 121 | // 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; | |
122 | 125 | |
123 | 126 | for (int i = 1; i < points.length; i++) { |
124 | - center = center.add(points[i]); | |
127 | + center.addToThis(points[i]); | |
125 | 128 | } |
126 | 129 | |
130 | + | |
127 | 131 | float inverseQuantity = 1.0f / points.length; |
128 | - center = center.mult(inverseQuantity); | |
129 | - | |
132 | + center.multThis(inverseQuantity); | |
133 | + | |
130 | 134 | // compute covariances of points |
131 | 135 | float sumXX = 0.0f; |
132 | 136 | float sumXY = 0.0f; |
@@ -177,7 +181,7 @@ public class Approximation { | ||
177 | 181 | axis[2].x = eigen.getEigenvector(0, 2); |
178 | 182 | axis[2].y = eigen.getEigenvector(1, 2); |
179 | 183 | axis[2].z = eigen.getEigenvector(2, 2); |
180 | - | |
184 | + | |
181 | 185 | extent[0] = eigen.getRealEigenvalue(0); |
182 | 186 | extent[1] = eigen.getRealEigenvalue(1); |
183 | 187 | extent[2] = eigen.getRealEigenvalue(2); |
@@ -51,7 +51,10 @@ public class Distance { | ||
51 | 51 | * @return the distance between point1 and point2. |
52 | 52 | */ |
53 | 53 | 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; | |
55 | 58 | } |
56 | 59 | |
57 | 60 | /** |
@@ -36,7 +36,7 @@ import jme.exception.MonkeyRuntimeException; | ||
36 | 36 | /** |
37 | 37 | * <code>Vector</code> defines a three dimensional vector of (x,y,z). |
38 | 38 | * @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 $ | |
40 | 40 | */ |
41 | 41 | public class Vector { |
42 | 42 | public float x; |
@@ -48,7 +48,7 @@ public class Vector { | ||
48 | 48 | * (0, 0, 0). |
49 | 49 | */ |
50 | 50 | public Vector() { |
51 | - x = 0; | |
51 | + x = 0; | |
52 | 52 | y = 0; |
53 | 53 | z = 0; |
54 | 54 | } |
@@ -119,6 +119,17 @@ public class Vector { | ||
119 | 119 | public Vector mult(float scalar) { |
120 | 120 | return new Vector(x * scalar, y * scalar, z * scalar); |
121 | 121 | } |
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 | + } | |
122 | 133 | |
123 | 134 | /** |
124 | 135 | * <code>add</code> adds the values of this vector by another |
@@ -130,6 +141,16 @@ public class Vector { | ||
130 | 141 | public Vector add(Vector v) { |
131 | 142 | return new Vector(x + v.x, y + v.y, z + v.z); |
132 | 143 | } |
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 | + } | |
133 | 154 | |
134 | 155 | /** |
135 | 156 | * <code>subtract</code> subtracts the values of this vector by |
@@ -196,6 +217,12 @@ public class Vector { | ||
196 | 217 | return out; |
197 | 218 | } |
198 | 219 | |
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 | + */ | |
199 | 226 | public Vector inverseRotate(Matrix m) { |
200 | 227 | Vector out = new Vector(); |
201 | 228 | out.x = x * m.matrix[0][0] + y * m.matrix[1][0] + z * m.matrix[2][0]; |
@@ -76,10 +76,10 @@ import org.lwjgl.opengl.Window; | ||
76 | 76 | * and create a new system. |
77 | 77 | * |
78 | 78 | * @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 $ | |
80 | 80 | */ |
81 | 81 | public class DisplaySystem { |
82 | - private static String VERSION = "jME version 0.1.0"; | |
82 | + private static String VERSION = "jME version 0.1.1"; | |
83 | 83 | //Singleton reference. |
84 | 84 | private static DisplaySystem instance = null; |
85 | 85 |
@@ -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 |
@@ -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 | +} |
@@ -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 | +} |
@@ -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 | + |
@@ -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 | +} |
@@ -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 | +} |
@@ -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 | +} |
@@ -47,6 +47,7 @@ import jme.AbstractGame; | ||
47 | 47 | import jme.entity.Entity; |
48 | 48 | import jme.geometry.model.md3.Md3Model; |
49 | 49 | import jme.geometry.primitive.Pyramid; |
50 | +import jme.geometry.bounding.BoundingSphere; | |
50 | 51 | import jme.geometry.hud.SplashScreen; |
51 | 52 | import jme.geometry.hud.text.Font2D; |
52 | 53 | import jme.lighting.SlopeLighting; |
@@ -81,10 +82,12 @@ public class TestMain extends AbstractGame { | ||
81 | 82 | private Font2D font = null; |
82 | 83 | private Pyramid object; |
83 | 84 | Entity e; |
85 | + Entity[] elist; | |
84 | 86 | private TestController cc = null; |
85 | 87 | protected Logger log = null; |
86 | 88 | private Timer timer; |
87 | 89 | SplashScreen ss; |
90 | + boolean collision = false; | |
88 | 91 | |
89 | 92 | static { |
90 | 93 | if (GLCaps.WGL_EXT_swap_control) { |
@@ -155,6 +158,8 @@ public class TestMain extends AbstractGame { | ||
155 | 158 | + 8; |
156 | 159 | |
157 | 160 | } |
161 | + | |
162 | + | |
158 | 163 | |
159 | 164 | // update animation.... |
160 | 165 | if (physics.getCurrentVelocity() < -1 && currentAnimation != 4) { |
@@ -217,6 +222,7 @@ public class TestMain extends AbstractGame { | ||
217 | 222 | + " / " |
218 | 223 | + world.getTotalEntities(), |
219 | 224 | 0); |
225 | + | |
220 | 226 | |
221 | 227 | } |
222 | 228 | private void initLogger() { |
@@ -345,16 +351,18 @@ public class TestMain extends AbstractGame { | ||
345 | 351 | new Md3Model("data/model/Paladin", "Paladin", "railgun"); |
346 | 352 | msmodel.setTorsoAnimation("TORSO_STAND"); |
347 | 353 | msmodel.setLegsAnimation("LEGS_IDLE"); |
348 | - | |
354 | + BoundingSphere ebs = new BoundingSphere(); | |
355 | + ebs.averagePoints(msmodel.getPoints()); | |
356 | + | |
349 | 357 | msmodel.setScale(new Vector(0.15f, 0.15f, 0.15f)); |
350 | 358 | |
351 | 359 | e.setGeometry(msmodel); |
360 | + e.setBoundingVolume(ebs); | |
352 | 361 | e.setPosition( |
353 | 362 | 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)); | |
358 | 366 | camera.setView(e.getPosition()); |
359 | 367 | |
360 | 368 | //Move to app specific |
@@ -384,18 +392,19 @@ public class TestMain extends AbstractGame { | ||
384 | 392 | object.setColor(0.5f, 0.85f, 0.5f, 0.5f); |
385 | 393 | object.setTexture("data/texture/plants15.jpg"); |
386 | 394 | object.useDisplayList(true); |
395 | + BoundingSphere bs = new BoundingSphere(); | |
396 | + bs.averagePoints(object.getPoints()); | |
387 | 397 | |
388 | 398 | //object = new MilkshapeModel("data/tree.ms3d"); |
389 | 399 | |
390 | - Entity[] elist = new Entity[1000]; | |
400 | + elist = new Entity[1]; | |
391 | 401 | float x, z; |
392 | - for (int i = 0; i < 1000; i++) { | |
402 | + for (int i = 0; i < 1; i++) { | |
393 | 403 | elist[i] = new Entity(i + 1); |
394 | 404 | elist[i].setGeometry(object); |
395 | - elist[i].setVisibilityType(Entity.VISIBILITY_POINT); | |
396 | 405 | do { |
397 | - x = (float) Math.random() * 2000; | |
398 | - z = (float) Math.random() * 2000; | |
406 | + x = 500; | |
407 | + z = 500; | |
399 | 408 | } while ( |
400 | 409 | hm1.getInterpolatedHeight(x / 2, z / 2) < 75 |
401 | 410 | || hm1.getInterpolatedHeight(x / 4, z / 4) > 200); |
@@ -404,8 +413,8 @@ public class TestMain extends AbstractGame { | ||
404 | 413 | x, |
405 | 414 | hm1.getInterpolatedHeight(x / 4, z / 4) + 1, |
406 | 415 | z)); |
416 | + elist[i].setBoundingVolume(bs); | |
407 | 417 | world.addEntity(elist[i]); |
408 | - elist[i].setVisibilityType(Entity.VISIBILITY_SPHERE); | |
409 | 418 | } |
410 | 419 | cc = new TestController(camera, e, this); |
411 | 420 | cc.setTrackingDistance(30f); |
@@ -195,7 +195,6 @@ public class TestKeyController extends AbstractGame { | ||
195 | 195 | |
196 | 196 | // initialize the pyramid entity |
197 | 197 | entity1 = new Entity(entity_1); |
198 | - entity1.setVisibilityType(Entity.VISIBILITY_CUBE); | |
199 | 198 | entity1.setPosition(new Vector(0.0f, 0.0f, 0.0f)); |
200 | 199 | entity1.setGeometry(triangle); |
201 | 200 | } |