55 */
66
77module Display {
8- export class Matrix {
8+ export class Matrix implements Display . ISerializable {
99 private _data :Array < number > ;
1010
1111 constructor ( a :number = 1 , b :number = 0 , c :number = 0 , d :number = 1 , tx :number = 0 , ty :number = 0 ) {
1212 this . _data = [ a , c , tx , b , d , ty , 0 , 0 , 1 ] ;
1313 }
1414
15+ private dotProduct ( o :Array < number > ) :Array < number > {
16+ if ( other . length < 9 ) {
17+ throw new Error ( "Matrix dot product expects a matrix" ) ;
18+ }
19+ var res :Array < number > = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ;
20+ for ( var i = 0 ; i < 3 ; i ++ ) {
21+ for ( var j = 0 ; j < 3 ; j ++ ) {
22+ for ( var k = 0 ; k < 3 ; k ++ ) {
23+ res [ i * 3 + j ] += this . _data [ i * 3 + k ] * o [ k * 3 + j ] ;
24+ }
25+ }
26+ }
27+ return res ;
28+ }
29+
1530 public setTo ( a :number = 1 , b :number = 0 , c :number = 0 , d :number = 1 , tx :number = 0 , ty :number = 0 ) :void {
1631 this . _data = [ a , c , tx , b , d , ty , 0 , 0 , 1 ] ;
1732 }
1833
34+ public translate ( tX :number , tY :number ) :void {
35+ this . _data [ 2 ] += tX ;
36+ this . _data [ 5 ] += tY ;
37+ }
38+
39+ public rotate ( q :number ) :void {
40+ this . _data = this . dotProduct ( [
41+ Math . cos ( q ) , - Math . sin ( q ) , 0 ,
42+ Math . sin ( q ) , Math . cos ( q ) , 0 ,
43+ 0 , 0 , 1
44+ ] ) ;
45+ }
46+
47+ public scale ( sx :number , sy :number ) :void {
48+ this . _data = this . dotProduct ( [
49+ sx , 0 , 0 ,
50+ 0 , sy , 0 ,
51+ 0 , 0 , 1
52+ ] ) ;
53+ }
54+
1955 public identity ( ) :void {
2056 this . setTo ( 1 , 0 , 0 , 1 , 0 , 0 ) ;
2157 }
2258
59+ public createBox ( sX :number , sY :number , q :number , tX :number , tY :number ) :void {
60+ this . identity ( ) ;
61+ this . rotate ( q ) ;
62+ this . scale ( sX , sY ) ;
63+ this . translate ( tX , tY ) ;
64+ }
2365 public clone ( ) :Matrix {
2466 var a :number = this . _data [ 0 ] ,
2567 b :number = this . _data [ 3 ] ,
@@ -29,9 +71,13 @@ module Display {
2971 ty :number = this . _data [ 5 ] ;
3072 return new Matrix ( a , b , c , d , tx , ty ) ;
3173 }
74+
75+ public serialize ( ) :Object {
76+ return this . _data ;
77+ }
3278 }
3379
34- export class Matrix3D {
80+ export class Matrix3D implements Display . ISerializable {
3581 private _data :Array < number > ;
3682
3783 constructor ( iv :Array < number > = [ 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 ] ) {
@@ -50,6 +96,10 @@ module Display {
5096 public clone ( ) :Matrix3D {
5197 return new Matrix3D ( this . _data ) ;
5298 }
99+
100+ public serialize ( ) :Object {
101+ return this . _data ;
102+ }
53103 }
54104
55105 export function createMatrix ( ) :any {
@@ -68,6 +118,14 @@ module Display {
68118 return null ;
69119 }
70120
121+ export function projectVector ( matrix :Matrix3D , vector :Array < number > ) :any {
122+ return [ ] ;
123+ }
124+
125+ export function projectVectors ( matrix :Matrix3D , verts :Array < number > , projectedVerts :Array < number > , uvts :Array < number > ) :void {
126+
127+ }
128+
71129 /**
72130 * Transforms a JS Array into an AS3 Vector<int>.
73131 * Nothing is actually done since the methods are very
0 commit comments