Inverse Matrix

Hi, I need to find the inverse matrix for the following transformations.

glTranslatef(float(m_ptPos.x), float(m_ptPos.y), 0.0f);
glTranslatef(float(float(m_nWidth))/2.0f, float(float(m_nHeight))/2.0f, 0.0f);
glRotatef(m_fAngle, 0.0f, 0.0f, 1.0f);
glRotatef(m_fFlipHorizontal, 0.0f, 1.0f, 0.0f);
glRotatef(m_fFlipVertical, 1.0f, 0.0f, 0.0f);
glScalef(m_fHorizontalScale, 1.0f, 0.0f);
glScalef(1.0f, m_fVerticalScale, 0.0f);
glTranslatef(-float(float(m_nWidth))/2.0f, -float(float(m_nHeight))/2.0f, 0.0f);

Can anybody tell me, how to find the inverse transformations?

Reverse the order of all those gl calls.
For glTranslate, negate all the arguments.
For glRotate, negate the angles.
For glScale, replace the scales by reciprocals.

I am using this code for getting the inverse,
but I didn’t get:

glTranslatef(float(float(m_nWidth))/2.0f, float(float(m_nHeight))/2.0f, 0.0f);
glScalef(1.0f, 1.0f/m_fVerticalScale, 0.0f);
glScalef(1.0f/m_fHorizontalScale, 1.0f, 0.0f);
glRotatef(-m_fFlipVertical, 1.0f, 0.0f, 0.0f);
glRotatef(-m_fFlipHorizontal, 0.0f, 1.0f, 0.0f);
glRotatef(-m_fAngle, 0.0f, 0.0f, 1.0f);
glRotatef(-180.0f, 1.0f, 0.0f, 0.0f);
glTranslatef(-float(float(m_nWidth))/2.0f, -float(float(m_nHeight))/2.0f, 0.0f);
glTranslatef(-float(m_ptPos.x), -float(m_ptPos.y), 0.0f);

A bit OT:


glTranslatef(float(float(m_nWidth))/2.0f, float(float(m_nHeight))/2.0f, 0.0f);

You don’t need cast to float twice. Once will do

Note that the inverse of a scale with factor zero (0) is non invertible

ToolTech is right.

But why do you need to invert that transformation? I’m suspicious you might just need to push and pop the matrix.