OpenGL Mathematics

bibliothèque logicielle

GLM (OpenGL Mathematics) est une bibliothèque libre utilitaire d'OpenGL apportant au programmeur C++ tout un ensemble de classes et de fonctions permettant de manipuler les données pour OpenGL.

Une spécificité de GLM, par rapport aux autres bibliothèques mathématiques, repose sur le fait que son implémentation est basée sur les spécifications de GLSL (OpenGL Shading Language) de manière très stricte offrant ainsi un confort d'utilisation similaire sans nécessiter d'apprendre une nouvelle API.

Le code source est disponible sous MIT.

Exemple modifier

#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]);
}

Lien externe modifier