• Create Account

## Rotate around model's axes

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1steven166  Members

Posted 14 May 2014 - 11:55 PM

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.

### #2phil_t  Members

Posted 15 May 2014 - 12:46 AM

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.

### #3slayemin  Members

Posted 15 May 2014 - 12:59 AM

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.

### #4Burnt_Fyr  Members

Posted 22 May 2014 - 11:10 AM

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];