Jump to content
• Advertisement

# How to rotate in local axes in Direct3D

This topic is 2806 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 guys,
my problem i've figured out is that i want to rotate a model in local X(or Y,Z) axis to give it a desired look. But it is getting rotated in global X after using D3DXMatrixRotationX(&matRotX, D3DXToRadian(angle)). (Obvious since World is global matrix)

Guys forgive me if this question is too trivial but i dint got any clue how to do it.

Pls help me out
Thanks

#### Share this post

##### Share on other sites
Advertisement
You can first multiply with the inverse translation matrix (to place it back at the origin) and then multiply with the rotationmatrix. Then you multiply it again with the translation matrix. I'm not sure if there was a faster way of doing it using D3DX because i use my own math library.

#### Share this post

##### Share on other sites
Nope, there's no faster way of doing it. Move it to the origin, move it back. Depending on how DX implements matrix operations it may not even do a full matrix multiplication.

#### Share this post

##### Share on other sites
Hi thanks for replying but the approach u told its not working. i am already doing the translation in the end. What is the idea exactly i cant figure it out

#### Share this post

##### Share on other sites
Post your code for creating the object's world matrix (how you rotate and translate it) and the code for rendering the object.

#### Share this post

##### Share on other sites
I'm going to jump the gun and assume that you are looking for a 6dof system. If so, you want to store your objects local axii, and use an arbitrary axis rotation, suppling the local axis as the vector to rotate around. Use this matrix to transform the other 2 axii.

some psuedocode

class object {  Vector3 front, right, up;  void Pitch(float radians) {    // to pitch we rotate about the local X axis    Matrix m;    m = AxisAngleRotationMatrix(right, radians);      // and transform our local z and y axii    Transform(up, m);    Transform(front, m);  }  void Roll(float radians) {    // to roll we rotate about the local Z axis    Matrix m;    m = AxisAngleRotationMatrix(front, radians);    // and transform the other 2 axii    Transform(right,m);    Transform(up,m);  }}

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5
• Advertisement

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631781
• Total Posts
3002319
×

## Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!