-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Description
There is an issue where Matrix4f#get(Quat4f) will returns NaN as the quaternion. The issue is related to the ww calculation that can ends up with a negative value. This situation was taken care by the if statement using a ternary operator but not by the Math.sqrt juste below, where the code passes the ww value without consideration for possible negative values.
Simply replacing Math.sqrt(ww) by Math.sqrt(Math.abs(ww)) solved the issue. Even though the get didn't return exactly the same quaternion, it returned an equivalent such as applying both quaternion to the same vector will return the same transformed vector.
To test the issue:
import javax.vecmath.Matrix4d;
import javax.vecmath.Matrix4f;
import javax.vecmath.Quat4f;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;
public class Test {
public static void main(String args[]) {
testBogus(new Quat4f(0.6464f, -0.0189f, 0.76269996f, 0.0002f));
testBogusDouble(new Quat4f(0.6464f, -0.0189f, 0.76269996f, 0.0002f));
}
public static void testBogus(Quat4f q) {
Vector3f v = new Vector3f(1,0,0);
Quat4f qt = new Quat4f();
Quat4f n = new Quat4f(q);
Matrix4f pose = new Matrix4f();
n.normalize();
pose.set(n);
pose.transform(v);
pose.get(qt);
// pose.transform returns a vector but qt is now NaN
System.out.println(qt + " " + v);
}
public static void testBogusDouble(Quat4f q) {
Vector3d v = new Vector3d(1,0,0);
Quat4f qt = new Quat4f();
Quat4f n = new Quat4f(q);
Matrix4d pose = new Matrix4d();
n.normalize();
pose.set(n);
pose.transform(v);
pose.get(qt);
// pose.transform returns a vector but qt is now NaN
System.out.println(qt + " " + v);
}
}Metadata
Metadata
Assignees
Labels
No labels