Problem with reseting rotations

Hi there,

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.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 dont think is possible if u r using spatial transformer. coz update geometricstate will always reset the changes u made.

my advice would be using ur own local translation transformer. this way u have compelete control of everything :smiley:

I think he's using physics not a spatial transformer. So setting back rotation should be working.

The clean way with physic would be a joint limiting the rotation, but there is no joint yet (see several posts about that)…

@paul: My fix for that would have been similar to yours with the direction vector. What does not work?

irrisor said:

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:

Vector 3f tmp = dyna.getLocalRotation().toRotationMatrix().mult(up);
tmp.z = 0f;
dyna.getLocalRotation().lookAt(new Vector3f(0f, 0f, 1f), tmp);

Where dyna is just a dynamic node.. Now it works, and I am happy :) But I still don't know what was going on in the first place

mmm, sounds ok, too but you can omit that toRotationMatrix() - quaternions can be multiplied with vectors, too.