Sign in to follow this  
Nesta

Rotating volume texture

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.
    D3DXQUATERNION quat;
    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;
}

Any help appriciated.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this