{
quaternion currQuat;
quaternion rotQuat;
quaternion invRotQuat;
//setup current facing and rotation quaternions
currQuat.set(facing.X, facing.Y, facing.Z);
rotQuat.set(euler.X, euler.Y, euler.Z);
// Make an inverse of the rotation quaternion
invRotQuat = rotQuat;
invRotQuat.makeInverse();
// v' = v q v-1 - Gamasutra article
quaternion newRotQuat = (rotQuat * currQuat) *invRotQuat ;
// seems to get things a little closer to working
newRotQuat.normalize();
// now get back to euler angles
matrix4 mat = newRotQuat.getMatrix();
vector3df newRotation = mat.getRotationDegrees();
// store the new rotation and apply it
facing = newRotation;
NodePtr->setRotation(facing);
}
vector3df euler is the desired rotation.
This code seems to make the object rotate in a pretty much arbitrary fashion. I've been puzzling over it for a while, but my understanding of quaternions is limited to that article linked above, so I thought I'd see if any cleverer people could find the problem...
SimRex wrote:
Why do these things never become apparent during 4 hours of scouring the code, but within 5 minutes of posting a "please help me" thread?!?
That's a well known problem. An easy but not complete answer is:
During the confrontation with the problem the mind tends to forget and overlook things. If you explain the problem to someone else you have to give more information and let the mind think about other stuff. When you get back and rethink the problem you suddenly see things you didn't see in the first place.
It's like, if you try to observe an object through a telescope, you'll have to focus on a point next to the object to see things clearer....
I find that the minute you mutter something like "For f*** sake" it's time to get up, get something to eat or have a fag, then come back to the problem fresh. Otherwise accidents like keyboards through moniters mysteriously happen