• ### Popular Now

• 14
• 12
• 9
• 10
• 13

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

## Recommended Posts

I have created a rotation of a model with quaternions. (with 6dof) Now, I want to move it along the direction it is heading. I use the following formulas to find out what heading, pitch and roll are: roll = atan2(2.0 * (local_x * local_y + local_z * local_w),(sq_x - sq_y - sq_z + sq_w)) ; heading = asin(-2.0 * (local_x * local_z - local_y * local_w)); pitch = atan2(2.0 * (local_y * local_z + local_x * local_w),(-sq_x - sq_y + sq_z + sq_w)); My problem is that there appears to be something wrong with this. For instance when I change the heading by more then 90 degrees, both pitch and roll instantly change 180 degrees. Also, when using pitch to rotate 180 degrees (upside down) the heading remains same. Is there something wrong with my fomula's, or is there something else I am mistaking about? (or am I going about it the wrong way completely and is there an easier way to move along the models heading?) Thank you for any insight!

##### Share on other sites
Why are you trying to extract the Euler angles from the quaternion? Rotate the orientation vector of the object by the quaternion and move the object along the result.

I dont know how to change the orientation vector... :$Is it then also possible to know the x,y,z position in the world? I would expect this to be necessary to perform distance calculations between objects? Thank you for your fast reply #### Share this post ##### Link to post ##### Share on other sites Quote:  Original post by LocutusborgI dont know how to change the orientation vector... :$

Quaternion q(blah, blah, blah);
Quote:
 Is it then also possible to know the x,y,z position in the world? I would expect this to be necessary to perform distance calculations between objects?

Vector new_position = old_position + (heading * velocity);

##### Share on other sites
When I try to multiply a vector and a quaternion, I get an error:

error C2678: binary '*' : no operator found which takes a left-hand operand of type 'D3DXQUATERNION' (or there is no acceptable conversion)

Did I do something wrong?
also, what do you mean by ~q? Is that the inverse quaternion?
thanks

##### Share on other sites
Quote:
 Original post by LocutusborgWhen I try to multiply a vector and a quaternion, I get an error:error C2678: binary '*' : no operator found which takes a left-hand operand of type 'D3DXQUATERNION' (or there is no acceptable conversion)Did I do something wrong?also, what do you mean by ~q? Is that the inverse quaternion?thanks
Typically the 'v' in 'q*v*~q' is converted to quaternion form by setting the imaginary part to the vector you want to rotate and the real part to zero. As for ~, it refers to the conjugate (which, for a unit-length quaternion, returns the same value as the inverse).

Usually though you don't need to perform 'manual' quaternion rotation of vectors to do what you're wanting. Assuming the object moves along the cardinal basis vectors in local space ([1,0,0], [0,1,0], [0,0,1]), you can simply convert the orientation quaternion to a matrix and extract the direction vectors therefrom.