Rotation about the z axis

Started by
3 comments, last by LostSource 17 years, 5 months ago
Hello all, and good morning (well its 7:43 am here). I was hoping that someone would be able to help me solve this problem. See I made a sprite class that will draw a 2D texture in 3d space at any given position. Now the problem is that I'm trying to rotate the sprite by 90 degrees around its own local coordinate space z axis and keep it in the same position. But when I rotate the sprite by 90 degrees around the z axis, it acts like I'm rotating it about the origin z axis, and not by its own z axis. Here is what I'm doing: D3DXVECTOR3 z_axis(0.0f, 0.0f, position.z); D3DXMatrixRotationAxis(&m_hLocalMatrix, &z_axis, 90.0f); pDevice->SetTransform(D3DTS_WORLD, &m_hLocalMatrix); Thanks for the help in advance. = ]
Advertisement
Quote:Original post by LostSource
D3DXVECTOR3 z_axis(0.0f, 0.0f, position.z); // Creates the axis (0, 0, 1)
D3DXMatrixRotationAxis(&m_hLocalMatrix, &z_axis, 90.0f); // Rotates around the axis (0, 0, 1) [Z axis]

I.e. the vector you specify for the axis is exactly the same as the world space Z axis.
I see what you mean. That explains why it is causing to rotation at the (0, 0, 1) world origin. But how would I go about setting it up to rotation around the sprites z axis without having it rotate around the (0, 0, 1)? Because for some reason no matter what position I give it, its only rotating around the (0, 0, 1).

Edit: Searching around on the google, it seems that this question has been asked alot, and I haven't found a solution to rotation around the sprites origin. = /

[Edited by - LostSource on November 7, 2006 8:08:00 AM]
Do you have a set of vertices for each sprite, or do you just use 4 vertices and set a new world translation for each sprite?

If you are just using 4 vertices, make sure that the translation happens *after* the rotation. If I remember correctly, that would mean you need to multiply them in the reverse order, ie:

D3DXMatrix translation();D3DXMatrix rotation();D3DXMatrixTranslation( &translation, position );D3DXMatrixRotationZ( &rotation, 90.0f );m_hLocalMatrix = translation * rotation;pDevice->SetTransform(D3DTS_WORLD, &m_hLocalMatrix);


The function names might not be correct, but you should get the idea.


If your using seperate vertices for each sprite and they are already translated you will have to modify the vertices themselves to rotate them locally. Here is a link to a billboarding tutorial that uses that idea.
http://www.mvps.org/directx/articles/view_oriented_billboards.htm
Thanks Galaximo, I completely forgot about combine matrix transformations to make the final matrix. The rotation works now. The only thing that I want to change is to have the sprite rotate put yet still remain the the same position. So I guess I just need to make a small adjust ment and make the "position" the center "origin" of the sprite.

This topic is closed to new replies.

Advertisement