diff --git a/src/pixi/core/Matrix.js b/src/pixi/core/Matrix.js index ce94c7b..5e73cdd 100644 --- a/src/pixi/core/Matrix.js +++ b/src/pixi/core/Matrix.js @@ -178,20 +178,39 @@ }; +/** + * Translates the matrix on the x and y. + * @method translate + * @param {Number} x + * @param {Number} y + * @return {Matrix} This matrix. Good for chaining method calls. + **/ +PIXI.Matrix.prototype.append = function(matrix) +{ + var a1 = this.a; + var b1 = this.b; + var c1 = this.c; + var d1 = this.d; + this.a = matrix.a * a1 + matrix.b * c1; + this.b = matrix.a * b1 + matrix.b * d1; + this.c = matrix.c * a1 + matrix.d * c1; + this.d = matrix.c * b1 + matrix.d * d1; - -PIXI.identityMatrix = new PIXI.Matrix(); - -PIXI.determineMatrixArrayType = function() { - return (typeof Float32Array !== 'undefined') ? Float32Array : Array; + this.tx = matrix.tx * a1 + matrix.ty * c1 + this.tx; + this.ty = matrix.tx * b1 + matrix.ty * d1 + this.ty; + + return this; }; -/** - * The Matrix2 class will choose the best type of array to use between - * a regular javascript Array and a Float32Array if the latter is available - * - * @class Matrix2 - * @constructor - */ -PIXI.Matrix2 = PIXI.determineMatrixArrayType(); +PIXI.Matrix.prototype.identity = function() +{ + this.a = 1; + this.b = 0; + this.c = 0; + this.d = 1; + this.tx = 0; + this.ty = 0; +}; + +PIXI.identityMatrix = new PIXI.Matrix(); diff --git a/src/pixi/core/Matrix.js b/src/pixi/core/Matrix.js index ce94c7b..5e73cdd 100644 --- a/src/pixi/core/Matrix.js +++ b/src/pixi/core/Matrix.js @@ -178,20 +178,39 @@ }; +/** + * Translates the matrix on the x and y. + * @method translate + * @param {Number} x + * @param {Number} y + * @return {Matrix} This matrix. Good for chaining method calls. + **/ +PIXI.Matrix.prototype.append = function(matrix) +{ + var a1 = this.a; + var b1 = this.b; + var c1 = this.c; + var d1 = this.d; + this.a = matrix.a * a1 + matrix.b * c1; + this.b = matrix.a * b1 + matrix.b * d1; + this.c = matrix.c * a1 + matrix.d * c1; + this.d = matrix.c * b1 + matrix.d * d1; - -PIXI.identityMatrix = new PIXI.Matrix(); - -PIXI.determineMatrixArrayType = function() { - return (typeof Float32Array !== 'undefined') ? Float32Array : Array; + this.tx = matrix.tx * a1 + matrix.ty * c1 + this.tx; + this.ty = matrix.tx * b1 + matrix.ty * d1 + this.ty; + + return this; }; -/** - * The Matrix2 class will choose the best type of array to use between - * a regular javascript Array and a Float32Array if the latter is available - * - * @class Matrix2 - * @constructor - */ -PIXI.Matrix2 = PIXI.determineMatrixArrayType(); +PIXI.Matrix.prototype.identity = function() +{ + this.a = 1; + this.b = 0; + this.c = 0; + this.d = 1; + this.tx = 0; + this.ty = 0; +}; + +PIXI.identityMatrix = new PIXI.Matrix(); diff --git a/test/unit/pixi/core/Matrix.js b/test/unit/pixi/core/Matrix.js index 6f1d838..da75e2e 100644 --- a/test/unit/pixi/core/Matrix.js +++ b/test/unit/pixi/core/Matrix.js @@ -3,10 +3,6 @@ var expect = chai.expect; - it('Ensure determineMatrixArrayType exists', function () { - expect(PIXI.determineMatrixArrayType).to.be.a('function'); - }); - it('Matrix exists', function () { expect(PIXI.Matrix).to.be.an('function'); });