diff --git a/README.md b/README.md index f362ec9..5b23b34 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ ### How to build ### -PixiJS is build with Grunt. If you don't already have this, go install Node and NPM then install the Grunt Command Line. +PixiJS is built with Grunt. If you don't already have this, go install Node and NPM then install the Grunt Command Line. ``` $> npm install -g grunt-cli diff --git a/README.md b/README.md index f362ec9..5b23b34 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ ### How to build ### -PixiJS is build with Grunt. If you don't already have this, go install Node and NPM then install the Grunt Command Line. +PixiJS is built with Grunt. If you don't already have this, go install Node and NPM then install the Grunt Command Line. ``` $> npm install -g grunt-cli diff --git a/src/pixi/core/Matrix.js b/src/pixi/core/Matrix.js index cc4ebe2..7416d20 100644 --- a/src/pixi/core/Matrix.js +++ b/src/pixi/core/Matrix.js @@ -78,6 +78,45 @@ return array; }; +/** + * Get a new position with the current transormation applied. + * Can be used to go from a child's coordinate space to the world coordinate space. (e.g. rendering) + * + * @method apply + * @param pos {Point} The origin + * @param [newPos] {Point} The point that the new position is assigned to (allowed to be same as input) + * @return {Point} The new point, transformed trough this matrix + */ +PIXI.Matrix.prototype.apply = function(pos, newPos) +{ + newPos = newPos || new PIXI.Point(); + + newPos.x = this.a * pos.x + this.b * pos.y + this.tx; + newPos.y = this.c * pos.x + this.d * pos.y + this.ty; + + return newPos; +}; + +/** + * Get a new position with the inverse of the current transormation applied. + * Can be used to go from the world coordinate space to a child's coordinate space. (e.g. input) + * + * @method apply + * @param pos {Point} The origin + * @param [newPos] {Point} The point that the new position is assigned to (allowed to be same as input) + * @return {Point} The new point, inverse-transformed trough this matrix + */ +PIXI.Matrix.prototype.applyInverse = function(pos, newPos) +{ + newPos = newPos || new PIXI.Point(); + + var id = 1 / (this.a * this.d + this.b * -this.c); + newPos.x = this.d * id * pos.x - this.b * id * pos.y + (this.ty * this.b - this.tx * this.d) * id; + newPos.y = this.a * id * pos.y - this.c * id * pos.x + (this.tx * this.c - this.ty * this.a) * id; + + return newPos; +}; + PIXI.identityMatrix = new PIXI.Matrix(); PIXI.determineMatrixArrayType = function() {