Results 1 to 3 of 3

Thread: glRotetef & 4x4 Matrix

  1. #1
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    2
    Qt products
    Qt4

    Red face glRotetef & 4x4 Matrix

    Hi,

    Sorry in advance if this is in the wrong place!

    I just wonder if anyone know how can I decompose a 4x4 transformation matrix (Rotation & translation) into angles & other thing so I can use with glRotatef, glScalef & glTranslationf.

    Thank alot!

  2. #2
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: glRotetef & 4x4 Matrix

    That's a pure OpenGL question, so I highly doubt a Qt forum would be the right place for it...

  3. #3
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: glRotetef & 4x4 Matrix

    Hi!

    I would suggest to do it the other way around. Use OpenGL to setup your matrix!

    Qt Code:
    1. // use gl to perform the matrix multiplications. using modelview matrix as temp.. Start fresh
    2. glMatrixMode(GL_MODELVIEW);
    3. glPushMatrix();
    4. glLoadIdentity();
    5. glScaled(...);
    6. glTranslated(...);
    7. if (Angle().x() != 0) glRotatef(Angle().x(),1,0,0);
    8. if (Angle().y() != 0) glRotatef(Angle().y(),0,1,0);
    9. if (Angle().z() != 0) glRotatef(Angle().z(),0,0,1);
    10.  
    11. GLfloat itemtrans[16];
    12. glGetFloatv(GL_MODELVIEW_MATRIX , itemtrans);
    13.  
    14. // Restore previous gl matrix
    15. glPopMatrix();
    To copy to clipboard, switch view to plain text mode 
    afterwards you can transform this to a QTransform like this:

    Qt Code:
    1. QTransform GetQTrans(GLfloat* m)
    2. {
    3. // In QTransform the dx and dy are stored in m31 and m32. which is nuts.
    4. // In 4x4 GL they are stored in 03 and 13, so that when you multiply
    5. // with a homogenous (x,y,z,1) vector you get them added automatically.
    6.  
    7. // Build QTransform of this matrix. QTransform 3x3 recieves the values per row,
    8. // whereas GL saves the 4x4 matrix per column.
    9. // m11 m12 m13 1 2 3 m00 m10 m30 0 1 3
    10. // QT: m21 m22 m23 4 5 6 GL: m01 m11 m31 4 5 7
    11. // dx dy m33 7 8 9 m03 m13 m33 12 13 15
    12.  
    13. // AAH! QTransform does not use m33, unless the transformation is not affine, m13<>0 and m23 <> 0
    14. QTransform trans;
    15. if (qFuzzyCompare(m[3] + 1, 1) && qFuzzyCompare(m[7] + 1, 1))
    16. 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]);
    17. else
    18. trans = QTransform(m[0], m[1], m[3], m[4], m[5], m[7], m[12], m[13], m[15]);
    19. trans.scale(1,-1);
    20. return trans;
    21. }
    To copy to clipboard, switch view to plain text mode 
    For a project sample have a look at this thread http://www.qtcentre.org/threads/2005...a-tiny-problem

    HIH

    Johannes

Similar Threads

  1. QGraphicsScene and matrix
    By Artturi.Sakari in forum Qt Programming
    Replies: 3
    Last Post: 18th June 2010, 11:49
  2. need help with creating an m x n matrix
    By Petr_Kropotkin in forum General Programming
    Replies: 3
    Last Post: 3rd April 2010, 15:18
  3. matrix for QBrush
    By navi1084 in forum Qt Programming
    Replies: 5
    Last Post: 5th February 2010, 11:27
  4. Dot Matrix Printer
    By estanisgeyer in forum Qt Programming
    Replies: 3
    Last Post: 18th December 2009, 19:30
  5. dynamic matrix of QStrings
    By QiT in forum Newbie
    Replies: 19
    Last Post: 4th April 2007, 09:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.