humbletim / glm-js

JavaScript adaptation of the OpenGL Mathematics (GLM) C++ library interfaces. JavaScript adaptation of the OpenGL Mathematics (GLM) C++ library interfaces. (project currently inactive)
http://humbletim.github.io/glm-js/
Other
43 stars 5 forks source link

glm.ortho is missing #4

Closed Beuc closed 7 years ago

Beuc commented 7 years ago

Hi,

I noticed that glm.ortho is not present in glm-js. C++ GLM implements both glOrtho and gluOrtho2D under the "glm::ortho" function using function overloading. https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glOrtho.xml https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluOrtho2D.xml http://glm.g-truc.net/0.9.8/glm-0.9.8.pdf

I use glOrtho2D to initialize a 2D projection matrix so as to draw sprites.

Beuc commented 7 years ago

AFAICS glOrtho is provided by gl-matrix.js:mat4.ortho and tdl-fast.js:tdl.fast.matrix4.ortho. For three.js it seems it's somewhere in the THREE.OrthographicCamera/THREE.PerspectiveCamera constructors.

For gluOrtho2D here's my take:

    glm.ortho = function(left, right, bottom, top) {
    var ret = Array(16).fill(0);
    ret[0]  = 2 / (right - left);
    ret[5]  = 2 / (top - bottom);
    ret[10] = -1;
    ret[12] = - (right + left) / (right - left);
    ret[13] = - (top + bottom) / (top - bottom);
    ret[15] = 1;
    return glm.mat4(ret);
    }
Beuc commented 7 years ago

Thanks! I just pointed my webgl tests to https://cdn.rawgit.com/humbletim/glm-js/31fd034/build/glm-js.min.js and they now all work without any work-around :)