PDA

View Full Version : Inverse Matrix



ramana
01-29-2004, 04:48 AM
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?

Coconut
01-29-2004, 05:08 AM
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.

ramana
02-01-2004, 09:14 PM
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);

DarkWIng
02-01-2004, 10:26 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

ToolTech
02-02-2004, 12:07 AM
Note that the inverse of a scale with factor zero (0) is non invertible

endash
02-03-2004, 01:12 PM
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.