- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / third_party / spaceport / js / sprites / Transform.js
1 define([ ], function () {
2     function Transform(options) {
3         this.x = 0;
4         this.y = 0;
5         this.scaleX = 1;
6         this.scaleY = 1;
7         this.rotation = 0;
8
9         'x,y,scaleX,scaleY,rotation'.split(',').forEach(function (prop) {
10             if (prop in options) {
11                 this[prop] = options[prop];
12             }
13         }, this);
14
15         // Matrix <=> array index representation:
16         // [ 0 1 2 ]
17         // [ 3 4 5 ]
18         // [ - - - ]
19         var cos = Math.cos(this.rotation);
20         var sin = Math.sin(this.rotation);
21         this.matrix = [
22             cos * this.scaleX, -sin, this.x,
23             sin, cos * this.scaleY, this.y,
24             0, 0, 0  // Padding to pass as 3fv to WebGL
25         ];
26
27         this.cssTransform2d = '' +
28             'translate(' + this.x + 'px,' + this.y + 'px) ' +
29             'scale(' + this.scaleX + ',' + this.scaleY + ') ' +
30             'rotate(' + this.rotation + 'rad) ' +
31             '';
32
33         this.cssTransform3d = '' +
34             'translate3D(' + this.x + 'px,' + this.y + 'px,0px) ' +
35             'scale3D(' + this.scaleX + ',' + this.scaleY + ',1) ' +
36             'rotate(' + this.rotation + 'rad) ' +
37             '';
38     }
39
40     Transform.prototype.transformPointInto = function transformPointInto(x, y, out, offset) {
41         var m = this.matrix;
42         out[offset + 0] = m[0] * x + m[3] * y + m[2];
43         out[offset + 1] = m[1] * x + m[4] * y + m[5];
44     };
45
46     return Transform;
47 });