import { ASObject } from '@awayfl/avm2'; import { DataBuffer } from '@awayjs/graphics'; import { Point } from './Point'; import { Vector3D } from './Vector3D'; import { Matrix as AwayMatrix } from '@awayjs/core'; import { SecurityDomain } from '../SecurityDomain'; export class Matrix extends ASObject { private _adaptee: AwayMatrix; static axClass: typeof Matrix; static classInitializer() { this.FROZEN_IDENTITY_MATRIX = Object.freeze(this.axConstruct([])); this.TEMP_MATRIX = this.axConstruct([]); } static classSymbols: string [] = null; // []; static instanceSymbols: string [] = null; // ["a", "b", "c", "d", "tx", "ty", "concat", // "invert", "identity", "createBox", // "createGradientBox", "rotate", "translate", // "scale", "deltaTransformPoint", "transformPoint", // "copyFrom", "setTo", "copyRowTo", "copyColumnTo", // "copyRowFrom", "copyColumnFrom", "clone", // "toString"]; public get adaptee(): AwayMatrix { return this._adaptee; } /** * The value that affects the positioning of pixels along the x axis * when scaling or rotating an image. */ public get a(): number { return this._adaptee.rawData[0]; } public set a(value: number) { this._adaptee.rawData[0] = value; } /** * The value that affects the positioning of pixels along the y axis * when rotating or skewing an image. */ public get b(): number { return this._adaptee.rawData[1]; } public set b(value: number) { this._adaptee.rawData[1] = value; } /** * The value that affects the positioning of pixels along the x axis * when rotating or skewing an image. */ public get c(): number { return this._adaptee.rawData[2]; } public set c(value: number) { this._adaptee.rawData[2] = value; } /** * The value that affects the positioning of pixels along the y axis * when scaling or rotating an image. */ public get d(): number { return this._adaptee.rawData[3]; } public set d(value: number) { this._adaptee.rawData[3] = value; } /** * The distance by which to translate each point along the x axis. */ public get tx(): number { return this._adaptee.rawData[4]; } public set tx(value: number) { this._adaptee.rawData[4] = value; } /** * The distance by which to translate each point along the y axis. */ public get ty(): number { return this._adaptee.rawData[5]; } public set ty(value: number) { this._adaptee.rawData[5] = value; } /** * Creates a new Matrix object with the specified parameters. In matrix * notation, the properties are organized like this: * *
If you do not provide any parameters to the new Matrix()
* constructor, it creates an identity matrix with the following
* values:
In matrix notation, the identity matrix looks like this:
* * @param a The value that affects the positioning of pixels along the * x axis when scaling or rotating an image. * @param b The value that affects the positioning of pixels along the * y axis when rotating or skewing an image. * @param c The value that affects the positioning of pixels along the * x axis when rotating or skewing an image. * @param d The value that affects the positioning of pixels along the * y axis when scaling or rotating an image.. * @param tx The distance by which to translate each point along the x * axis. * @param ty The distance by which to translate each point along the y * axis. */ constructor(aAdaptee: number | AwayMatrix = 1, b: number = 0, c: number = 0, d: number = 1, tx: number = 0, ty: number = 0) { super(); this._adaptee = (aAdaptee instanceof AwayMatrix) ? aAdaptee : new AwayMatrix(+aAdaptee, +b, +c, +d, +tx, +ty); } public static FromUntyped(object: any): Matrix { return new (For example, if matrix m1 scales an object by a factor of
* four, and matrix m2 rotates an object by 1.5707963267949
* radians(Math.PI/2), then m1.concat(m2)
* transforms m1 into a matrix that scales an object by a factor
* of four and rotates the object by Math.PI/2 radians.
This method replaces the source matrix with the concatenated matrix. If
* you want to concatenate two matrixes without altering either of the two
* source matrixes, first copy the source matrix by using the
* clone() method, as shown in the Class Examples section.
After calling the identity() method, the resulting matrix
* has the following properties: a=1, b=0,
* c=0, d=1, tx=0,
* ty=0.
In matrix notation, the identity matrix looks like this:
* */ public identity(): void { this._adaptee.identity(); } /** * Includes parameters for scaling, rotation, and translation. When applied * to a matrix it sets the matrix's values based on those parameters. * *Using the createBox() method lets you obtain the same
* matrix as you would if you applied the identity(),
* rotate(), scale(), and translate()
* methods in succession. For example, mat1.createBox(2,2,Math.PI/4,
* 100, 100) has the same effect as the following:
beginGradientFill() and lineGradientStyle()
* methods of the Graphics class. Width and height are scaled to a
* scaleX/scaleY pair and the
* tx/ty values are offset by half the width and
* height.
*
* For example, consider a gradient with the following * characteristics:
* *GradientType.LINEAR[0,
* 255]SpreadMethod.PADInterpolationMethod.LINEAR_RGBThe following illustrations show gradients in which the matrix was
* defined using the createGradientBox() method with different
* parameter settings:
width parameter.
* @param ty The distance, in pixels, to translate down along the
* y axis. This value is offset by half of the
* height parameter.
*/
public createGradientBox(width: number, height: number,
rotation: number = 0, tx: number = 0, ty: number = 0): void {
this._adaptee.createGradientBox(width, height, rotation, tx, ty);
}
/**
* Applies a rotation transformation to the Matrix object.
*
* The rotate() method alters the a,
* b, c, and d properties of the
* Matrix object. In matrix notation, this is the same as concatenating the
* current matrix with the following:
dx and dy parameters.
*
* @param dx The amount of movement along the x axis to the right, in
* pixels.
* @param dy The amount of movement down along the y axis, in pixels.
*/
public translate(dx: number, dy: number): void {
this._adaptee.translate(dx, dy);
}
/**
* Applies a scaling transformation to the matrix. The x axis is
* multiplied by sx, and the y axis it is multiplied by
* sy.
*
* The scale() method alters the a and
* d properties of the Matrix object. In matrix notation, this
* is the same as concatenating the current matrix with the following
* matrix:
transformPoint()
* method, the deltaTransformPoint() method's transformation
* does not consider the translation parameters tx and
* ty.
*
* @param point The point for which you want to get the result of the matrix
* transformation.
* @return The point resulting from applying the matrix transformation.
*/
public deltaTransformPoint(point: Point): Point {
return new (