diff options
author | Valerio Virgillito | 2012-05-16 01:00:22 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-05-16 01:00:22 -0700 |
commit | f9f8fdc3000042ba5b4504d91870dc9a32ef25eb (patch) | |
tree | 606f22568ad2be0f7aed266a4d20de576f44002f /js/lib/geom/rectangle.js | |
parent | a9672abd32c2e03b8607c1af4903c90f7ff9531c (diff) | |
download | ninja-f9f8fdc3000042ba5b4504d91870dc9a32ef25eb.tar.gz |
Squashed master into dom-architecture
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-x | js/lib/geom/rectangle.js | 1409 |
1 files changed, 738 insertions, 671 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index 490a9a6f..d75abb05 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js | |||
@@ -13,370 +13,428 @@ var MaterialsModel = require("js/models/materials-model").MaterialsModel; | |||
13 | // GL representation of a rectangle. | 13 | // GL representation of a rectangle. |
14 | // Derived from class GeomObj | 14 | // Derived from class GeomObj |
15 | /////////////////////////////////////////////////////////////////////// | 15 | /////////////////////////////////////////////////////////////////////// |
16 | var Rectangle = function GLRectangle() { | 16 | exports.Rectangle = Object.create(GeomObj, { |
17 | // CONSTANTS | 17 | // CONSTANTS |
18 | this.N_TRIANGLES = 15; | 18 | N_TRIANGLES: { value : 15, writable: false }, // TODO - This is not being used anywhere. Remove? |
19 | 19 | ||
20 | /////////////////////////////////////////////////////////////////////// | 20 | /////////////////////////////////////////////////////////////////////// |
21 | // Instance variables | 21 | // Instance variables |
22 | /////////////////////////////////////////////////////////////////////// | 22 | /////////////////////////////////////////////////////////////////////// |
23 | this._width = 2.0; | 23 | _width: { value : 2.0, writable: true }, |
24 | this._height = 2.0; | 24 | _height: { value : 2.0, writable: true }, |
25 | this._xOffset = 0; | 25 | _xOffset: { value : 0, writable: true }, |
26 | this._yOffset = 0; | 26 | _yOffset: { value : 0, writable: true }, |
27 | 27 | ||
28 | this._tlRadius = 0; | 28 | _tlRadius: { value : 0, writable: true }, |
29 | this._trRadius = 0; | 29 | _trRadius: { value : 0, writable: true }, |
30 | this._blRadius = 0; | 30 | _blRadius: { value : 0, writable: true }, |
31 | this._brRadius = 0; | 31 | _brRadius: { value : 0, writable: true }, |
32 | 32 | ||
33 | this._strokeWidth = 0.25; | 33 | _strokeWidth: { value : 0.25, writable: true }, |
34 | _strokeStyle: { value : "Solid", writable: true }, | ||
34 | 35 | ||
35 | this._strokeStyle = "Solid"; | 36 | init: { |
36 | this.init = function(world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, | 37 | value: function(world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, |
37 | tlRadius, trRadius, blRadius, brRadius, strokeMaterial, fillMaterial, strokeStyle) { | 38 | tlRadius, trRadius, blRadius, brRadius, strokeMaterial, fillMaterial, strokeStyle) { |
39 | this.m_world = world; | ||
38 | 40 | ||
41 | if (arguments.length > 0) { | ||
42 | this._width = width; | ||
43 | this._height = height; | ||
44 | this._xOffset = xOffset; | ||
45 | this._yOffset = yOffset; | ||
39 | 46 | ||
40 | this.m_world = world; | 47 | this._strokeWidth = strokeSize; |
48 | this._strokeColor = strokeColor; | ||
49 | this._fillColor = fillColor; | ||
41 | 50 | ||
42 | if (arguments.length > 0) { | 51 | this.setTLRadius(tlRadius); |
43 | this._width = width; | 52 | this.setTRRadius(trRadius); |
44 | this._height = height; | 53 | this.setBLRadius(blRadius); |
45 | this._xOffset = xOffset; | 54 | this.setBRRadius(brRadius); |
46 | this._yOffset = yOffset; | ||
47 | 55 | ||
48 | this._strokeWidth = strokeSize; | 56 | this._strokeStyle = strokeStyle; |
49 | this._strokeColor = strokeColor; | ||
50 | this._fillColor = fillColor; | ||
51 | |||
52 | this.setTLRadius(tlRadius); | ||
53 | this.setTRRadius(trRadius); | ||
54 | this.setBLRadius(blRadius); | ||
55 | this.setBRRadius(brRadius); | ||
56 | |||
57 | this._strokeStyle = strokeStyle; | ||
58 | 57 | ||
59 | this._matrix = Matrix.I(4); | 58 | this._matrix = Matrix.I(4); |
60 | //this._matrix[12] = xoffset; | 59 | //this._matrix[12] = xoffset; |
61 | //this._matrix[13] = yoffset; | 60 | //this._matrix[13] = yoffset; |
62 | } | 61 | } |
63 | 62 | ||
64 | // the overall radius includes the fill and the stroke. separate the two based onthe stroke width | 63 | // the overall radius includes the fill and the stroke. separate the two based on the stroke width |
65 | // this._fillRad = this._radius - this._strokeWidth; | 64 | // this._fillRad = this._radius - this._strokeWidth; |
66 | // var err = 0.05; | 65 | // var err = 0.05; |
67 | var err = 0; | 66 | var err = 0; |
68 | this._fillWidth = this._width - this._strokeWidth + err; | 67 | this._fillWidth = this._width - this._strokeWidth + err; |
69 | this._fillHeight = this._height - this._strokeWidth + err; | 68 | this._fillHeight = this._height - this._strokeWidth + err; |
70 | 69 | ||
71 | this._materialAmbient = [0.2, 0.2, 0.2, 1.0]; | 70 | this._materialAmbient = [0.2, 0.2, 0.2, 1.0]; |
72 | this._materialDiffuse = [0.4, 0.4, 0.4, 1.0]; | 71 | this._materialDiffuse = [0.4, 0.4, 0.4, 1.0]; |
73 | this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; | 72 | this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; |
74 | 73 | ||
75 | if(strokeMaterial) { | 74 | if(strokeMaterial) { |
76 | this._strokeMaterial = strokeMaterial; | 75 | this._strokeMaterial = strokeMaterial; |
77 | } else { | 76 | } else { |
78 | this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | 77 | this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); |
79 | } | 78 | } |
80 | 79 | ||
81 | if(fillMaterial) { | 80 | if(fillMaterial) { |
82 | this._fillMaterial = fillMaterial; | 81 | this._fillMaterial = fillMaterial; |
83 | } else { | 82 | } else { |
84 | this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | 83 | this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); |
84 | } | ||
85 | } | 85 | } |
86 | }; | 86 | }, |
87 | 87 | ||
88 | /////////////////////////////////////////////////////////////////////// | 88 | /////////////////////////////////////////////////////////////////////// |
89 | // Property Accessors | 89 | // Property Accessors |
90 | /////////////////////////////////////////////////////////////////////// | 90 | /////////////////////////////////////////////////////////////////////// |
91 | this.getStrokeWidth = function() { | 91 | // TODO - Use getters/setters in the future |
92 | return this._strokeWidth; | 92 | getStrokeWidth: { |
93 | }; | 93 | value: function() { |
94 | 94 | return this._strokeWidth; | |
95 | this.setStrokeWidth = function(w) { | 95 | } |
96 | this._strokeWidth = w; | 96 | }, |
97 | }; | ||
98 | |||
99 | this.getStrokeMaterial = function() { | ||
100 | return this._strokeMaterial; | ||
101 | }; | ||
102 | |||
103 | this.setStrokeMaterial = function(m) { | ||
104 | this._strokeMaterial = m; | ||
105 | }; | ||
106 | 97 | ||
107 | this.getFillMaterial = function() { | 98 | setStrokeWidth: { |
108 | return this._fillMaterial; | 99 | value: function(w) { |
109 | }; | 100 | this._strokeWidth = w; |
101 | } | ||
102 | }, | ||
110 | 103 | ||
111 | this.setFillMaterial = function(m) { | 104 | getStrokeMaterial: { |
112 | this._fillMaterial = m; | 105 | value: function() { |
113 | }; | 106 | return this._strokeMaterial; |
107 | } | ||
108 | }, | ||
114 | 109 | ||
115 | this.getStrokeColor = function() { | 110 | setStrokeMaterial: { |
116 | return this._strokeColor; | 111 | value: function(m) { |
117 | }; | 112 | this._strokeMaterial = m; |
113 | } | ||
114 | }, | ||
118 | 115 | ||
119 | //this.setStrokeColor = function(c) { | 116 | getFillMaterial: { |
120 | // this._strokeColor = c; | 117 | value: function() { |
121 | // }; | 118 | return this._fillMaterial; |
119 | } | ||
120 | }, | ||
122 | 121 | ||
123 | this.getFillColor = function() { | 122 | setFillMaterial: { |
124 | return this._fillColor; | 123 | value: function(m) { |
125 | }; | 124 | this._fillMaterial = m; |
125 | } | ||
126 | }, | ||
126 | 127 | ||
127 | //this.setFillColor = function(c) { | 128 | /////////////////////////////////////////////////////////////////////// |
128 | // this._fillColor = c.slice(0); | 129 | // update the "color of the material |
129 | // }; | 130 | getFillColor: { |
131 | value: function() { | ||
132 | return this._fillColor; | ||
133 | } | ||
134 | }, | ||
130 | 135 | ||
131 | this.getTLRadius = function() { | 136 | // setFillColor: { |
132 | return this._tlRadius; | 137 | // value: function(c) { |
133 | }; | 138 | // this._fillColor = c; |
139 | // } | ||
140 | // }, | ||
134 | 141 | ||
135 | this.setTLRadius = function(r) { | 142 | getStrokeColor: { |
136 | this._tlRadius = Math.min(r, (this._height - this._strokeWidth)/2, (this._width - this._strokeWidth)/2); | 143 | value: function() { |
137 | }; | 144 | return this._strokeColor; |
145 | } | ||
146 | }, | ||
147 | |||
148 | // setStrokeColor: { | ||
149 | // value: function(c) { | ||
150 | // this._strokeColor = c; | ||
151 | // } | ||
152 | // }, | ||
153 | /////////////////////////////////////////////////////////////////////// | ||
154 | getTLRadius: { | ||
155 | value: function() { | ||
156 | return this._tlRadius; | ||
157 | } | ||
158 | }, | ||
138 | 159 | ||
139 | this.getTRRadius = function() { | 160 | setTLRadius: { |
140 | return this._trRadius; | 161 | value: function(r) { |
141 | }; |