Quaternion problems

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
SimRex
Posts: 6
Joined: Wed Feb 04, 2004 11:54 pm
Location: England
Contact:

Quaternion problems

Post by SimRex »

OK, I'm going to cut right to the chase... I'm trying to use quaternions to do rotations in full 3d space, and it's just not working :(

I've been using http://www.gamasutra.com/features/19980 ... ons_01.htm as a reference guide (requires free registration I think) but have met with basically no success. Here's the code I'm using for my rotations:

Code: Select all

{
    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...

Thanks for your time!
SimRex
Posts: 6
Joined: Wed Feb 04, 2004 11:54 pm
Location: England
Contact:

Post by SimRex »

Um.. Okay, I'm being a bit dopey today - just spotted a huge flaw in my reasoning :oops:

It's not working because I'm trying to rotate a rotation vector, not a standard vector.

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?!? :(
Gorgon Zola
Posts: 118
Joined: Thu Sep 18, 2003 10:05 pm
Location: switzerland

Post by Gorgon Zola »

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.... :lol:
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

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 :D
Gorgon Zola
Posts: 118
Joined: Thu Sep 18, 2003 10:05 pm
Location: switzerland

Post by Gorgon Zola »

Tyn, You definitively have a point there :lol:
Post Reply