Sign in to follow this  

World Inverse Transpose

This topic is 3155 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

Is this the proper way to set the world inverse transpose matrix? Do I need to normalize anything? I never know when to normalize things. Sometimes it's done to account for floating point error and sometimes its done because it actually makes sense.
//----------------------------------------------------------------------------
void Effect::SetWorldMatrix(const D3DXMATRIX & worldMatrix)
{
   BaseException exception("Not Set", 
                           "void Effect::SetWorldMatrix(const D3DXMATRIX & worldMatrix)",
                           "Effect.cpp");

   // Check for a valid world matrix
   if ( !m_worldMatrix ||
        !m_worldMatrix->IsValid() )
   {
      exception.m_msg = "World matrix effect variable is NULL or invalid. Check that the effect contains a matrix variable named 'world'", 
      throw exception;
   }

   // Check for a valid world inverse transpose matrix
   if( !m_worldInverseTransposeMatrix ||
       !m_worldInverseTransposeMatrix->IsValid() )
   {
      exception.m_msg = "World inverse transpose matrix effect variable is NULL or invalid. Check that the effect contains a matrix variable named 'worldInverseTranspose'", 
      throw exception;
   }

   // Set the world matrix effect variable
   m_worldMatrix->SetMatrix((float *)&worldMatrix);

   // Set the world inverse transpose matrix effect variable
   D3DXMATRIX inverseTranspose;
   float determinant = D3DXMatrixDeterminant(&worldMatrix);
   D3DXMatrixInverse(&inverseTranspose, &determinant, &worldMatrix);
   D3DXMatrixTranspose(&inverseTranspose, &inverseTranspose);

   m_worldInverseTransposeMatrix->SetMatrix((float *)&inverseTranspose);
}

Share this post


Link to post
Share on other sites
Make sure that your only using the 3x3 portion of the matrix that has the rotation and scale. If the world matrix included translation, then the results will not be what you want.

Share this post


Link to post
Share on other sites
So, when my application sets the world inverse transpose matrix, I should do it like this?


// Set the world inverse transpose matrix effect variable
D3DXMATRIX inverseTranspose(worldMatrix);
inverseTranspose._14 = inverseTranspose._24 = inverseTranspose._34 = 0.0f;
inverseTranspose._41 = inverseTranspose._42 = inverseTranspose._43 = 0.0f;
inverseTranspose._44 = 1.0f;

float determinant = D3DXMatrixDeterminant(&inverseTranspose);
D3DXMatrixInverse(&inverseTranspose, &determinant, &inverseTranspose);
D3DXMatrixTranspose(&inverseTranspose, &inverseTranspose);

m_worldInverseTransposeMatrix->SetMatrix((float *)&inverseTranspose);

Share this post


Link to post
Share on other sites

This topic is 3155 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.

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