Jump to content
  • Advertisement
Sign in to follow this  

Rotating volume texture

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone. I'm rendering the volume (IDirect3DVolumeTexture9). To rotate it I use texture transform matrix which is based on quaternions. Everything works fine except that texture rotates around it's local axis but I need it to rotate around the global axis. For example I render the human's head and by default the camera is directed to human's left ear. I say "Rotate around Z axis" (nod the head) and it nods. But when I rotate the head around Y axis and then I say "Rotate around Z axis" I expect the head to tilt towards me but it doesn't - the head nods. The reason for this is quite obvious. When I rotate the texture it's local axis also rotate. But does anybody know what I should do to make my head rotate around global axis? That mean when I say "Rotate around Y axis" - the head must rotate around global Y axis but not around the local one. I have to simulate camera rotation around the head. Here's the code which allows the head to rotate around it's local axis:

//Gets texture transformation matrix.
D3DXMATRIX MyTexture::GetTransformMatrix()
    D3DXMATRIX result;
    D3DXMATRIX transformMatrix;

    //Current texture rotation.
    D3DXQuaternionRotationYawPitchRoll(&quat, D3DXToRadian(m_YawOffset), 
    D3DXToRadian(m_PitchOffset), D3DXToRadian(m_RollOffset));
    m_TransformQuaternion *= quat; //m_TransformQuaternion stores texture     rotation parameters and is updated every time when camera is moved.

    //Because this method is called every time when WM_PAINT
    //these variables need to be set to NULL. Otherwise the camera 
    //will rotate on each WM_PAINT
    m_YawOffset = 0.0f;
    m_PitchOffset = 0.0f;
    m_RollOffset = 0.0f;

    //Converting from quaternion to matrix
    D3DXMatrixRotationQuaternion(&transformMatrix, &m_TransformQuaternion);
    result = transformMatrix;

    return result;

Share this post

Link to post
Share on other sites
I couldn't follow your code out of context, but it sounds like you might just be doing the rotations in the wrong order. Remember that for 3D rotations, a * b is not the same as b * a.

Share this post

Link to post
Share on other sites
You should eliminate the use of Euler angles wherever you can. They cannot fully describe 3D rotations and you will run into problems like gimbal lock, etc. Use either 3x3 matrices or quaternions to represent rotations in 3D. Basically every object has a 3x3 rotation matrix R.

When rotating about each axis:

R = Rx * R (Rx is an x axis rotation matrix)
R = Ry * R (Ry is a y axis rotation matrix)
R = Rz * R (Rz is a z axis rotation matrix)

Depending on which order you apply these transformations, you will get different results. The difference between this approach and the approach you are currently using is that Euler angles will rotate the object but each rotation (x, y, or z) will relative to the previously applied rotation, while the scheme I present will always perform the rotations relative to the global axes.

Note: don't forget to orthonormalize your rotation matrix R every few rotations or else it will become non-orthonormal due to precision errors.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!