diff options
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-x | js/lib/geom/rectangle.js | 1165 |
1 files changed, 1165 insertions, 0 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js new file mode 100755 index 00000000..81b385b3 --- /dev/null +++ b/js/lib/geom/rectangle.js | |||
@@ -0,0 +1,1165 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var GeomObj = require("js/lib/geom/geom-obj").GeomObj; | ||
8 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; | ||
9 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; | ||
10 | var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial; | ||
11 | /////////////////////////////////////////////////////////////////////// | ||
12 | // Class GLRectangle | ||
13 | // GL representation of a rectangle. | ||
14 | // Derived from class GeomObj | ||
15 | /////////////////////////////////////////////////////////////////////// | ||
16 | var Rectangle = function GLRectangle() { | ||
17 | // CONSTANTS | ||
18 | this.N_TRIANGLES = 15; | ||
19 | |||
20 | /////////////////////////////////////////////////////////////////////// | ||
21 | // Instance variables | ||
22 | /////////////////////////////////////////////////////////////////////// | ||
23 | this._width = 2.0; | ||
24 | this._height = 2.0; | ||
25 | this._xOffset = 0; | ||
26 | this._yOffset = 0; | ||
27 | |||
28 | this._tlRadius = 0; | ||
29 | this._trRadius = 0; | ||
30 | this._blRadius = 0; | ||
31 | this._brRadius = 0; | ||
32 | |||
33 | this._strokeWidth = 0.25; | ||
34 | |||
35 | this._strokeStyle = "Solid"; | ||
36 | this.init = function(world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, | ||
37 | tlRadius, trRadius, blRadius, brRadius, strokeMaterial, fillMaterial, strokeStyle) { | ||
38 | |||
39 | |||
40 | this.m_world = world; | ||
41 | |||
42 | if (arguments.length > 0) { | ||
43 | this._width = width; | ||
44 | this._height = height; | ||
45 | this._xOffset = xOffset; | ||
46 | this._yOffset = yOffset; | ||
47 | |||
48 | this._strokeWidth = strokeSize; | ||
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 | } | ||
59 | |||
60 | // the overall radius includes the fill and the stroke. separate the two based onthe stroke width | ||
61 | // this._fillRad = this._radius - this._strokeWidth; | ||
62 | // var err = 0.05; | ||
63 | var err = 0; | ||
64 | this._fillWidth = this._width - this._strokeWidth + err; | ||
65 | this._fillHeight = this._height - this._strokeWidth + err; | ||
66 | |||
67 | this._materialAmbient = [0.2, 0.2, 0.2, 1.0]; | ||
68 | this._materialDiffuse = [0.4, 0.4, 0.4, 1.0]; | ||
69 | this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; | ||
70 | |||
71 | if(strokeMaterial) { | ||
72 | this._strokeMaterial = strokeMaterial; | ||
73 | } else { | ||
74 | this._strokeMaterial = MaterialsModel.exportFlatMaterial(); | ||
75 | } | ||
76 | |||
77 | if(fillMaterial) { | ||
78 | this._fillMaterial = fillMaterial; | ||
79 | } else { | ||
80 | this._fillMaterial = MaterialsModel.exportFlatMaterial(); | ||
81 | } | ||
82 | }; | ||
83 | |||
84 | /////////////////////////////////////////////////////////////////////// | ||
85 | // Property Accessors | ||
86 | /////////////////////////////////////////////////////////////////////// | ||
87 | this.getStrokeWidth = function() { | ||
88 | return this._strokeWidth; | ||
89 | }; | ||
90 | |||
91 | this.setStrokeWidth = function(w) { | ||
92 | this._strokeWidth = w; | ||
93 | }; | ||
94 | |||
95 | this.getStrokeMaterial = function() { | ||
96 | return this._strokeMaterial; | ||
97 | }; | ||
98 | |||
99 | this.setStrokeMaterial = function(m) { | ||
100 | this._strokeMaterial = m; | ||
101 | }; | ||
102 | |||
103 | this.getFillMaterial = function() { | ||
104 | return this._fillMaterial; | ||
105 | }; | ||
106 | |||
107 | this.setFillMaterial = function(m) { | ||
108 | this._fillMaterial = m; | ||
109 | }; | ||
110 | |||
111 | this.getStrokeColor = function() { | ||
112 | return this._strokeColor; | ||
113 | }; | ||
114 | |||
115 | //this.setStrokeColor = function(c) { | ||
116 | // this._strokeColor = c; | ||
117 | // }; | ||
118 | |||
119 | this.getFillColor = function() { | ||
120 | return this._fillColor; | ||
121 | }; | ||
122 | |||
123 | //this.setFillColor = function(c) { | ||
124 | // this._fillColor = c.slice(0); | ||
125 | // }; | ||
126 | |||
127 | this.getTLRadius = function() { | ||
128 | return this._tlRadius; | ||
129 | }; | ||
130 | |||
131 | this.setTLRadius = function(r) { | ||
132 | this._tlRadius = Math.min(r, (this._height - this._strokeWidth)/2, (this._width - this._strokeWidth)/2); | ||
133 | }; | ||
134 | |||
135 | this.getTRRadius = function() { | ||
136 | return this._trRadius; | ||
137 | }; | ||
138 | |||
139 | this.setTRRadius = function(r) { | ||
140 | this._trRadius = Math.min(r, (this._height - this._strokeWidth)/2, (this._width - this._strokeWidth)/2); | ||
141 | }; | ||
142 | |||
143 | this.getBLRadius = function() { | ||
144 | return this._blRadius; | ||
145 | }; | ||
146 | |||
147 | this.setBLRadius = function(r) { | ||
148 | this._blRadius = Math.min(r, (this._height - this._strokeWidth)/2, (this._width - this._strokeWidth)/2); | ||
149 | }; | ||
150 | |||
151 | this.getBRRadius = function() { | ||
152 | return this._brRadius; | ||
153 | }; | ||
154 | |||
155 | this.setBRRadius = function(r) { | ||
156 | this._brRadius = Math.min(r, (this._height - this._strokeWidth)/2, (this._width - this._strokeWidth)/2); | ||
157 | }; | ||
158 | |||
159 | this.getStrokeStyle = function() { | ||
160 | return this._strokeStyle; | ||
161 | }; | ||
162 | |||
163 | this.setStrokeStyle = function(s) { | ||
164 | this._strokeStyle = s; | ||
165 | }; | ||
166 | |||
167 | this.getWidth = function() { | ||
168 | return this._width; | ||
169 | }; | ||
170 | |||
171 | this.setWidth = function(w) { | ||
172 | this._width = w; | ||
173 | }; | ||
174 | |||
175 | this.getHeight = function() { | ||
176 | return this._height; | ||
177 | }; | ||
178 | |||
179 | this.setHeight = function(h) { | ||
180 | this._height = h; | ||
181 | }; | ||
182 | |||
183 | this.geomType = function() { | ||
184 | return this.GEOM_TYPE_RECTANGLE; | ||
185 | }; | ||
186 | |||
187 | |||
188 | /////////////////////////////////////////////////////////////////////// | ||
189 | // Methods | ||
190 | /////////////////////////////////////////////////////////////////////// | ||
191 | this.export = function() { | ||
192 | var rtnStr = "type: " + this.geomType() + "\n"; | ||
193 | |||
194 | ///////////////////////////////////////////////////////////////////////// | ||
195 | // | ||
196 | // world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, | ||
197 | // tlRadius, trRadius, blRadius, brRadius, strokeMaterial, fillMaterial, strokeStyle | ||
198 | // | ||
199 | ///////////////////////////////////////////////////////////////////////////// | ||
200 | |||
201 | rtnStr += "xoff: " + this._xOffset + "\n"; | ||
202 | rtnStr += "yoff: " + this._yOffset + "\n"; | ||
203 | rtnStr += "width: " + this._width + "\n"; | ||
204 | rtnStr += "height: " + this._height + "\n"; | ||
205 | rtnStr += "strokeWidth: " + this._strokeWidth + "\n"; | ||
206 | rtnStr += "strokeColor: " + String(this._strokeColor) + "\n"; | ||
207 | rtnStr += "fillColor: " + String(this._fillColor) + "\n"; | ||
208 | rtnStr += "tlRadius: " + this._tlRadius + "\n"; | ||
209 | rtnStr += "trRadius: " + this._trRadius + "\n"; | ||
210 | rtnStr += "blRadius: " + this._blRadius + "\n"; | ||
211 | rtnStr += "brRadius: " + this._brRadius + "\n"; | ||
212 | rtnStr += "innerRadius: " + this._innerRadius + "\n"; | ||
213 | rtnStr += "strokeStyle: " + this._strokeStyle + "\n"; | ||
214 | |||
215 | rtnStr += "strokeMat: "; | ||
216 | if (this._strokeMaterial) { | ||
217 | rtnStr += this._strokeMaterial.getName(); | ||
218 | } else { | ||
219 | rtnStr += "flatMaterial"; | ||
220 | } | ||
221 | |||
222 | rtnStr += "\n"; | ||
223 | |||
224 | rtnStr += "fillMat: "; | ||
225 | if (this._fillMaterial) { | ||
226 | rtnStr += this._fillMaterial.getName(); | ||
227 | } else { | ||
228 | rtnStr += "flatMaterial"; | ||
229 | } | ||
230 | |||
231 | rtnStr += "\n"; | ||
232 | |||
233 | return rtnStr; | ||
234 | }; | ||
235 | |||
236 | this.import = function( importStr ) { | ||
237 | this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) ); | ||
238 | this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) ); | ||
239 | this._width = Number( this.getPropertyFromString( "width: ", importStr ) ); | ||
240 | this._height = Number( this.getPropertyFromString( "height: ", importStr ) ); | ||
241 | this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) ); | ||
242 | this._innerRadius = Number( this.getPropertyFromString( "innerRadius: ", importStr ) ); | ||
243 | this._strokeStyle = Number( this.getPropertyFromString( "strokeStyle: ", importStr ) ); | ||
244 |