Skip to content

Commit aae6052

Browse files
committed
removed the need to allocate a temporary object.
(Quaternion.inverse())
1 parent baae9df commit aae6052

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,8 +1000,21 @@ public Quaternion worldToLocal(final Quaternion in, Quaternion store){
10001000
}else{
10011001
store.set(in);
10021002
}
1003-
store.multLocal(worldTransform.getRotation().inverse());
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, rotation.getZ()*-norm, rotation.getW()*norm);
10041011
return store;
1012+
1013+
//Third option is to temporarily change the parent's quaternion. More expensive then option 2,
1014+
//but produces more accurate results. compared to option 2. (Error still below 1e-6f)
1015+
//store.multLocal(rotation.inverseLocal());
1016+
//rotation.inverseLocal();
1017+
//return store;
10051018
}
10061019

10071020
/**

0 commit comments

Comments
 (0)