Browse Source

removed the need to allocate a temporary object.
(Quaternion.inverse())

zzuegg 2 months ago
parent
commit
aae6052af3
1 changed files with 14 additions and 1 deletions
  1. 14 1
      jme3-core/src/main/java/com/jme3/scene/Spatial.java

+ 14 - 1
jme3-core/src/main/java/com/jme3/scene/Spatial.java

@@ -1000,8 +1000,21 @@ public abstract class Spatial implements Savable, Cloneable, Collidable,
         }else{
             store.set(in);
         }
-        store.multLocal(worldTransform.getRotation().inverse());
+        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);
         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;
     }
 
     /**