OpenGL Mathematics (GLM) is a header only C++ mathematics library for graphics software based on the OpenGL Shading Language (GLSL) specifications. GLM provides classes and functions designed and implemented with the same naming conventions and functionality than GLSL so that anyone who knows GLSL, can use GLM as well in C++.
glm::vec3{ }
glm::vec3{ 1.f }
glm::vec3{ 1.f, 2.f, 3.f }
glm::vec4{ glm::vec3{ 1.f, 2.f, 3.f }, 4.f }
GLM uses column major ordering by default.
glm::mat3{ 0.f }
glm::mat3{ 1.f }
glm::mat3{{1.f, 2.f, 3.f},
{4.f, 5.f, 6.f},
{7.f, 8.f, 9.f}}
glm::mat3{glm::vec3{1.f},
glm::vec3{2.f},
{3.f, 3.f, 3.f}}
glm::mat2x3{{1.f, 2.f, 3.f},
{4.f, 5.f, 6.f}};
glm::mat4{ glm::mat3{ 2.f } }
TODO
#include <glm/glm.hpp>
glm::vec3 v1{ 1.f, 2.f, 3.f };
glm::vec3 v2{ 4.f, 5.f, 6.f };
glm::mat3 m1{{1.f, 2.f, 3.f},
{4.f, 5.f, 6.f},
{7.f, 8.f, 9.f}};
glm::mat3 m2{{1.f, 1.f, 1.f},
{2.f, 2.f, 2.f},
{3.f, 3.f, 3.f} };
glm::mat3 m3{{3.f, 3.f, 3.f},
{2.f, 2.f, 2.f},
{1.f, 1.f, 1.f}};
2.f * v1
v1 * v2
glm::dot(v1, v2)
glm::cross(v1, v2)
` m1 * m2`
v1 * m1
m1 * v1
m1 * m2 * m3
glm::radians(x)
glm::degrees(x)
glm::inverse(m)
See GLSL’s functions.
mat4 glm::translate(mat4 m, vec3 pos)
mat4 glm::rotate(mat4 m, vec3 angle, vec3 axis)
mat4 glm::scale(mat4 m, vec3 scale)
mat4 glm::ortho(float left, float right, float bottom, float top, float zNear, float zFar)
mat4 glm::perspective(float fovy, float aspect, float zNear, float zFar)
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
glm::vec3 v1{ 1.f, 2.f, 3.f };
glm::mat3 m1{{1.f, 2.f, 3.f},
{4.f, 5.f, 6.f},
{7.f, 8.f, 9.f}};
float* pV1 = glm::value_ptr(v1); // {1, 2, 3}
float* pM1 = glm::value_ptr(m1); // {1, 2, 3, 4, 5, 6, 7, 8, 9}
float pV2[3]{3.f, 2.f, 1.f};
float pM2[9]{ 3.f, 3.f, 3.f, 2.f, 2.f, 2.f, 1.f, 1.f, 1.f };
glm::vec3 v2{glm::make_vec3(pV2)}; // {3, 2, 1}
glm::mat3 m2{glm::make_mat3(pM2)};
//3 3 3
//2 2 2
//1 1 1