How to rotate in local axes in Direct3D

Started by
4 comments, last by Burnt_Fyr 13 years, 5 months ago
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
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.
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.

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
Post your code for creating the object's world matrix (how you rotate and translate it) and the code for rendering the object.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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);  }}

This topic is closed to new replies.

Advertisement