From bce7b9c63861ba722ed4e423edf2992ece0d6e27 Mon Sep 17 00:00:00 2001 From: Mike Armstrong Date: Mon, 17 Aug 2015 06:10:20 -0700 Subject: [PATCH] generalise handling of uniforms and samplers --- Libraries/Utilities/MatrixMath.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Libraries/Utilities/MatrixMath.js b/Libraries/Utilities/MatrixMath.js index 6103e1d1e..21ad74ae2 100755 --- a/Libraries/Utilities/MatrixMath.js +++ b/Libraries/Utilities/MatrixMath.js @@ -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);