#### Archived

This topic is now archived and is closed to further replies.

# Rotating objects

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

## Recommended Posts

Hi! I previously asked about rotating object in Direct3d and I also got some answers which said that should do my matrix calculations in right order... I tried but... Well I didn''t manage to do it... So could somebody please give a simple code example of rotating object (a triangle for example) in different locations. And so that the object rotates around it''s own origo not around the world origo which is my problem. Any help would be appreciated. Floru

##### Share on other sites
D3DXMATRIX T,Rx,Ry,Rz;D3DXMatrixRotationZ(&Rz, Roll);D3DXMatrixRotationX(&Rx, Pitch);D3DXMatrixRotationY(&Ry, Yaw);D3DXMatrixTranslation(&T, Pos.x, Pos.y, Pos.z);D3DXMATRIX Transform;D3DXMatrixMultiplication(&Transform, &Rz, &Rx);D3DXMatrixMultiplication(&Transform, &Transform, &Ry);D3DXMatrixMultiplication(&Transform, &Transform, &T);

And there you have it

Of course, if you're really lazy then you can use D3DXMatrixRotationYawPitchRoll() instead of above rotation matrices. It's also a good optimization, although you will probably not notice much difference unless you compute the transformmatrix lots and lots of time during each frame.

Edited by - Spellbound on 3/17/00 6:43:41 AM