Browse Source

* The bounding box will compute faster, maybe even more faster on Android .. If its bad, please go ahead and complain

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9548 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
Sha..rd 13 years ago
parent
commit
d46ee26002
1 changed files with 32 additions and 23 deletions
  1. 32 23
      engine/src/core/com/jme3/bounding/BoundingBox.java

+ 32 - 23
engine/src/core/com/jme3/bounding/BoundingBox.java

@@ -221,30 +221,39 @@ public class BoundingBox extends BoundingVolume {
         }
 
         TempVars vars = TempVars.get();
+        
+        float[] tmpArray = vars.skinPositions;
 
-        BufferUtils.populateFromBuffer(vars.vect1, points, 0);
-        float minX = vars.vect1.x, minY = vars.vect1.y, minZ = vars.vect1.z;
-        float maxX = vars.vect1.x, maxY = vars.vect1.y, maxZ = vars.vect1.z;
-
-        for (int i = 1, len = points.remaining() / 3; i < len; i++) {
-            BufferUtils.populateFromBuffer(vars.vect1, points, i);
-
-            if (vars.vect1.x < minX) {
-                minX = vars.vect1.x;
-            } else if (vars.vect1.x > maxX) {
-                maxX = vars.vect1.x;
-            }
-
-            if (vars.vect1.y < minY) {
-                minY = vars.vect1.y;
-            } else if (vars.vect1.y > maxY) {
-                maxY = vars.vect1.y;
-            }
-
-            if (vars.vect1.z < minZ) {
-                minZ = vars.vect1.z;
-            } else if (vars.vect1.z > maxZ) {
-                maxZ = vars.vect1.z;
+        float minX = Float.MAX_VALUE, minY = Float.MAX_VALUE, minZ = Float.MAX_VALUE;
+        float maxX = Float.MIN_VALUE, maxY = Float.MIN_VALUE, maxZ = Float.MIN_VALUE;
+        
+        int iterations = (int) FastMath.ceil(points.limit() / ((float) tmpArray.length));
+        for (int i = iterations - 1; i >= 0; i--) {
+            int bufLength = Math.min(tmpArray.length, points.remaining());
+            points.get(tmpArray, 0, bufLength);
+
+            for (int j = 0; j < bufLength; j += 3) {
+                vars.vect1.x = tmpArray[j];
+                vars.vect1.y = tmpArray[j+1];
+                vars.vect1.z = tmpArray[j+2];
+                
+                if (vars.vect1.x < minX) {
+                    minX = vars.vect1.x;
+                } else if (vars.vect1.x > maxX) {
+                    maxX = vars.vect1.x;
+                }
+
+                if (vars.vect1.y < minY) {
+                    minY = vars.vect1.y;
+                } else if (vars.vect1.y > maxY) {
+                    maxY = vars.vect1.y;
+                }
+
+                if (vars.vect1.z < minZ) {
+                    minZ = vars.vect1.z;
+                } else if (vars.vect1.z > maxZ) {
+                    maxZ = vars.vect1.z;
+                }
             }
         }