generalise handling of uniforms and samplers

This commit is contained in:
Mike Armstrong 2015-08-17 06:10:20 -07:00
parent 65713992c4
commit bce7b9c638
1 changed files with 30 additions and 0 deletions

View File

@ -31,6 +31,23 @@ var MatrixMath = {
];
},
createOrthographic: function(left, right, bottom, top, near, far) {
var a = 2 / (right - left);
var b = 2 / (top - bottom);
var c = -2 / (far - near);
var tx = -(right + left) / (right - left);
var ty = -(top + bottom) / (top - bottom);
var tz = -(far + near) / (far - near);
return [
a, 0, 0, 0,
0, b, 0, 0,
0, 0, c, 0,
tx, ty, tz, 1
];
},
createFrustum: function(left, right, bottom, top, near, far) {
var r_width = 1 / (right - left);
var r_height = 1 / (top - bottom);
@ -49,6 +66,19 @@ var MatrixMath = {
];
},
createPerspective: function(fovInRadians, aspect, near, far) {
var h = 1 / Math.tan(fovInRadians);
var r_depth = 1 / (near - far);
var C = (far + near) * r_depth;
var D = 2 * (far * near * r_depth);
return [
h/aspect, 0, 0, 0,
0, h, 0, 0,
0, 0, C,-1,
0, 0, D, 0,
];
},
createTranslate2d: function(x, y) {
var mat = MatrixMath.createIdentityMatrix();
MatrixMath.reuseTranslate2dCommand(mat, x, y);