Quaternions - Rotations

Started by
3 comments, last by sjaakiejj 13 years, 1 month ago
Hi,

I'm trying to get my head around Quaternions in Graphics, and I believe I understand the basic principles. Given that, I came up with the following piece of code to handle my rotations:



quaternion newRot(0.0f, ANGLE * timeSinceLastUpdate, 0.0f);
rotation *= newRot;
rotation.toEuler(euler);
setRotation(euler * RADTODEG );



setRotation sets the rotation of the entity, and it requires euler co-ordinates to do so. In addition, I have a getRotation and a getQRotation method for use with the Camera. getQRotation returns the same rotation variable seen in this code-snippet.

For now I'm assuming that toEuler is doing the correct thing, and it's my maths that's off. The character rotates, but in a very "jerky" way, e.g. it just skips parts. When moving in a certain direction, it also moves much slower than moving in another direction, which is clearly wrong as well. As for the camera, I've written this:



setPosition( parent->getPosition()+parent->getQRotation() * vector3df(-50.0, 30.0, 0.0) );


This rotates correctly, but doesn't keep the same distance consistently. I'm quite sure that that's related to my 50.0, but at the same time wasn't quite sure how to handle the translation otherwise.

Thanks in advance for your help.
Advertisement
My first question would be, is this all your own code, or are you working with an external API? (In particular, I'm wondering about the use of Euler angles here and if it's actually necessary.)

My first question would be, is this all your own code, or are you working with an external API? (In particular, I'm wondering about the use of Euler angles here and if it's actually necessary.)


Hi Jyk,

Thanks for your reply. The quaternions and Vectors I'm using are both part of the Irrlicht Engine; SetRotate sets the rotation of a scene node.
There are lots of thing that could potentially be going wrong here. Here's a few things to check:

1. Make sure all the necessary degree<->radian conversions are in place (I see one in your code, but I'll mention it anyway).

2. Make sure the axis-order convention matches between your 'to Euler' function and what Irrlicht expects.

3. Be sure to normalize your quaternion periodically if you're updating incrementally (as you appear to be).

4. Make sure your quaternion-vector rotation function is implemented correctly. (I'd also advise not overloading the * operator for quaternion-vector rotation, as it's potentially confusing and misleading.)

Anyway, those are a few things you can try. As I mentioned though, problems like these can be caused by any number of things. The actual cause of the problem could lie at just about any point in the process, so you may have to do a little debugging in order to isolate the cause (whatever it might be).

There are lots of thing that could potentially be going wrong here. Here's a few things to check:

1. Make sure all the necessary degree<->radian conversions are in place (I see one in your code, but I'll mention it anyway).

2. Make sure the axis-order convention matches between your 'to Euler' function and what Irrlicht expects.

3. Be sure to normalize your quaternion periodically if you're updating incrementally (as you appear to be).

4. Make sure your quaternion-vector rotation function is implemented correctly. (I'd also advise not overloading the * operator for quaternion-vector rotation, as it's potentially confusing and misleading.)

Anyway, those are a few things you can try. As I mentioned though, problems like these can be caused by any number of things. The actual cause of the problem could lie at just about any point in the process, so you may have to do a little debugging in order to isolate the cause (whatever it might be).


Whoops! You're right, I forgot to normalize the quaternion, which would explain the behaviour that I was experiencing. I just updated my code, and it works perfectly now :D

Thanks !

This topic is closed to new replies.

Advertisement