/*\r
- * Copyright (c) 2009-2010 jMonkeyEngine\r
+ * Copyright (c) 2009-2012 jMonkeyEngine\r
* All rights reserved.\r
*\r
* Redistribution and use in source and binary forms, with or without\r
import com.jme3.export.JmeExporter;\r
import com.jme3.export.JmeImporter;\r
import com.jme3.export.OutputCapsule;\r
-import java.io.IOException;\r
-import java.nio.FloatBuffer;\r
-\r
-import com.jme3.math.FastMath;\r
-import com.jme3.math.Matrix3f;\r
-import com.jme3.math.Matrix4f;\r
-import com.jme3.math.Plane;\r
-import com.jme3.math.Ray;\r
-import com.jme3.math.Transform;\r
-import com.jme3.math.Triangle;\r
-import com.jme3.math.Vector3f;\r
+import com.jme3.math.*;\r
import com.jme3.scene.Mesh;\r
-import com.jme3.util.BufferUtils;\r
import com.jme3.util.TempVars;\r
+import java.io.IOException;\r
+import java.nio.FloatBuffer;\r
//import com.jme.scene.TriMesh;\r
\r
/**\r
vars.release();\r
}\r
\r
- public static final void checkMinMax(Vector3f min, Vector3f max, Vector3f point) {\r
+ public static void checkMinMax(Vector3f min, Vector3f max, Vector3f point) {\r
if (point.x < min.x) {\r
min.x = point.x;\r
}\r
}\r
\r
TempVars vars = TempVars.get();\r
+ \r
+ float[] tmpArray = vars.skinPositions;\r
\r
- BufferUtils.populateFromBuffer(vars.vect1, points, 0);\r
- float minX = vars.vect1.x, minY = vars.vect1.y, minZ = vars.vect1.z;\r
- float maxX = vars.vect1.x, maxY = vars.vect1.y, maxZ = vars.vect1.z;\r
-\r
- for (int i = 1, len = points.remaining() / 3; i < len; i++) {\r
- BufferUtils.populateFromBuffer(vars.vect1, points, i);\r
-\r
- if (vars.vect1.x < minX) {\r
- minX = vars.vect1.x;\r
- } else if (vars.vect1.x > maxX) {\r
- maxX = vars.vect1.x;\r
- }\r
-\r
- if (vars.vect1.y < minY) {\r
- minY = vars.vect1.y;\r
- } else if (vars.vect1.y > maxY) {\r
- maxY = vars.vect1.y;\r
- }\r
-\r
- if (vars.vect1.z < minZ) {\r
- minZ = vars.vect1.z;\r
- } else if (vars.vect1.z > maxZ) {\r
- maxZ = vars.vect1.z;\r
+ float minX = Float.POSITIVE_INFINITY, minY = Float.POSITIVE_INFINITY, minZ = Float.POSITIVE_INFINITY;\r
+ float maxX = Float.NEGATIVE_INFINITY, maxY = Float.NEGATIVE_INFINITY, maxZ = Float.NEGATIVE_INFINITY;\r
+ \r
+ int iterations = (int) FastMath.ceil(points.limit() / ((float) tmpArray.length));\r
+ for (int i = iterations - 1; i >= 0; i--) {\r
+ int bufLength = Math.min(tmpArray.length, points.remaining());\r
+ points.get(tmpArray, 0, bufLength);\r
+\r
+ for (int j = 0; j < bufLength; j += 3) {\r
+ vars.vect1.x = tmpArray[j];\r
+ vars.vect1.y = tmpArray[j+1];\r
+ vars.vect1.z = tmpArray[j+2];\r
+ \r
+ if (vars.vect1.x < minX) {\r
+ minX = vars.vect1.x;\r
+ }\r
+ if (vars.vect1.x > maxX) {\r
+ maxX = vars.vect1.x;\r
+ }\r
+\r
+ if (vars.vect1.y < minY) {\r
+ minY = vars.vect1.y;\r
+ }\r
+ if (vars.vect1.y > maxY) {\r
+ maxY = vars.vect1.y;\r
+ }\r
+\r
+ if (vars.vect1.z < minZ) {\r
+ minZ = vars.vect1.z;\r
+ }\r
+ if (vars.vect1.z > maxZ) {\r
+ maxZ = vars.vect1.z;\r
+ }\r
}\r
}\r
\r
}\r
\r
/**\r
- * <code>merge</code> combines this sphere with a second bounding sphere.\r
- * This new sphere contains both bounding spheres and is returned.\r
+ * <code>merge</code> combines this bounding box with a second bounding box.\r
+ * This new box contains both bounding box and is returned.\r
* \r
* @param volume\r
- * the sphere to combine with this sphere.\r
- * @return the new sphere\r
+ * the bounding box to combine with this bounding box.\r
+ * @return the new bounding box\r
*/\r
public BoundingVolume merge(BoundingVolume volume) {\r
if (volume == null) {\r
/*\r
- * Copyright (c) 2009-2010 jMonkeyEngine\r
+ * Copyright (c) 2009-2012 jMonkeyEngine\r
* All rights reserved.\r
*\r
* Redistribution and use in source and binary forms, with or without\r
import com.jme3.collision.UnsupportedCollisionException;\r
import com.jme3.export.JmeExporter;\r
import com.jme3.export.JmeImporter;\r
+import com.jme3.math.*;\r
+import com.jme3.util.BufferUtils;\r
+import com.jme3.util.TempVars;\r
import java.io.IOException;\r
import java.nio.FloatBuffer;\r
import java.util.logging.Level;\r
import java.util.logging.Logger;\r
\r
-import com.jme3.math.FastMath;\r
-import com.jme3.math.Matrix4f;\r
-import com.jme3.math.Plane;\r
-import com.jme3.math.Ray;\r
-import com.jme3.math.Transform;\r
-import com.jme3.math.Triangle;\r
-import com.jme3.math.Vector3f;\r
-import com.jme3.util.BufferUtils;\r
-import com.jme3.util.TempVars;\r
-\r
/**\r
* <code>BoundingSphere</code> defines a sphere that defines a container for a\r
* group of vertices of a particular piece of geometry. This sphere defines a\r
* in <code>points</code>.\r
*/\r
private void recurseMini(FloatBuffer points, int p, int b, int ap) {\r
- TempVars vars = TempVars.get();\r
+ //TempVars vars = TempVars.get();\r
\r
- Vector3f tempA = vars.vect1;\r
- Vector3f tempB = vars.vect2;\r
- Vector3f tempC = vars.vect3;\r
- Vector3f tempD = vars.vect4;\r
+ Vector3f tempA = new Vector3f(); //vars.vect1;\r
+ Vector3f tempB = new Vector3f(); //vars.vect2;\r
+ Vector3f tempC = new Vector3f(); //vars.vect3;\r
+ Vector3f tempD = new Vector3f(); //vars.vect4;\r
\r
switch (b) {\r
case 0:\r
BufferUtils.populateFromBuffer(tempC, points, ap - 3);\r
BufferUtils.populateFromBuffer(tempD, points, ap - 4);\r
setSphere(tempA, tempB, tempC, tempD);\r
- vars.release();\r
+ //vars.release();\r
return;\r
}\r
for (int i = 0; i < p; i++) {\r
BufferUtils.setInBuffer(tempB, points, j - 1 + ap);\r
}\r
recurseMini(points, i, b + 1, ap + 1);\r
-\r
}\r
}\r
- vars.release();\r
+ //vars.release();\r
}\r
\r
/**\r
* the list of points to contain.\r
*/\r
public void averagePoints(Vector3f[] points) {\r
- logger.info("Bounding Sphere calculated using average points.");\r
+ logger.fine("Bounding Sphere calculated using average points.");\r
center = points[0];\r
\r
for (int i = 1; i < points.length; i++) {\r
*\r
* @see com.jme.bounding.BoundingVolume#intersectsWhere(com.jme.math.Ray)\r
*/\r
- public int collideWithRay(Ray ray, CollisionResults results) {\r
+ private int collideWithRay(Ray ray, CollisionResults results) {\r
TempVars vars = TempVars.get();\r
\r
Vector3f diff = vars.vect1.set(ray.getOrigin()).subtractLocal(\r
return 1;\r
}\r
}\r
-\r
+ \r
public int collideWith(Collidable other, CollisionResults results) {\r
if (other instanceof Ray) {\r
Ray ray = (Ray) other;\r
return collideWithRay(ray, results);\r
+ } else if (other instanceof Triangle){\r
+ Triangle t = (Triangle) other;\r
+ \r
+ float r2 = radius * radius;\r
+ float d1 = center.distanceSquared(t.get1());\r
+ float d2 = center.distanceSquared(t.get2());\r
+ float d3 = center.distanceSquared(t.get3());\r
+ \r
+ if (d1 <= r2 || d2 <= r2 || d3 <= r2) {\r
+ CollisionResult r = new CollisionResult();\r
+ r.setDistance(FastMath.sqrt(Math.min(Math.min(d1, d2), d3)) - radius);\r
+ results.addCollision(r);\r
+ return 1;\r
+ }\r
+\r
+ return 0;\r
} else {\r
throw new UnsupportedCollisionException();\r
}\r
/*\r
- * Copyright (c) 2009-2010 jMonkeyEngine\r
+ * Copyright (c) 2009-2012 jMonkeyEngine\r
* All rights reserved.\r
*\r
* Redistribution and use in source and binary forms, with or without\r
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
*/\r
-\r
package com.jme3.bounding;\r
\r
import com.jme3.collision.Collidable;\r
import com.jme3.export.JmeExporter;\r
import com.jme3.export.JmeImporter;\r
import com.jme3.export.Savable;\r
-import com.jme3.math.Matrix4f;\r
+import com.jme3.math.*;\r
import java.io.IOException;\r
import java.nio.FloatBuffer;\r
\r
-import com.jme3.math.Plane;\r
-import com.jme3.math.Ray;\r
-import com.jme3.math.Transform;\r
-import com.jme3.math.Vector3f;\r
-\r
/**\r
* <code>BoundingVolume</code> defines an interface for dealing with\r
* containment of a collection of points.\r
*/\r
public abstract class BoundingVolume implements Savable, Cloneable, Collidable {\r
\r
+ /**\r
+ * The type of bounding volume being used.\r
+ */\r
public enum Type {\r
- Sphere, AABB, OBB, Capsule;\r
+ /**\r
+ * {@link BoundingSphere}\r
+ */\r
+ Sphere, \r
+ \r
+ /**\r
+ * {@link BoundingBox}.\r
+ */\r
+ AABB, \r
+ \r
+ /**\r
+ * Currently unsupported by jME3.\r
+ */\r
+ Capsule;\r
}\r
\r
protected int checkPlane = 0;\r
- Vector3f center = new Vector3f();\r
+ protected Vector3f center = new Vector3f();\r
\r
public BoundingVolume() {\r
}\r
/*
- * Copyright (c) 2009-2010 jMonkeyEngine
+ * Copyright (c) 2009-2012 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
package com.jme3.bounding;
-import com.jme3.util.TempVars;
import com.jme3.math.FastMath;
import com.jme3.math.Plane;
import com.jme3.math.Vector3f;
-
-import static java.lang.Math.min;
+import com.jme3.util.TempVars;
import static java.lang.Math.max;
+import static java.lang.Math.min;
/**
* This class includes some utility methods for computing intersection
/*\r
- * Copyright (c) 2009-2010 jMonkeyEngine\r
+ * Copyright (c) 2009-2012 jMonkeyEngine\r
* All rights reserved.\r
*\r
* Redistribution and use in source and binary forms, with or without\r
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
*/\r
-\r
package com.jme3.bounding;\r
\r
/**\r