I got a node, thats rotating freely around all axis. At one point I want to reset the rotation but keep the rotation around the z-axis axis. What I've done so far is
//multiply the up vector 0f, 1f, 0f with the rotation matrix
Vector3f tmp = quat.toRotationMatrix().mult(up);
//calculate the rotation angle around z-axis
tmp.z = 0f;
float angle = FastMath.atan2(tmp.y, tmp.x);
//reset all
quat.loadIdentity();
quat.fromAngleAxis(angle, new Vector3f(0f, 0f, 1f));
This doesn't work.. I tried a couple of other aproaches, but nothing helped so far..
Any help is apreciated
I think he's using physics not a spatial transformer
That's right.
irrisor said:
My fix for that would have been similar to yours with the direction vector. What does not work?
I'm not sure about what's going wrong. My guess is, that the angles aren't neccesarily from 0 to 2PI. If I rotate an object around its z-axis the resulting angle is going from 0 to PI and then suddenly switches to -PI. To compensate that, the two other angles ( around x and y) switch from 0 to PI. So when I tried to rebuild the rotations Quaternion from three angles with x = y = 0 and z = 0..2PI strange things happend..There was some strange flipping and well, it just didn't do what I expected. So I made a table and remebered and filled in the x, y values for every quadrant.. was a bit of a quirky solution, and yes: didn't work either..
What I am doing now is: