# Rotate around model's axes

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

## Recommended Posts

I want to rotate around model's y-axis, but I do not know how to do it. There is a same topic but I do not completely understand and it is closed. There is a function name D3DXMatrixRotationAxis in DX, but the problem is how to set the vector value, to rotate around, after loading a model.

##### Share on other sites

To rotate about the y-axis, you would use for D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) for the vector. That's the unit vector representing the +ve y-axis.

##### Share on other sites

Phil_t is correct. Here is the MSDN reference for that method. Just to add one small extra note: You'll want to make sure that your model is in "model space", which means you haven't applied any transformations to it. The center should be very near (0,0,0) and it should be oriented towards your preferred standard orientation (I use [1,0,0] as my facing direction). Apply your rotation to get your rotation matrix, then apply your rotation matrix to your model.

##### Share on other sites

From what i gather, it's not the performing of the rotation that you have an issue with, but the actually finding of that axis of rotation. If you have a world transform already, you can extract the local X Y and Z vectors from it, and use those to rotate around. this will be different depending on your matrix layout, but you should be able to use the [] operator on the world matrix to get each axis individually(i think anyway, I have never used the d3d math library).

// psuedo code

// matrix layout
// x.x, x.y, x.z 0
// y.x, y.y, y.z, 0
// z.x, z.y, z.z, 0
// t.x,  t.y,  t.z,  1

Vec3 xAxis = model.worldTransform[0];
model.worldTransform *= xRot;

Vec3 yAxis = model.worldTransform[1];
mode.worldTransform *= yRot;

Edited by Burnt_Fyr