Sign in to follow this  
him_me

How to rotate in local axes in Direct3D

Recommended Posts

him_me    100
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


Link to post
Share on other sites
RXminuS    100
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


Link to post
Share on other sites
zerothrillz    152
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


Link to post
Share on other sites
him_me    100
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


Link to post
Share on other sites
Buckeye    10747
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


Link to post
Share on other sites
Burnt_Fyr    1665
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


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this