Advertisement Jump to content
Sign in to follow this  
sjaakiejj

Quaternions - Rotations

This topic is 2866 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

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 !

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!