Added convenience method worldToLocal(Quaternion) to spatial. - #2559
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.
I suggest using isSimilar for equality checks so it doesn't fail on round-off error.
|
I am going reimplement to get rid of the unneccesary allocation. |
…enhanced floating-point precision checks.
(Quaternion.inverse())
codex128
left a comment
There was a problem hiding this comment.
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.
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.
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);
}
}
There was a problem hiding this comment.
I could use temp vars and use the existing math functions. I probably prefer that. Considering that this code is probably never executed in the "hot loop"
…mized quaternion handling and removed redundant comments.
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.