Giter Site home page Giter Site logo

glmatrix's People

Contributors

toji avatar

Watchers

James Cloos avatar  avatar

Forkers

constantince

glmatrix's Issues

slerp e lerp

Suggestion imprementação Lerp and slerp.

vec3.lerp = function(vec, vec2, lerp, dest){
dest[0] = vec[0] + lerp * (vec2[0] - vec[0]);
dest[1] = vec[1] + lerp * (vec2[1] - vec[1]);
dest[2] = vec[2] + lerp * (vec2[2] - vec[2]);
}

e 

quat4.slerp = function(quat, quat2, lerp, dest){
var epsilon = 1.0;

var dot = quat[0]*quat2[0] + quat[1]*quat2[1] + quat[2]*quat2[2] + 
quat[3]*quat2[3];
if (dot < 0.0) epsilon = -1.0;

dest[0] = 1.0 - lerp * quat[0] + epision * lerp * quat2[0];
dest[1] = 1.0 - lerp * quat[1] + epision * lerp * quat2[1];
dest[2] = 1.0 - lerp * quat[2] + epision * lerp * quat2[2];
dest[3] = 1.0 - lerp * quat[3] + epision * lerp * quat2[3];
}

Original issue reported on code.google.com by [email protected] on 9 Nov 2010 at 4:23

Revert == 0 to ! optimization

Looks like it is not an optimization after all:

<html>
<script type="text/javascript">


function a(x) {
    if (!x){}
}

function b(x) {
    if (x==0){}
}
var n = 30000000;
var len = 10;
var d=new Date();
do {
       a(0);
}
while(n--);
var e = new Date() -d;
var a = 10;
var n = 30000000;
var len = 10;
var f = new Date();
do {
     b(0);

}
while(--n);
var g = new Date() -f;

alert(e);
alert(g);
</script>
</html>

Original issue reported on code.google.com by [email protected] on 14 Jun 2010 at 6:51

FR: rotateAbout(mat, angle, axis, pivot, dest)

I have a reasonable amount of objects that require translation, rotation, and 
then return to previous matrix.

Not understanding how expensive the different options are, i’ve been doing:
mat4.translate(mvMatrix, [-0.5, 1.5, 0.0]);
mat4.rotate(mvMatrix, degToRad(ryRArm), [1.0, 0.0, 0.0]);
mat4.translate(mvMatrix, [0.5, -1.5, 0.0]);
.. do more ops in area ..

Is it worth introducing that function, or am I being dense? :)

Original issue reported on code.google.com by jdrinkwater on 4 Mar 2011 at 12:56

Using closures much faster than typed arrays

Using javascript closures is faster than typed arrays.
See this benchmark in my clone: 
http://danielheres-glmatrix2.googlecode.com/hg/benchmark/matrix_benchmark.html?r
=a1885c17e9a5e0f319ddf6e31e59e08f7e59ac84

Original issue reported on code.google.com by [email protected] on 28 Dec 2010 at 1:25

type vec4 not defined

I might be mistaken but i turned your library into a closure compiler extern 
file and it complains that type vec4 is not defined in your script

Original issue reported on code.google.com by [email protected] on 18 Oct 2010 at 1:56

Incorrect Comment

Line 1350 says that the current function is mat4.ortho. It is in fact 
mat4.lookAt. Easy fix.

Original issue reported on code.google.com by [email protected] on 18 Mar 2011 at 12:32

Bitshifting instead of multiplying in frustum

mat4.frustum = function(left, right, bottom, top, near, far, dest) {
    dest[0] = near << 1 / (right - left);
    dest[1] = 0;
    dest[2] = 0;
    dest[3] = 0;
    dest[4] = 0;
    dest[5] = near << 1 / (top - bottom);
    dest[6] = 0;
    dest[7] = 0;
    dest[8] = (right + left) / (right - left);
    dest[9] = (top + bottom) / (top - bottom);
    dest[10] = -(far + near) / (far - near);
    dest[11] = -1;
    dest[12] = 0;
    dest[13] = 0;
    dest[14] = -(far * near << 1) / (far - near);
    dest[15] = 0;
    return dest;
};

Shaves about 6% from benchmark here.




Proof with microbenchmark:

<html>
<script type="text/javascript">

var d = new Date();
var i = 100;
for (var a = 0; a < 10000000; a++) {
    var i = i << 1;
}
var e = new Date() - d;

var f = new Date();
var i = 100;
for (var a = 0; a < 10000000; a++) {
    var i = i * 2;
}
var g = new Date() - f;

alert(e);
alert(g);
</script>
</html>

Original issue reported on code.google.com by [email protected] on 5 Jun 2010 at 7:51

/= faster in Chromium, as fast in Minefield

in mat4.lookAt, 

Benchmark:
<html>
<script type="text/javascript">
var q = new WebGLFloatArray(3);
var n = 30000000;
var len = 10;
var d=new Date();
do {
                q[0] = q[0] / len;
                q[1] = q[1] / len;
                q[2] = q[2] / len;
}
while(n--);
var e = new Date() -d;
var a = 10;
var n = 30000000;
var len = 10;
var f = new Date();
do {
                q[0] /= len;
                q[1] /= len;
                q[2] /= len;

}
while(--n);
var g = new Date() -f;

alert(e);
alert(g);
</script>
</html>

Original issue reported on code.google.com by [email protected] on 14 Jun 2010 at 6:26

Unproject

I'm trying to unproject but am having difficulty!

mat4.unproject = function (width, height, maxDepth, minDepth, x, y, 
screenSpace, ProjectionMatrix, ViewMatrix, uv) {
  var scale = mat4.create();
  var invScale = mat4.create();

  scale[0] = width / 2f;
  scale[5] = -height / 2f;
  scale[10] = maxDepth - minDepth;
  scale[12] = x + width / 2f;
  scale[13] = y + height / 2f;
  scale[14] = minDepth;
  scale[15] = 1f;
  mat4.inverse(scale, invScale);

  var us = vec3.create();
  var up = vec3.create();

  mat4.multiplyVec3(invScale, screenSpace, us);
  mat4.multiplyVec3(projectionMatrix, us, up);
  mat4.multiplyVec3(viewMatrix, up, uv);
}

Original issue reported on code.google.com by [email protected] on 21 Jun 2010 at 5:02

Change q[x] = -q[x] to *= -1

Conclusions:
In this benchmark both Minefield and Chromium *= -1 is fastest as suggested in 
quat4.inverse.

<html>
<script type="text/javascript">
var q = new WebGLFloatArray(3);
var n = 30000000;
var d=new Date();
do {
                q[0] *= -1;
                q[1] *= -1;
                q[2] *= -1;
}
while(n--);
var e = new Date() -d;
var a = 10;
var n = 30000000;
var f = new Date();
do {
                q[0] = -q[0];
                q[1] *= -q[1];
                q[2] *= -q[2];

}
while(--n);
var g = new Date() -f;

alert(e);
alert(g);
</script>
</html>

Original issue reported on code.google.com by [email protected] on 14 Jun 2010 at 6:10

Tiny syntax fixes

I fixed some tiny syntax issues with semicolons that JSLint cried about.

Also, I switched from normal equal comparisons (== and !=) to strict equal 
comparisons (=== and !==) because the strict versions are much faster.

Thank you for your work.

Cheers!
Tero

Original issue reported on code.google.com by [email protected] on 18 Mar 2011 at 1:16

Attachments:

There is no transpose for mat3

The calculation of a normal transformation matrix requires a transpose for 
mat3. Currently this can be worked around by doing:

    var normMat = mat3.create();
    mat4.toInverseMat3(mvMatrix, normMat);
    normMat2 = mat3.toMat4(normMat);
    mat4.transpose(normMat);

but this is just annoying. The transpose should be done on the mat3, not the 
mat4.

Original issue reported on code.google.com by [email protected] on 27 Feb 2011 at 10:23

mat4.scale + mat4.inverse

Props on that library! the API is graceful! But I have a bug with the matrix 
scaling :

What steps will reproduce the problem?
1. Scale a ModelView Matrix
2. Inverse and Transpose for the Normal Matrix
3. Specular Lights on normal mapped model looks wrong

What is the expected output? What do you see instead?
There are lights aberations that are not appearing when I don't touch the scale

Original issue reported on code.google.com by [email protected] on 31 Jul 2010 at 4:44

mat4.lookat bug

In mat4.lookat(...),  "return mat4.identity()" should be "return 
mat4.identity(dest)".

In general I think that there you need to make a clearer separation of 
destructive vs non destructive operations eg

function mat4.setIdentity(dest) { ..... return undefined;}

 and 

function mat4.identity() {var dest=mat4.create(); mat4.setIdentity(dest); 
return dest; } 

Also I notice there isn't a quat4.create() method at the moment.

And +1 for unit testing :-)

Original issue reported on code.google.com by Drew.Whitehouse on 24 Jun 2010 at 1:59

.str() issue... you are not printing what you think you want to print.

if you create a matrix, then modify it, then print it, then modify it again and 
print it to console... you will see both logs being identical (to the latest 
state of the matrix you have been modifying) despite the matrix not being the 
same in both logging statements.
A workaround is to call the first console.log() like this:

console.log(mat4.create(testMat));

this way we know that the value printed out to console is the value the matrix 
had at that point in the JavaScript program.


Defining the following helper function is another workaround:

function printVec3 (v) {
    console.log(vec3.create(v));
}

function printVec4 (v) {
    console.log(vec4.create(v));
}


function printMat3 (m) {
    console.log(mat3.create(m));
}

function printMat4 (m) {
    console.log(mat4.create(m));
}

Original issue reported on code.google.com by [email protected] on 6 Apr 2011 at 1:55

Use ![var] instead of [var]==0

It is not exactly the same but it is faster.

Microbenchmark:

<html>
<script type="text/javascript">
var a = 0;

var d=new Date();
for(var x = 0; x < 10000000; x++) {
    if (!a){}
}
var e = new Date() -d;
var f=new Date();
for(var b = 0; b < 10000000; b++) {
    if (a==0){}
}
var g = new Date() -d;
alert(e);
alert(g);
</script>
</html>

Original issue reported on code.google.com by [email protected] on 5 Jun 2010 at 10:33

canvasMatrix plays a bit dirty in the benchmark

What steps will reproduce the problem?
1. try creating a random matrix 
2. notices that it still return a indetity matrix 
3.

What is the expected output? 
randomized matrix

What do you see instead?
a identity matrix

Original issue reported on code.google.com by [email protected] on 2 Mar 2011 at 8:46

quat4.inverse

Lines 1551-1553 (quat4.inverse) contain:

quat[0] *= 1
quat[1] *= 1
quat[2] *= 1

It's clearly a typo, '-'s are missing.

Original issue reported on code.google.com by [email protected] on 6 Apr 2011 at 9:29

mat4.ortho is upside down

The mat4.ortho function is different from the glOrtho implementation (found at 
http://www.opengl.org/sdk/docs/man/xhtml/glOrtho.xml),  which switches the 
positive and negative directions.

Fixed by changing:

1247 dest[12] = (left + right) / rl;
1248 dest[13] = (top + bottom) / tb;
1249 dest[14] = (far + near) / fn;

to:

1247 dest[12] = -(left + right) / rl;
1248 dest[13] = -(top + bottom) / tb;
1249 dest[14] = -(far + near) / fn;

Cheers for the library - it's super useful,
Joe

Original issue reported on code.google.com by [email protected] on 23 Sep 2010 at 3:23

Rotate(x,y,z)

  It is most call convenient to rotate in roll (z), pitch (x), and then yaw (y).

Original issue reported on code.google.com by [email protected] on 19 Jun 2010 at 10:48

api name change suggestion

Perhaps it would be clearer if mat4.multiply was renamed mat4.preMultiply. Then 
have mat4.multiply(A,B) do A*B (instead of B*A), and for completeness set 
mat4.postMultiply = mat4.postMultiply.

Original issue reported on code.google.com by Drew.Whitehouse on 26 Jun 2010 at 7:16

Return null early in inverse 3x3

replace it by something like this:

    var a00 = mat[0], a01 = mat[1], a02 = mat[2];

    var b01 = a22*a11-a12*a21;
        var b11 = -a22*a10+a12*a20;
    var b21 = a21*a10-a11*a20;

    var d = a00 * b01 + a01 * b11 + a02 * b21;
    if (!d) { return null; }

    var a10 = mat[4], a11 = mat[5], a12 = mat[6];
    var a20 = mat[8], a21 = mat[9], a22 = mat[10];

    var b02 = -a22*a01+a02*a21;
    var b03 = a12*a01-a02*a11;
    var b12 = a22*a00-a02*a20;
    var b13 = -a12*a00+a02*a10;
    var b22 = -a21*a00+a01*a20;
    var b23 = a11*a00-a01*a10;



Original issue reported on code.google.com by [email protected] on 4 Jun 2010 at 8:11

More benchmarks

Could You, please, include Sylvester lib in the benchmark?
A few pages uses it for WebGL and I'm interested in the results.

Original issue reported on code.google.com by [email protected] on 1 Mar 2011 at 1:17

dup matrix

very important to use the array dup

mat4.dup = function(mat){
   return new glMatrixArrayType(mat);
}

Original issue reported on code.google.com by [email protected] on 23 Jul 2010 at 1:07

bag usage of << in mat4.frustum

mat4.frustum partially fails for non-integer near parameters, miserably for 
near < 1 (at least on my chromium foo << n = Math.floor(foo) << n)

Original issue reported on code.google.com by [email protected] on 14 Jun 2010 at 8:47

mat4.multiplyVec4 is wrong

dest[4] should be dest[3] in this method and mat[4] should be mat[3]

mat4.multiplyVec4 = function(mat, vec, dest) {
        if(!dest) { dest = vec }

        var x = vec[0], y = vec[1], z = vec[2], w = vec[3];

        dest[0] = mat[0]*x + mat[4]*y + mat[8]*z + mat[12]*w;
        dest[1] = mat[1]*x + mat[5]*y + mat[9]*z + mat[13]*w;
        dest[2] = mat[2]*x + mat[6]*y + mat[10]*z + mat[14]*w;
/* Here is the error: dest[4] should be dest[3] and mat[4] should be mat[3]*/
        dest[4] = mat[4]*x + mat[7]*y + mat[11]*z + mat[15]*w;

        return dest;
};


Original issue reported on code.google.com by [email protected] on 18 Dec 2010 at 4:46

Include vec4 math.

vec4 objects are handy for storing points with the W component, as well as 
vertex color, and other things.

you support vec4 in the mat4 functions, but dont specifically declare the vec4's

Original issue reported on code.google.com by [email protected] on 29 Mar 2011 at 12:45

Do not create new var for 1/len but use the same var

Much faster in Chromium (about 40%), slower in Minefield. Strange.

<html>
<script type="text/javascript">
var n = 30000000;
var len = 10;
var d=new Date();
do {
                var l = 10;
                var il = 1/l;
}
while(n--);
var e = new Date() -d;
var n = 30000000;
var len = 10;
var f = new Date();
do {
                var l = 10;
                l = 1/l;

}
while(--n);
var g = new Date() -f;

alert(e);
alert(g);
</script>
</html>

Original issue reported on code.google.com by [email protected] on 14 Jun 2010 at 6:31

unit testing

We will need some sort of unit testing if this wants to be easily testable

Original issue reported on code.google.com by [email protected] on 23 Jun 2010 at 8:29

Some additions

Hi, I'm using the glmatrix library in my WebGL lib, and I added a bunch of 
stuff to it (vec2, slightly more complete mat3 & vec3, object create count 
logging). 

See https://github.com/kig/magi/blob/master/src/matrix.js 
and pick whatever you like. 

Some of the new things aren't probably something you'd want (like setLeft(dest, 
src), and I think mat4.billboard is broken), but maybe there's something of use.

Original issue reported on code.google.com by [email protected] on 27 Feb 2011 at 11:01

Alternative fast method with all vars for each matrix

about 4 times faster here

Just for fun :) The callback is to compensate for the lack of multiple
return values.

mat4.multiply = function(a00, a01, a02, a03, a10, a11, a12, a13, a20, a21,
a22, a23, a30, a31, a32, a33, b00, b01, b02, b03, b10, b11, b12, b13, b20,
b21, b22, b23, b30, b31, b32, b33, callback) {

    callback(b00 * a00 + b01 * a10 + b02 * a20 + b03 * a30,
    b00 * a01 + b01 * a11 + b02 * a21 + b03 * a31,
    b00 * a02 + b01 * a12 + b02 * a22 + b03 * a32,
    b00 * a03 + b01 * a13 + b02 * a23 + b03 * a33,
    b10 * a00 + b11 * a10 + b12 * a20 + b13 * a30,
    b10 * a01 + b11 * a11 + b12 * a21 + b13 * a31,
    b10 * a02 + b11 * a12 + b12 * a22 + b13 * a32,
    b10 * a03 + b11 * a13 + b12 * a23 + b13 * a33,
    b20 * a00 + b21 * a10 + b22 * a20 + b23 * a30,
    b20 * a01 + b21 * a11 + b22 * a21 + b23 * a31,
    b20 * a02 + b21 * a12 + b22 * a22 + b23 * a32,
    b20 * a03 + b21 * a13 + b22 * a23 + b23 * a33,
    b30 * a00 + b31 * a10 + b32 * a20 + b33 * a30,
    b30 * a01 + b31 * a11 + b32 * a21 + b33 * a31,
    b30 * a02 + b31 * a12 + b32 * a22 + b33 * a32,
    b30 * a03 + b31 * a13 + b32 * a23 + b33 * a33);
};


benchmark:


                { name: 'glMatrix', test: function(count) {
                        var a = 5.0;var b = 1.0;var c = 2.0;var d = 4.0;var e = 5.0;var f =
6.0;var g = 2.0;var h = 0.0;var i = 8.0;var j = 10.0;var k = 2.0;var l =
3.0;var m = 4.0;var n = 5.0;var o = 6.0;var p = 7.0;var q = 8.0;var r =
9.0;var s = 10.0;var t = 2.0;var u = 3.0;var v = 4.0;var w = 5.0;var x =
6.0;var y = 7.0;var z = 2.0;var A = 3.0;var B = 4.0;var C = 5.0;var D =
6.0;var E = 7.0;var F = 2.0;
                        function cb(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s,
t, u, v, w, x, y, z, A, B, C, D, E, F){}
                        var start = Date.now();
                        for (var i = 0; i < count; ++i) {
                            mat4.multiply(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r,
s, t, u, v, w, x, y, z, A, B, C, D, E, F, cb);
                        }

                        return Date.now()-start;
                    }},

Original issue reported on code.google.com by [email protected] on 5 Jun 2010 at 8:47

implemented possible feature: graphs for the benchmarks

Hi Brandon,

I was working with the JavaScript graphing library flotr and needed to pick a 
matrix library for some webgl work so I first played with and then adapted the 
benchmarks you created in your glmatrix library: 
https://glmatrix.googlecode.com/hg/.

My changes include:
- I'm only including the benchmarks.
- I've updated to the latest mjs as of Dec 15: 16:8e5b0944ef1e and included it 
in several more tests.
- I've also added a graph display of the results using flotr, see: 
http://solutoire.com/flotr/

My fork of these benchmarks are available here: 
https://github.com/stepheneb/webgl-matrix-benchmarks

And you can run them in a browser with webgl at this url: 
http://stepheneb.github.com/webgl-matrix-benchmarks/matrix_benchmark.html

The somewhat lame reason this is a fork is that it was taking me longer thanI 
wanted using mercurial (don't use hg much) to follow the typical workflow I use 
on github, fork a repo, push my changes into a branch and send a pull request 
to the original developer ...

I've made a branch in my hg checkout of your code with these changes but ... it 
wasn't clear to me the simplest way to share these with you.

I was quite interested in sharing my results because I found that glmatrix and 
mjs are about 5x faster in Minefield than Chrome ... and about twice as fast in 
Chrome than in a WebKit nightly -- I posted a message to 
[email protected] asking people there if they thought these results were 
reasonable. 

They surprised me ...

Original issue reported on code.google.com by [email protected] on 14 Feb 2011 at 5:05

avoid i / len

in mat4.rotate:

        if (len != 1) {
                var ilen = 1 / len;
                x *= ilen; y *= ilen; z *= ilen;
        }

to 
        if (len != 1) {
                x /= len; y /= len; z /= len;
        }



and vec3.normalize:

                dest[0] = x / len;
                dest[1] = y / len;
                dest[2] = z / len;

Original issue reported on code.google.com by [email protected] on 5 Jun 2010 at 10:05

Return as early as possible

for example

vec3.add = function(vec, vec2, dest) {
        if(!dest) { dest = vec; }

        if(vec == dest) {
                dest[0] += vec2[0];
                dest[1] += vec2[1];
                dest[2] += vec2[2];
        } else {
                dest[0] = vec[0] + vec2[0];
                dest[1] = vec[1] + vec2[1];
                dest[2] = vec[2] + vec2[2];
        }

        return dest;
}
could be

vec3.add = function(vec, vec2, dest) {
        if(!dest) {
                var dest = vec;
                dest[0] += vec2[0];
                dest[1] += vec2[1];
                dest[2] += vec2[2];
                return dest; 
        }

        if(vec == dest) {
                dest[0] += vec2[0];
                dest[1] += vec2[1];
                dest[2] += vec2[2];
                return dest;
        }

        dest[0] = vec[0] + vec2[0];
        dest[1] = vec[1] + vec2[1];
        dest[2] = vec[2] + vec2[2];
        return dest;
        }
}

Original issue reported on code.google.com by [email protected] on 4 Jun 2010 at 7:18

Inline dests in mat4.lookAt

Something like this (didn't test it)?

mat4.lookAt = function(eye, center, up, dest) {
        var eyex = eye[0],
                eyey = eye[1],
                eyez = eye[2],
                upx = up[0],
                upy = up[1],
                upz = up[2],
                centerx = center[0],
                centery = center[1],
                centerz = center[2];

        if (eyex == centerx && eyey == centery && eyez == centerz) {
                        return mat4.identity();
        }

        var z0,z1,z2,x0,x1,x2,y0,y1,y2,len;

        //vec3.direction(eye, center, z);
        z0 = eyex - center[0];
        z1 = eyey - center[1];
        z2 = eyez - center[2];

        // normalize (no check needed for 0 becuase of early return)
        len = Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);
        z0 = z0/len;
        z1 = z1/len;
        z2 = z2/len;

        //vec3.normalize(vec3.cross(up, z, x));
        x0 = upy * z2 - upz * z1;
        x1 = upz * z0 - upx * z2;
        x2 = upx * z1 - upy * z0;
        len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);
        if (!len) {
                dest[0] = 0;
                dest[4] = 0;
                dest[8] = 0;
                dest[12] = 0;
        } else {
                x0 = x0/len;
                x1 = x1/len;
                x2 = x2/len;
                dest[0] = x0;
                dest[4] = x1;
                dest[8] = x2;
                dest[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);
        };

        //vec3.normalize(vec3.cross(z, x, y));
        y0 = z1 * x2 - z2 * x1;
        y1 = z2 * x0 - z0 * x2;
        y2 = z0 * x1 - z1 * x0;

        len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
        if (!len) {
                dest[1] = 0;
                dest[5] = 0;
                dest[9] = 0;
                dest[13] = 0;
        } else {
                y0 = y0/len;
                y1 = y1/len;
                y2 = y2/len;
                dest[1] = y0;
                dest[5] = y1;
                dest[9] = y2;
                dest[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);
        }        

        dest[2] = z0;
        dest[3] = 0;
        dest[6] = z1;
        dest[7] = 0;
        dest[10] = z2;
        dest[11] = 0;
        dest[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
        dest[15] = 1;

        return dest;
};

Original issue reported on code.google.com by [email protected] on 14 Jun 2010 at 6:09

Use inverse and bitshifting for ortho

Didn't test / benchmark it, maybe it's slower.

mat4.ortho = function(left, right, bottom, top, near, far, dest) {
        var lmr = 1 / (left - right);
        var tmb = 1 / (top - bottom);
        dest[0] = lmr << 1;
        dest[1] = 0;
        dest[2] = 0;
        dest[3] = 0;
        dest[4] = 0;
        dest[5] = tmb << 1;
        dest[6] = 0;
        dest[7] = 0;
        dest[8] = 0;
        dest[9] = 0;
        dest[10] = -2 / (far - near);
        dest[11] = 0;
        dest[12] = (left + right) * lmr;
        dest[13] = (top + bottom) * tmb;
        dest[14] = (far + near) / (far - near);
        dest[15] = 1;
        return dest;
};

OR

mat4.ortho = function(left, right, bottom, top, near, far, dest) {
        var lmr = 1 / (left - right);
        var tmb = 1 / (top - bottom);
        var fmn = 1 / (far - near);
        dest[0] = lmr << 1;
        dest[1] = 0;
        dest[2] = 0;
        dest[3] = 0;
        dest[4] = 0;
        dest[5] = tmb << 1;
        dest[6] = 0;
        dest[7] = 0;
        dest[8] = 0;
        dest[9] = 0;
        dest[10] = -2 * fmn;
        dest[11] = 0;
        dest[12] = (left + right) * lmr;
        dest[13] = (top + bottom) * tmb;
        dest[14] = (far + near) * fmn;
        dest[15] = 1;
        return dest;
};

OR maybe with
dest[10] = ~fmn << 1 + 1;

(~ changes the sign)

Original issue reported on code.google.com by [email protected] on 7 Jun 2010 at 10:14

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.