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

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

##### 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.)

##### 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 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).

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

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

Thanks !

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634103
• Total Posts
3015539
×