浏览代码

Refactored `worldToLocal` in `Spatial` to utilize `TempVars` for optimized quaternion handling and removed redundant comments.

zzuegg 2 月之前
父节点
当前提交
2eb11cf389
共有 1 个文件被更改,包括 5 次插入15 次删除
  1. 5 15
      jme3-core/src/main/java/com/jme3/scene/Spatial.java

+ 5 - 15
jme3-core/src/main/java/com/jme3/scene/Spatial.java

@@ -1000,22 +1000,12 @@ public abstract class Spatial implements Savable, Cloneable, Collidable,
         }else{
             store.set(in);
         }
-        Quaternion rotation = worldTransform.getRotation();
-        //can we be sure if the quaternion is normalized?
-        //if yes, the conjugate could be used, and the normalizing procedure skipped
-        //store.multLocal(-rotation.getX(), -rotation.getY(), -rotation.getZ(), rotation.getW();
-
-        //Second option is to normalize manually
-        float norm = rotation.norm();
-        store.multLocal(rotation.getX()*-norm, rotation.getY()*-norm,
-                        rotation.getZ()*-norm, rotation.getW()*norm);
+        TempVars tempVars = TempVars.get();
+        Quaternion worldRotation = tempVars.quat1.set(getWorldRotation());
+        worldRotation.inverseLocal();
+        store.multLocal(worldRotation);
+        tempVars.release();
         return store;
-
-        //Third option is to temporarily change the parent's quaternion. More expensive then option 2,
-        //but produces more accurate results. compared to option 2. (Error still below 1e-6f)
-        //store.multLocal(rotation.inverseLocal());
-        //rotation.inverseLocal();
-        //return store;
     }
 
     /**