Răsfoiți Sursa

account for world transform in TerrainQuad.setNormalRecalcNeeded() (#1741)

* Fix Normal Recalculation 

Fixes issue in setNormalRecalcNeeded() method where the bounding box containing recently changed points was always located at 0,0,0 regardless of the terrain's world translation.

* Update TerrainQuad.java

fix indentation that got messed up while copying over my code

* Update TerrainQuad.java

* Update TerrainQuad.java

updated to account for scale

* Update TerrainQuad.java

* Update TerrainQuad.java

* Update TerrainQuad.java

* Update TerrainQuad.java

accidentally deleted quaternion import, added back in

* Update TerrainQuad.java

forgot import for bounding sphere

* Update TerrainQuad.java
Ryan McDonough 3 ani în urmă
părinte
comite
371849bd52

+ 22 - 1
jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/TerrainQuad.java

@@ -32,6 +32,7 @@
 package com.jme3.terrain.geomipmap;
 
 import com.jme3.bounding.BoundingBox;
+import com.jme3.bounding.BoundingSphere;
 import com.jme3.bounding.BoundingVolume;
 import com.jme3.collision.Collidable;
 import com.jme3.collision.CollisionResults;
@@ -44,6 +45,7 @@ import com.jme3.math.FastMath;
 import com.jme3.math.Ray;
 import com.jme3.math.Vector2f;
 import com.jme3.math.Vector3f;
+import com.jme3.math.Quaternion;
 import com.jme3.scene.Geometry;
 import com.jme3.scene.Node;
 import com.jme3.scene.Spatial;
@@ -850,7 +852,26 @@ public class TerrainQuad extends Node implements Terrain {
             affectedAreaBBox = null;
             return;
         }
-
+        
+        Vector2f worldLocVec2 = changedPoint.clone();
+        worldLocVec2.multLocal(new Vector2f(getWorldScale().x, getWorldScale().z));
+        worldLocVec2.addLocal(getWorldTranslation().x, getWorldTranslation().z);		
+        changedPoint = worldLocVec2;
+
+        Quaternion wr = getWorldRotation();
+        if (wr.getX() != 0 || wr.getY() != 0 || wr.getZ() != 0) {
+            BoundingVolume bv = getWorldBound();
+            if (bv instanceof BoundingSphere) {
+                BoundingSphere bs = (BoundingSphere) bv;
+                float r = bs.getRadius();
+                Vector3f center = bs.getCenter();
+                affectedAreaBBox = new BoundingBox(center, r, r, r);
+            } else {
+                affectedAreaBBox = (BoundingBox) bv.clone();
+            }            
+            return;
+        }
+        
         if (affectedAreaBBox == null) {
             affectedAreaBBox = new BoundingBox(new Vector3f(changedPoint.x, 0, changedPoint.y), 1f, Float.MAX_VALUE, 1f); // unit length
         } else {