2020-07-23 11:00:46 +08:00
|
|
|
|
module es {
|
2020-06-08 11:49:45 +08:00
|
|
|
|
/**
|
2020-07-23 11:00:46 +08:00
|
|
|
|
* 表示右手3 * 3的浮点矩阵,可以存储平移、缩放和旋转信息。
|
2020-06-08 11:49:45 +08:00
|
|
|
|
*/
|
2020-07-23 13:25:10 +08:00
|
|
|
|
export class Matrix2D extends egret.Matrix{
|
|
|
|
|
|
public get m11(): number{
|
|
|
|
|
|
return this.a;
|
2020-07-23 11:00:46 +08:00
|
|
|
|
}
|
2020-07-23 13:25:10 +08:00
|
|
|
|
public set m11(value: number){
|
|
|
|
|
|
this.a = value;
|
2020-07-23 11:00:46 +08:00
|
|
|
|
}
|
2020-07-23 13:25:10 +08:00
|
|
|
|
public get m12(): number{
|
|
|
|
|
|
return this.b;
|
2020-07-23 11:00:46 +08:00
|
|
|
|
}
|
2020-07-23 13:25:10 +08:00
|
|
|
|
public set m12(value: number){
|
|
|
|
|
|
this.b = value;
|
2020-07-23 11:00:46 +08:00
|
|
|
|
}
|
2020-07-23 13:25:10 +08:00
|
|
|
|
public get m21(): number{
|
|
|
|
|
|
return this.c;
|
|
|
|
|
|
}
|
|
|
|
|
|
public set m21(value: number){
|
|
|
|
|
|
this.c = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
public get m22(): number{
|
|
|
|
|
|
return this.d;
|
|
|
|
|
|
}
|
|
|
|
|
|
public set m22(value: number){
|
|
|
|
|
|
this.d = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
public get m31(): number {
|
|
|
|
|
|
return this.tx;
|
|
|
|
|
|
}
|
|
|
|
|
|
public set m31(value: number){
|
|
|
|
|
|
this.tx = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
public get m32(): number{
|
|
|
|
|
|
return this.ty;
|
|
|
|
|
|
}
|
|
|
|
|
|
public set m32(value: number){
|
|
|
|
|
|
this.ty = value;
|
2020-07-23 11:00:46 +08:00
|
|
|
|
}
|
2020-06-08 11:49:45 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
public static create(): Matrix2D{
|
|
|
|
|
|
return egret.Matrix.create() as Matrix2D;
|
|
|
|
|
|
}
|
2020-06-08 11:49:45 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
public identity(): Matrix2D{
|
|
|
|
|
|
super.identity();
|
|
|
|
|
|
return this;
|
2020-07-23 11:00:46 +08:00
|
|
|
|
}
|
2020-06-08 11:49:45 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
public translate(dx: number, dy: number): Matrix2D {
|
|
|
|
|
|
super.translate(dx, dy);
|
|
|
|
|
|
return this;
|
2020-07-23 11:00:46 +08:00
|
|
|
|
}
|
2020-06-08 11:49:45 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
public scale(sx: number, sy: number): Matrix2D {
|
|
|
|
|
|
super.scale(sx, sy);
|
|
|
|
|
|
return this;
|
2020-07-23 11:00:46 +08:00
|
|
|
|
}
|
2020-06-08 11:49:45 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
public rotate(angle: number): Matrix2D {
|
|
|
|
|
|
super.rotate(angle);
|
|
|
|
|
|
return this;
|
2020-07-23 11:00:46 +08:00
|
|
|
|
}
|
2020-06-08 11:49:45 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
public invert(): Matrix2D {
|
|
|
|
|
|
super.invert();
|
|
|
|
|
|
return this;
|
2020-07-23 11:00:46 +08:00
|
|
|
|
}
|
2020-06-08 11:49:45 +08:00
|
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 创建一个新的matrix, 它包含两个矩阵的和。
|
2020-07-23 13:25:10 +08:00
|
|
|
|
* @param matrix
|
2020-07-23 11:00:46 +08:00
|
|
|
|
*/
|
2020-07-23 13:25:10 +08:00
|
|
|
|
public add(matrix: Matrix2D): Matrix2D{
|
|
|
|
|
|
this.m11 += matrix.m11;
|
|
|
|
|
|
this.m12 += matrix.m12;
|
2020-06-08 11:49:45 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
this.m21 += matrix.m21;
|
|
|
|
|
|
this.m22 += matrix.m22;
|
2020-06-08 11:49:45 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
this.m31 += matrix.m31;
|
|
|
|
|
|
this.m32 += matrix.m32;
|
2020-06-08 11:49:45 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
return this;
|
2020-07-23 11:00:46 +08:00
|
|
|
|
}
|
2020-06-19 00:38:37 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
public substract(matrix: Matrix2D): Matrix2D {
|
|
|
|
|
|
this.m11 -= matrix.m11;
|
|
|
|
|
|
this.m12 -= matrix.m12;
|
2020-06-08 11:49:45 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
this.m21 -= matrix.m21;
|
|
|
|
|
|
this.m22 -= matrix.m22;
|
2020-06-08 11:49:45 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
this.m31 -= matrix.m31;
|
|
|
|
|
|
this.m32 -= matrix.m32;
|
2020-06-08 11:49:45 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
return this;
|
2020-07-23 11:00:46 +08:00
|
|
|
|
}
|
2020-06-08 16:23:48 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
public divide(matrix: Matrix2D): Matrix2D{
|
|
|
|
|
|
this.m11 /= matrix.m11;
|
|
|
|
|
|
this.m12 /= matrix.m12;
|
2020-06-08 16:23:48 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
this.m21 /= matrix.m21;
|
|
|
|
|
|
this.m22 /= matrix.m22;
|
2020-06-08 16:23:48 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
this.m31 /= matrix.m31;
|
|
|
|
|
|
this.m32 /= matrix.m32;
|
2020-06-08 16:23:48 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
return this;
|
2020-07-23 11:00:46 +08:00
|
|
|
|
}
|
2020-06-08 16:23:48 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
public multiply(matrix: Matrix2D): Matrix2D{
|
|
|
|
|
|
let m11 = ( this.m11 * matrix.m11 ) + ( this.m12 * matrix.m21 );
|
|
|
|
|
|
let m12 = ( this.m11 * matrix.m12 ) + ( this.m12 * matrix.m22 );
|
2020-06-08 16:23:48 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
let m21 = ( this.m21 * matrix.m11 ) + ( this.m22 * matrix.m21 );
|
|
|
|
|
|
let m22 = ( this.m21 * matrix.m12 ) + ( this.m22 * matrix.m22 );
|
2020-06-08 16:23:48 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
let m31 = ( this.m31 * matrix.m11 ) + ( this.m32 * matrix.m21 ) + matrix.m31;
|
|
|
|
|
|
let m32 = ( this.m31 * matrix.m12 ) + ( this.m32 * matrix.m22 ) + matrix.m32;
|
2020-06-08 16:23:48 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
this.m11 = m11;
|
|
|
|
|
|
this.m12 = m12;
|
2020-07-08 18:12:17 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
this.m21 = m21;
|
|
|
|
|
|
this.m22 = m22;
|
2020-06-08 16:23:48 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
this.m31 = m31;
|
|
|
|
|
|
this.m32 = m32;
|
2020-06-08 16:23:48 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
return this;
|
2020-07-23 11:00:46 +08:00
|
|
|
|
}
|
2020-06-08 16:23:48 +08:00
|
|
|
|
|
2020-07-23 13:25:10 +08:00
|
|
|
|
public determinant(){
|
|
|
|
|
|
return this.m11 * this.m22 - this.m12 * this.m21;
|
2020-07-23 11:00:46 +08:00
|
|
|
|
}
|
2020-06-29 15:41:02 +08:00
|
|
|
|
}
|
2020-07-23 11:00:46 +08:00
|
|
|
|
}
|