// use gl to perform the matrix multiplications. using modelview matrix as temp.. Start fresh
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glScaled(...);
glTranslated(...);
if (Angle().x() != 0) glRotatef(Angle().x(),1,0,0);
if (Angle().y() != 0) glRotatef(Angle().y(),0,1,0);
if (Angle().z() != 0) glRotatef(Angle().z(),0,0,1);
GLfloat itemtrans[16];
glGetFloatv(GL_MODELVIEW_MATRIX , itemtrans);
// Restore previous gl matrix
glPopMatrix();
// use gl to perform the matrix multiplications. using modelview matrix as temp.. Start fresh
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glScaled(...);
glTranslated(...);
if (Angle().x() != 0) glRotatef(Angle().x(),1,0,0);
if (Angle().y() != 0) glRotatef(Angle().y(),0,1,0);
if (Angle().z() != 0) glRotatef(Angle().z(),0,0,1);
GLfloat itemtrans[16];
glGetFloatv(GL_MODELVIEW_MATRIX , itemtrans);
// Restore previous gl matrix
glPopMatrix();
To copy to clipboard, switch view to plain text mode
afterwards you can transform this to a QTransform like this:
QTransform GetQTrans(GLfloat* m)
{
// In QTransform the dx and dy are stored in m31 and m32. which is nuts.
// In 4x4 GL they are stored in 03 and 13, so that when you multiply
// with a homogenous (x,y,z,1) vector you get them added automatically.
// Build QTransform of this matrix. QTransform 3x3 recieves the values per row,
// whereas GL saves the 4x4 matrix per column.
// m11 m12 m13 1 2 3 m00 m10 m30 0 1 3
// QT: m21 m22 m23 4 5 6 GL: m01 m11 m31 4 5 7
// dx dy m33 7 8 9 m03 m13 m33 12 13 15
// AAH! QTransform does not use m33, unless the transformation is not affine, m13<>0 and m23 <> 0
QTransform trans;
if (qFuzzyCompare(m[3] + 1, 1) && qFuzzyCompare(m[7] + 1, 1))
trans = QTransform(m[0]/m[15], m[1]/m[15], m[4]/m[15], m[5]/m[15], m[12]/m[15], m[13]/m[15]);
else
trans = QTransform(m[0], m[1], m[3], m[4], m[5], m[7], m[12], m[13], m[15]);
trans.scale(1,-1);
return trans;
}
QTransform GetQTrans(GLfloat* m)
{
// In QTransform the dx and dy are stored in m31 and m32. which is nuts.
// In 4x4 GL they are stored in 03 and 13, so that when you multiply
// with a homogenous (x,y,z,1) vector you get them added automatically.
// Build QTransform of this matrix. QTransform 3x3 recieves the values per row,
// whereas GL saves the 4x4 matrix per column.
// m11 m12 m13 1 2 3 m00 m10 m30 0 1 3
// QT: m21 m22 m23 4 5 6 GL: m01 m11 m31 4 5 7
// dx dy m33 7 8 9 m03 m13 m33 12 13 15
// AAH! QTransform does not use m33, unless the transformation is not affine, m13<>0 and m23 <> 0
QTransform trans;
if (qFuzzyCompare(m[3] + 1, 1) && qFuzzyCompare(m[7] + 1, 1))
trans = QTransform(m[0]/m[15], m[1]/m[15], m[4]/m[15], m[5]/m[15], m[12]/m[15], m[13]/m[15]);
else
trans = QTransform(m[0], m[1], m[3], m[4], m[5], m[7], m[12], m[13], m[15]);
trans.scale(1,-1);
return trans;
}
To copy to clipboard, switch view to plain text mode
For a project sample have a look at this thread
Bookmarks