Jump to content
  • Advertisement
Sign in to follow this  
TheStudent111

GLM confusion

This topic is 970 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

While messing around glm, I stumbled upon something I need clarification on. I have always knew that GLM and OpenGL followed column major notation. But when I print the matrix out, it looks like its in row major form.

 

#include <iostream>
#include <glm\glm.hpp>
#include <glm\gtc\matrix_transform.hpp>
#include <glm\gtx\string_cast.hpp>

using std::cout;
using std::endl;

int main()
{
    glm::vec3 translate(3.0f, 4.0f, 4.0f);
    glm::mat4 identity(1.0f);
    glm::mat4 model = glm::translate(identity, translate);

    cout << "[0][0]: "  << model[0][0] << "  [0][1]: " << model[0][1] << "  [0][2]: " << model[0][2] <<  "  [0][3]: " << model[0][3] << endl;
    cout << "[1][0]: "  << model[1][0] << "  [1][1]: " << model[1][1] << "  [1][2]: " << model[1][2] <<  "  [1][3]: " << model[1][3] << endl;
    cout << "[2][0]: "  << model[2][0] << "  [2][1]: " << model[2][1] << "  [2][2]: " << model[2][2] <<  "  [2][3]: " << model[2][3] << endl;
    cout << "[3][0]: "  << model[3][0] << "  [3][1]: " << model[3][1] << "  [3][2]: " << model[3][2] <<  "  [3][3]: " << model[3][3] << endl;

    cout << " " << endl;
    cout << glm::to_string(model) << endl;


    system("Pause");
    return 0;
}

 

If you run the above code, the translation column is actually a translation row. This does not make sense, doesn't GLM follow column major. Shouldn't the translation be on [0][3], [1][3], [2][3], instead of [3][0], [3][1], [3][2].

Share this post


Link to post
Share on other sites
Advertisement

I guess that depends how GLM implements operator[]. Often, column-major libraries will implement it as matrix[column][row] instead of the standard convention of matrix[row][column]. If this is true for GLM, then the translation is in the 0/1/2 elements of the column 3, which sounds right.

Share this post


Link to post
Share on other sites

Ok, so

 cout << "[3][0]: "  << model[3][0] << "  [3][1]: " << model[3][1] << "  [3][2]: " << model[3][2] <<  "  [3][3]: " << model[3][3] << endl;

Is actually column 3, and not row 3. If that's the case, then it makes sense. Thanks Hodgman.

 

Side note, do you have links to were I can find how the translation matrix was derived. I can find the derivation of rotation matrix but not translation.

Edited by TheStudent111

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!