Skip to content

Commit 9c86515

Browse files
committed
Added more matrix support to the Display abstraction
1 parent 2e02b69 commit 9c86515

13 files changed

Lines changed: 176 additions & 5 deletions

File tree

src/scripting/build/Host.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,11 @@ var CCLScripting = function(workerUrl){
611611
applyStroke(e, this);
612612
defaultGroup.appendChild(e);
613613
};
614+
615+
this.clear = function(){
616+
defaultGroup.innerHTML = "";
617+
};
618+
614619
this.__defineGetter__("filters", function(f){
615620
return [];
616621
});

src/scripting/src/Host.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,11 @@ var CCLScripting = function(workerUrl){
611611
applyStroke(e, this);
612612
defaultGroup.appendChild(e);
613613
};
614+
615+
this.clear = function(){
616+
defaultGroup.innerHTML = "";
617+
};
618+
614619
this.__defineGetter__("filters", function(f){
615620
return [];
616621
});

src/scripting/src/Host/Host.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* General Host Engine for CCLScripter
3+
* Author: Jim Chen
4+
*/
5+
interface Logger{
6+
log(msg:any):void;
7+
error(msg:any):void;
8+
warn(msg:any):void;
9+
}
10+
11+
export class CCLScripting{
12+
public version:number = 1;
13+
public workerUrl:string;
14+
public logger:Logger = {
15+
log:(msg:any) => {console.log(msg);},
16+
error:(msg:any) => {console.error(msg);},
17+
warn:(msg:any) => {console.warn(msg);}
18+
};
19+
20+
constructor(url:string){
21+
this.workerUrl = url;
22+
}
23+
24+
public getWorker():Worker{
25+
return new Worker(this.workerUrl);
26+
}
27+
28+
public getScriptingContext(){
29+
30+
}
31+
32+
public getSandbox(){
33+
34+
}
35+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Created by jim on 6/23/14.
3+
*/
4+
module Unpacker{
5+
export class Button{
6+
7+
}
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/**
2+
* Created by jim on 6/23/14.
3+
*/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Created by jim on 6/23/14.
3+
*/
4+
5+
module Unpacker{
6+
export class Shape{
7+
8+
}
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Created by jim on 6/23/14.
3+
*/
4+
module Unpacker{
5+
export class Sprite{
6+
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Created by jim on 6/23/14.
3+
*/
4+
module Unpacker{
5+
export class TextField{
6+
7+
}
8+
}

src/scripting/src/api/Display/DisplayObject.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
module Display {
1010
class Transform implements ISerializable {
1111
private _parent:DisplayObject;
12+
private _scaleX:number;
13+
private _scaleY:number;
1214
private _matrix:Display.Matrix = new Matrix();
1315
private _matrix3d:Display.Matrix3D = null;
14-
private _m;
1516

1617
constructor(parent:DisplayObject) {
1718
this._parent = parent;
@@ -39,8 +40,31 @@ module Display {
3940
this._parent.transform = this;
4041
}
4142

43+
/**
44+
* Returns the working matrix as a serializable object
45+
* @returns {*} Serializable Matrix
46+
*/
47+
public getMatrix():Display.ISerializable{
48+
if(this._matrix){
49+
return this._matrix;
50+
}else{
51+
return this._matrix3d;
52+
}
53+
}
54+
55+
/**
56+
* Returns matrix type in use
57+
* @returns {string} - "2d" or "3d"
58+
*/
59+
public getMatrixType():string{
60+
return this._matrix ? "2d" : "3d";
61+
}
62+
4263
public serialize():Object {
43-
return {};
64+
return {
65+
"mode":this.getMatrixType(),
66+
"matrix":this.getMatrix()
67+
};
4468
}
4569

4670
}

src/scripting/src/api/Display/Matrix.ts

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,63 @@
55
*/
66

77
module 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

Comments
 (0)