Skip to content

Commit 2eb11cf

Browse files
committed
Refactored worldToLocal in Spatial to utilize TempVars for optimized quaternion handling and removed redundant comments.
1 parent 726ea52 commit 2eb11cf

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

jme3-core/src/main/java/com/jme3/scene/Spatial.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,22 +1000,12 @@ public Quaternion worldToLocal(final Quaternion in, Quaternion store){
10001000
}else{
10011001
store.set(in);
10021002
}
1003-
Quaternion rotation = worldTransform.getRotation();
1004-
//can we be sure if the quaternion is normalized?
1005-
//if yes, the conjugate could be used, and the normalizing procedure skipped
1006-
//store.multLocal(-rotation.getX(), -rotation.getY(), -rotation.getZ(), rotation.getW();
1007-
1008-
//Second option is to normalize manually
1009-
float norm = rotation.norm();
1010-
store.multLocal(rotation.getX()*-norm, rotation.getY()*-norm,
1011-
rotation.getZ()*-norm, rotation.getW()*norm);
1003+
TempVars tempVars = TempVars.get();
1004+
Quaternion worldRotation = tempVars.quat1.set(getWorldRotation());
1005+
worldRotation.inverseLocal();
1006+
store.multLocal(worldRotation);
1007+
tempVars.release();
10121008
return store;
1013-
1014-
//Third option is to temporarily change the parent's quaternion. More expensive then option 2,
1015-
//but produces more accurate results. compared to option 2. (Error still below 1e-6f)
1016-
//store.multLocal(rotation.inverseLocal());
1017-
//rotation.inverseLocal();
1018-
//return store;
10191009
}
10201010

10211011
/**

0 commit comments

Comments
 (0)