glm returning nan on simple translate

前端 未结 2 817
借酒劲吻你
借酒劲吻你 2020-12-04 03:22

I\'m tinkering with OpenGL using glfw, glad, and glm. In one of the tutorials I\'m using, they demonstrate some simple usage of glm as so:

glm::vec4 vec(1.0f         


        
相关标签:
2条回答
  • 2020-12-04 04:00

    You have to initialize the matrix variable glm::mat4 trans.

    The glm API documentation refers to The OpenGL Shading Language specification 4.20.

    5.4.2 Vector and Matrix Constructors

    If there is a single scalar parameter to a vector constructor, it is used to initialize all components of the constructed vector to that scalar’s value. If there is a single scalar parameter to a matrix constructor, it is used to initialize all the components on the matrix’s diagonal, with the remaining components initialized to 0.0.

    This means, that an identity matrix can be initialized by the single parameter 1.0: glm::mat4(1.0f).

    Change your code somehow like this:

    glm::mat4 trans(1.0f);
    


    See also OpenGL Mathematics (GLM); 2. Vector and Matrix Constructors

    0 讨论(0)
  • 2020-12-04 04:05

    Answering my own question: though the tutorial and other sources said that glm would automatically instantiate an identity vector for

    glm::mat4 trans;
    

    it did not. Looking at a different tutorial, it seems that you can do so explicitly with

    glm::mat4 trans = glm::mat4(1.0f);
    

    And this solved the problem!

    0 讨论(0)
提交回复
热议问题