GLM: rotation matrix initialisation

喜夏-厌秋 提交于 2020-01-07 09:26:17

问题


The basic aim of my code is just to rotate a few points around the z-axis. However, after trying to initialise a rotation matrix using glm::rotate(m4, a, v3) and trying to check its components, a quick printf outputs some 1 800 000 000.0000000... for each element. I believe this is not the correct functionality.~

Note: I am not asking about the maths behind spatial transformations. They are clear to me.

Code in essence:

int main(int argc, char **argv){
    InitGL(); // openGL, GLFW..
    CreateShaders();            // vertShader: "mat4 trans"-uniform
    GenerateTextures();

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    uniTrans = glGetUniformLocation(shaderProgram, "trans");
    glm::mat4 trans;

    while(!glfwWindowShouldClose(window)){
        glClear(GL_COLOR_BUFFER_BIT);

        trans = glm::rotate(trans, glm::radians(180.0f), glm::vec3(0.0f, 0.0f, 1.0f));
        glUniformMatrix4fv(uniTrans, 1, GL_FALSE, glm::value_ptr(trans));

        glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);

        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    CleanUp();
    glfwDestroyWindow(window);
    glfwTerminate();
    return 0;
}

Program works as intended when the rotation matrix isn't being used. The matrix values were checked with printf("%f", m[0][0]) and so on. Any idea as to where to even start with this? No errors or even warnings are thrown.


回答1:


Self-answer:

The matrices have to be initialised:

glm::mat4 trans(1.0f);

results to an identity matrix.



来源:https://stackoverflow.com/questions/46476551/glm-rotation-matrix-initialisation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!