Phaser.Matrix = function (a, b, c, d, tx, ty){ if (a === undefined || a === null ) { a = 1; } if (b === undefined || b === null ) { b = 0; } if (c === undefined || c === null ) { c = 0; } if (d === undefined || d === null ) { d = 1; } if (tx === undefined || tx === null ) { tx = 0; } if (ty === undefined || ty === null ) { ty = 0; } this.a = a; this.b = b; this.c = c; this.d = d; this.tx = tx; this.ty = ty; this.type = Phaser.MATRIX; } ; Phaser.Matrix.prototype.constructor = Phaser.Matrix; Phaser.Matrix.prototype = { fromArray: function (array){ return this.setTo(array[0], array[1], array[3], array[4], array[2], array[5]); } , setTo: function (a, b, c, d, tx, ty){ this.a = a; this.b = b; this.c = c; this.d = d; this.tx = tx; this.ty = ty; return this; } , clone: function (output){ if (output === undefined || output === null ) { output = new Phaser.Matrix(this.a, this.b, this.c, this.d, this.tx, this.ty); } else { output.a = this.a; output.b = this.b; output.c = this.c; output.d = this.d; output.tx = this.tx; output.ty = this.ty; } return output; } , copyTo: function (matrix){ matrix.copyFrom(this); return matrix; } , copyFrom: function (matrix){ this.a = matrix.a; this.b = matrix.b; this.c = matrix.c; this.d = matrix.d; this.tx = matrix.tx; this.ty = matrix.ty; return this; } , toArray: function (transpose, array){ if (array === undefined) { array = new Float32Array(9); } if (transpose) { array[0] = this.a; array[1] = this.b; array[2] = 0; array[3] = this.c; array[4] = this.d; array[5] = 0; array[6] = this.tx; array[7] = this.ty; array[8] = 1; } else { array[0] = this.a; array[1] = this.c; array[2] = this.tx; array[3] = this.b; array[4] = this.d; array[5] = this.ty; array[6] = 0; array[7] = 0; array[8] = 1; } return array; } , apply: function (pos, newPos){ if (newPos === undefined) { newPos = new Phaser.Point(); } newPos.x = this.a * pos.x + this.c * pos.y + this.tx; newPos.y = this.b * pos.x + this.d * pos.y + this.ty; return newPos; } , applyInverse: function (pos, newPos){ if (newPos === undefined) { newPos = new Phaser.Point(); } var id = 1 / (this.a * this.d + this.c * - this.b); var x = pos.x; var y = pos.y; newPos.x = this.d * id * x + - this.c * id * y + (this.ty * this.c - this.tx * this.d) * id; newPos.y = this.a * id * y + - this.b * id * x + (- this.ty * this.a + this.tx * this.b) * id; return newPos; } , translate: function (x, y){ this.tx += x; this.ty += y; return this; } , scale: function (x, y){ this.a *= x; this.d *= y; this.c *= x; this.b *= y; this.tx *= x; this.ty *= y; return this; } , rotate: function (angle){ var cos = Math.cos(angle); var sin = Math.sin(angle); var a1 = this.a; var c1 = this.c; var tx1 = this.tx; this.a = a1 * cos - this.b * sin; this.b = a1 * sin + this.b * cos; this.c = c1 * cos - this.d * sin; this.d = c1 * sin + this.d * cos; this.tx = tx1 * cos - this.ty * sin; this.ty = tx1 * sin + this.ty * cos; return this; } , 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; this.tx = matrix.tx * a1 + matrix.ty * c1 + this.tx; this.ty = matrix.tx * b1 + matrix.ty * d1 + this.ty; return this; } , identity: function (){ return this.setTo(1, 0, 0, 1, 0, 0); } } ; Phaser.identityMatrix = new Phaser.Matrix(); Phaser.tempMatrix = new Phaser.Matrix();