|
@@ -13,8 +13,7 @@ function Matrix(values)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- this.m = null;
|
|
|
- this.reset();
|
|
|
+ this.identity();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -26,10 +25,18 @@ Matrix.prototype.copy = function(mat)
|
|
|
this.m = mat.m.slice(0);
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * Create a new matrix object with a copy of the content of this one.
|
|
|
+ */
|
|
|
+Matrix.prototype.clone = function()
|
|
|
+{
|
|
|
+ return new Matrix(this.m.slice(0))
|
|
|
+};
|
|
|
+
|
|
|
/**
|
|
|
* Reset this matrix to indentity.
|
|
|
*/
|
|
|
-Matrix.prototype.reset = function()
|
|
|
+Matrix.prototype.identity = function()
|
|
|
{
|
|
|
this.m = [1, 0, 0, 1, 0, 0];
|
|
|
};
|
|
@@ -123,6 +130,22 @@ Matrix.prototype.scale = function(sx, sy)
|
|
|
this.m[3] *= sy;
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * Get the scale from the transformation matrix.
|
|
|
+ */
|
|
|
+Matrix.prototype.getScale = function()
|
|
|
+{
|
|
|
+ return new Vector2(this.m[0], this.m[3]);
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * Get the position from the transformation matrix.
|
|
|
+ */
|
|
|
+Matrix.prototype.getPosition = function()
|
|
|
+{
|
|
|
+ return new Vector2(this.m[5], this.m[6]);
|
|
|
+};
|
|
|
+
|
|
|
/**
|
|
|
* Apply skew to this matrix.
|
|
|
*/
|
|
@@ -149,6 +172,17 @@ Matrix.prototype.getInverse = function()
|
|
|
return new Matrix([this.m[3] * d, -this.m[1] * d, -this.m[2] * d, this.m[0] * d, d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]), d * (this.m[1] * this.m[4] - this.m[0] * this.m[5])]);
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * Transform a point using this matrix.
|
|
|
+ */
|
|
|
+Matrix.prototype.transformPoint = function(p)
|
|
|
+{
|
|
|
+ var px = p.x * this.m[0] + p.y * this.m[2] + this.m[4];
|
|
|
+ var py = p.x * this.m[1] + p.y * this.m[3] + this.m[5];
|
|
|
+
|
|
|
+ return new Vector2(px, py);
|
|
|
+};
|
|
|
+
|
|
|
/**
|
|
|
* Set a canvas context to use this transformation.
|
|
|
*/
|
|
@@ -164,14 +198,3 @@ Matrix.prototype.tranformContext = function(context)
|
|
|
{
|
|
|
context.transform(this.m[0], this.m[1], this.m[2], this.m[3], this.m[4], this.m[5]);
|
|
|
};
|
|
|
-
|
|
|
-/**
|
|
|
- * Transform a point using this matrix.
|
|
|
- */
|
|
|
-Matrix.prototype.transformPoint = function(p)
|
|
|
-{
|
|
|
- var px = p.x * this.m[0] + p.y * this.m[2] + this.m[4];
|
|
|
- var py = p.x * this.m[1] + p.y * this.m[3] + this.m[5];
|
|
|
-
|
|
|
- return new Vector2(px, py);
|
|
|
-};
|