OpenGL Mathematics

From Wikipedia, the free encyclopedia

GLM (OpenGL Mathematics) is an OpenGL utility library providing to C++ programmer all classes and functions allowing to use data for OpenGL.

One GLM characteristic is that GLM implementation is based on GLSL (OpenGL Shading Language) specification.

GLM source code is available under MIT license.

[edit] Example

#include <glm/glm.h>
 
using namespace glm;
 
enum
{
    PLANE_LEFT,
    PLANE_RIGHT,
    PLANE_BOTTOM,
    PLANE_TOP,
    PLANE_NEAR,
    PLANE_FAR,
    PLANE_MAX
};
 
vec4 planes[PLANE_MAX];
 
void createFrustumPlanes(const mat4& Model, const mat4& View, const mat4& Projection)
{
    mat4 mvp = transpose(Projection * View * Model);
 
    planes[PLANE_LEFT]   = normalize(mvp[3] + mvp[0]);
    planes[PLANE_RIGHT]  = normalize(mvp[3] - mvp[0]);
    planes[PLANE_BOTTOM] = normalize(mvp[3] + mvp[1]);
    planes[PLANE_TOP]    = normalize(mvp[3] - mvp[1]);
    planes[PLANE_NEAR]   = normalize(mvp[3] + mvp[2]);
    planes[PLANE_FAR]    = normalize(mvp[3] - mvp[2]);
}

[edit] External links

Languages