--- Sphere.java.old 2003-09-13 04:31:53.000000000 +0200 +++ Sphere.java 2003-10-31 21:58:01.000000000 +0100 @@ -79,7 +79,7 @@ private final static float BIGNUMBER = 100000000.0f; /* hundred million */ - public float x, y, z, radius, radius2; + public float x, y, z, radius; /** * BoundingSphere constructor comment. */ @@ -93,14 +93,12 @@ this.y = y; this.z = z; this.radius = radius; - radius2 = x*x + y*y + z*z; } public void setCenter( Tuple3f c) { x = c.x; y = c.y; z = c.z; - radius2 = x*x + y*y + z*z; } public void setRadius( float r) { @@ -110,7 +108,6 @@ x = cx; y = cy; z = cz; - radius2 = x*x + y*y + z*z; } /** @@ -119,7 +116,7 @@ */ public Classifier.Classification classify(float xx, float yy, float zz) { if ((x - xx) * (x - xx) + (y - yy) * (y - yy) + (z - zz) * (z - zz) - <= radius) + <= radius*radius) return Classifier.INSIDE; else return Classifier.OUTSIDE; @@ -133,15 +130,16 @@ float xx, float yy, float zz, - float radius2) { - float d = - (x - xx) * (x - xx) + (y - yy) * (y - yy) + (z - zz) * (z - zz); - - if (d + radius2 < radius) + float rr) { + float d = (float)Math.sqrt( + (x - xx) * (x - xx) + (y - yy) * (y - yy) + (z - zz) * (z - zz)); + if (d + rr < radius) return Classifier.INSIDE; - else if (d < radius2 + radius) + else if ( d + radius < rr ) + return Classifier.ENCLOSING; + else if (d < rr + radius) return Classifier.SPANNING; - else if (d > radius + radius2) + else if (d > radius + rr) return Classifier.OUTSIDE; else return Classifier.ENCLOSING; @@ -170,7 +168,7 @@ * @see com.powersolve.jglib.geometry.Classifier */ public Classifier.Classification classify(Sphere sphere) { - return classify(sphere.x, sphere.y, sphere.z, sphere.radius2); + return classify(sphere.x, sphere.y, sphere.z, sphere.radius); } /** * @see com.powersolve.jglib.geometry.Classifier @@ -210,9 +208,9 @@ zmax.set(-BIGNUMBER, -BIGNUMBER, -BIGNUMBER); int count = source.getVertexCount(); - - for (int i = 0; i < count; i++) { Vector3f caller_p = VectorHeap.alloc(); + for (int i = 0; i < count; i++) { + source.getVertex(i, caller_p); if (caller_p.x < xmin.x) { @@ -295,7 +293,6 @@ /* SECOND PASS: increment current sphere */ for (int i = 0; i < count; i++) { - Vector3f caller_p = VectorHeap.alloc(); source.getVertex(i, caller_p); dx = caller_p.x - x; dy = caller_p.y - y; @@ -325,6 +322,8 @@ } } + VectorHeap.free(caller_p); + VectorHeap.free(xmin); VectorHeap.free(xmax); @@ -339,4 +338,8 @@ } + public String toString() { + return "["+x+","+y+","+z+"]R"+radius; + } + }