Skip to content

Issue with Matrix4f#get(Quat4f), Matrix4d#get(Quat4f) and probably Matrix4d#get(Quat4d) #6

Description

@wyztix

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:

importjavax.vecmath.Matrix4d;
importjavax.vecmath.Matrix4f;
importjavax.vecmath.Quat4f;
importjavax.vecmath.Vector3d;
importjavax.vecmath.Vector3f;
publicclassTest {
publicstaticvoidmain(Stringargs[]) {
testBogus(newQuat4f(0.6464f, -0.0189f, 0.76269996f, 0.0002f));
testBogusDouble(newQuat4f(0.6464f, -0.0189f, 0.76269996f, 0.0002f));
}
publicstaticvoidtestBogus(Quat4fq) {
Vector3fv = newVector3f(1,0,0);
Quat4fqt = newQuat4f();
Quat4fn = newQuat4f(q);
Matrix4fpose = newMatrix4f();
n.normalize();
pose.set(n);
pose.transform(v);
pose.get(qt);
// pose.transform returns a vector but qt is now NaNSystem.out.println(qt + " " + v);
}
publicstaticvoidtestBogusDouble(Quat4fq) {
Vector3dv = newVector3d(1,0,0);
Quat4fqt = newQuat4f();
Quat4fn = newQuat4f(q);
Matrix4dpose = newMatrix4d();
n.normalize();
pose.set(n);
pose.transform(v);
pose.get(qt);
// pose.transform returns a vector but qt is now NaNSystem.out.println(qt + " " + v);
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions