OpenGL Mathematics
Encyclopedia
GLM is an OpenGL
OpenGL
OpenGL is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL...

 utility library providing to C++ programmer all classes and functions allowing to use data for OpenGL
OpenGL
OpenGL is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL...

 .

One GLM characteristic is that GLM implementation is based on GLSL
GLSL
OpenGL Shading Language , is a high-level shading language based on the syntax of the C programming language...

 (OpenGL Shading Language) specification .

GLM source code is available under the MIT license
MIT License
The MIT License is a free software license originating at the Massachusetts Institute of Technology . It is a permissive license, meaning that it permits reuse within proprietary software provided all copies of the licensed software include a copy of the MIT License terms...

.

Code samples


// Compute a triangle normal:
  1. include


void computeNormal(triangle & Triangle)
{
glm::vec3 const & a = Triangle.Position[0];
glm::vec3 const & b = Triangle.Position[1];
glm::vec3 const & c = Triangle.Position[2];
Triangle.Normal = glm::normalize(glm::cross(c - a, b - a));
}



// Matrix transform:
  1. include // glm::vec3, glm::vec4, glm::ivec4, glm::mat4
  2. include // glm::perspective
  3. include // glm::translate, glm::rotate, glm::scale
  4. include // glm::value_ptr


void transform
{
glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.f);
glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Translate));
glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Rotate.y, glm::vec3(-1.0f, 0.0f, 0.0f));
glm::mat4 View = glm::rotate(ViewRotateX, Rotate.x, glm::vec3(0.0f, 1.0f, 0.0f));
glm::mat4 Model = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f));
glm::mat4 MVP = Projection * View * Model;
glUniformMatrix4fv(LocationMVP, 1, GL_FALSE, glm::value_ptr(MVP));
}
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK