Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: GLM order of transforms

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2011
    Posts
    11

    GLM order of transforms

    I have an object which I first want to rotate (about it's own center) then translate it to some point. I have a glm::quat that holds the rotation and a glm::vec3 that holds the point to which it needs to be translated.

    Code :
    glm::vec3 position;
    glm::quat orientation;
    glm::mat4 modelmatrix; <-- want to combine them both in here
     
    modelmatrix = glm::translate(glm::toMat4(orientation),position);

    Then at my render function I do..

    Code :
    pvm = projectionMatrix*viewMatrix*modelmatrix;
    glUniformMatrix4fv(pvmMatrixUniformLocation, 1, GL_FALSE, glm::value_ptr(pvm));

    ..and render...

    Unfortunately the object just orbits around the origin when I apply a rotation (the farther the "position" from the origin, the larger the orbit).

    When I apply only the position it translates fine. When I apply only the rotation it stays at the origin and rotates about it's center (as expected). So why does it go weird when I apply them both? Am I missing something basic?

    thanks in advance,

    Jubei

  2. #2
    Super Moderator Frequent Contributor Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    936

    Re: GLM order of transforms

    "pvm = projectionMatrix*viewMatrix*modelmatrix;"

    You created a MVP matrix, not a PVM one... if this matter.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2011
    Posts
    11

    Re: GLM order of transforms

    I was under the impression that GLM::translate , translates the 1st argument based on the 2nd vector. Based on that assumption I thought I was creating a mat4 from the quaternion and then translating it (which is the correct order). That's not the case apparently.

    Thanks groovounet for the suggestion on the pvm, you're right.

  4. #4
    Super Moderator Frequent Contributor Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    936

    Re: GLM order of transforms

    glm::translate is equivalent to creating a translation matrix and multiplying this matrix by the one passed in parameter except that this operation is optimized.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •