-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Added convenience method worldToLocal(Quaternion) to spatial. #2559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…ns and corresponding test
…uaternion transformations.
Assert.assertEquals(worldTranslation,testNode.getWorldTranslation()); | ||
|
||
testNode.setLocalRotation(nodeB.worldToLocal(worldRotation,null)); | ||
Assert.assertEquals(worldRotation,testNode.getWorldRotation()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest using isSimilar
for equality checks so it doesn't fail on round-off error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point
I am going reimplement to get rid of the unneccesary allocation. |
…enhanced floating-point precision checks.
(Quaternion.inverse())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how quaternions work, so take this with a grain of salt.
|
||
//Second option is to normalize manually | ||
float norm = rotation.norm(); | ||
store.multLocal(rotation.getX()*-norm, rotation.getY()*-norm, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right to me if you're trying to normalize and invert the rotation. From looking at Quaternion, it seems like norm
should be changed like this:
norm = FastMath.invSqrt(norm) / norm;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally i agree, using jme math i have not yet managed to create a non normalized quaternion.
for (int i = 0; i < 1000000; i++) {
Quaternion quaternion=new Quaternion().fromAngles(FastMath.nextRandomFloat()*-360,FastMath.nextRandomFloat()*360,FastMath.nextRandomFloat()*360);
Quaternion inverse = quaternion.inverse();
float norm = quaternion.norm();
//norm = FastMath.invSqrt(norm)/norm;
System.out.println(norm);
quaternion.set(quaternion.getX()*-norm, quaternion.getY()*-norm, quaternion.getZ()*-norm, quaternion.getW()*norm);
if(!quaternion.isSimilar(inverse,0.000001f)){
System.out.println("Fail");
System.out.println(quaternion);
System.out.println(inverse);
System.exit(1);
}
}
This PR adds the convenience method worldToLocal for Quaternions, i added a test that shows the usage when transferring a spatial to a different Node.