aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/GLRectangle.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/GLRectangle.js')
-rw-r--r--js/helper-classes/RDGE/GLRectangle.js1251
1 files changed, 1251 insertions, 0 deletions
diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js
new file mode 100644
index 00000000..1334d7e6
--- /dev/null
+++ b/js/helper-classes/RDGE/GLRectangle.js
@@ -0,0 +1,1251 @@
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 ///////////////////////////////////////////////////////////////////////
8// Class GLRectangle
9// GL representation of a rectangle.
10// Derived from class GLGeomObj
11///////////////////////////////////////////////////////////////////////
12function GLRectangle()
13{
14 // CONSTANTS
15 this.N_TRIANGLES = 15;
16
17 // initialize the inherited members
18 this.inheritedFrom = GLGeomObj;
19 this.inheritedFrom();
20
21 ///////////////////////////////////////////////////////////////////////
22 // Instance variables
23 ///////////////////////////////////////////////////////////////////////
24 this._width = 2.0;
25 this._height = 2.0;
26 this._xOffset = 0;
27 this._yOffset = 0;
28
29 this._tlRadius = 0;
30 this._trRadius = 0;
31 this._blRadius = 0;
32 this._brRadius = 0;
33
34 this._strokeWidth = 0.25;
35
36 // stroke and fill colors
37 this._strokeColor;
38 this._fillColor;
39
40 // stroke and fill materials
41 this._fillMaterial;
42 this._strokeMaterial;
43
44 this._strokeStyle = "Solid";
45 this.init = function(world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor,
46 tlRadius, trRadius, blRadius, brRadius, strokeMaterial, fillMaterial, strokeStyle)
47 {
48
49
50 this.m_world = world;
51
52 if (arguments.length > 0)
53 {
54 this._width = width;
55 this._height = height;
56 this._xOffset = xOffset;
57 this._yOffset = yOffset;
58
59 this._strokeWidth = strokeSize;
60 this._strokeColor = strokeColor;
61 this._fillColor = fillColor;
62
63 this.setTLRadius(tlRadius);
64 this.setTRRadius(trRadius);
65 this.setBLRadius(blRadius);
66 this.setBRRadius(brRadius);
67
68 this._strokeStyle = strokeStyle;
69 }
70
71 // the overall radius includes the fill and the stroke. separate the two based onthe stroke width
72 // this._fillRad = this._radius - this._strokeWidth;
73 // var err = 0.05;
74 var err = 0;
75 this._fillWidth = this._width - this._strokeWidth + err;
76 this._fillHeight = this._height - this._strokeWidth + err;
77
78 this._materialAmbient = [0.2, 0.2, 0.2, 1.0];
79 this._materialDiffuse = [0.4, 0.4, 0.4, 1.0];
80 this._materialSpecular = [0.4, 0.4, 0.4, 1.0];
81
82 if(strokeMaterial)
83 {
84 this._strokeMaterial = strokeMaterial;
85 }
86 if(fillMaterial)
87 {
88 this._fillMaterial = fillMaterial;
89 }
90 }
91
92 ///////////////////////////////////////////////////////////////////////
93 // Property Accessors
94 ///////////////////////////////////////////////////////////////////////
95 this.getStrokeWidth = function() { return this._strokeWidth; }
96 this.setStrokeWidth = function(w) { this._strokeWidth = w; }
97
98 this.getStrokeMaterial = function() { return this._strokeMaterial; }
99 this.setStrokeMaterial = function(m) { this._strokeMaterial = m; }
100
101 this.getFillMaterial = function() { return this._fillMaterial; }
102 this.setFillMaterial = function(m) { this._fillMaterial = m; }
103
104 this.getStrokeColor = function() { return this._strokeColor; }
105 //this.setStrokeColor = function(c) { this._strokeColor = c; }
106
107 this.getFillColor = function() { return this._fillColor; }
108 //this.setFillColor = function(c) { this._fillColor = c.slice(0); }
109
110 this.getTLRadius = function() { return this._tlRadius; }
111 this.setTLRadius = function(r) { this._tlRadius = Math.min(r, (this._height - this._strokeWidth)/2, (this._width - this._strokeWidth)/2); }
112
113 this.getTRRadius = function() { return this._trRadius; }
114 this.setTRRadius = function(r) { this._trRadius = Math.min(r, (this._height - this._strokeWidth)/2, (this._width - this._strokeWidth)/2); }
115
116 this.getBLRadius = function() { return this._blRadius; }
117 this.setBLRadius = function(r) { this._blRadius = Math.min(r, (this._height - this._strokeWidth)/2, (this._width - this._strokeWidth)/2); }
118
119 this.getBRRadius = function() { return this._brRadius; }
120 this.setBRRadius = function(r) { this._brRadius = Math.min(r, (this._height - this._strokeWidth)/2, (this._width - this._strokeWidth)/2); }
121
122 this.getStrokeStyle = function() { return this._strokeStyle; }
123 this.setStrokeStyle = function(s) { this._strokeStyle = s; }
124
125 this.getWidth = function() { return this._width; }
126 this.setWidth = function(w) { this._width = w; }
127
128 this.getHeight = function() { return this._height; }
129 this.setHeight = function(h) { this._height = h; }
130
131 this.geomType = function() { return this.GEOM_TYPE_RECTANGLE; }
132
133
134 ///////////////////////////////////////////////////////////////////////
135 // Methods
136 ///////////////////////////////////////////////////////////////////////
137 this.export = function()
138 {
139 var rtnStr = "type: " + this.geomType() + "\n";
140
141 /////////////////////////////////////////////////////////////////////////
142 //
143 // world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor,
144 // tlRadius, trRadius, blRadius, brRadius, strokeMaterial, fillMaterial, strokeStyle
145 //
146 /////////////////////////////////////////////////////////////////////////////
147
148 rtnStr += "xoff: " + this._xOffset + "\n";
149 rtnStr += "yoff: " + this._yOffset + "\n";
150 rtnStr += "width: " + this._width + "\n";
151 rtnStr += "height: " + this._height + "\n";
152 rtnStr += "strokeWidth: " + this._strokeWidth + "\n";
153 rtnStr += "strokeColor: " + String(this._strokeColor) + "\n";
154 rtnStr += "fillColor: " + String(this._fillColor) + "\n";
155 rtnStr += "tlRadius: " + this._tlRadius + "\n";
156 rtnStr += "trRadius: " + this._trRadius + "\n";
157 rtnStr += "blRadius: " + this._blRadius + "\n";
158 rtnStr += "brRadius: " + this._brRadius + "\n";
159 rtnStr += "innerRadius: " + this._innerRadius + "\n";
160 rtnStr += "strokeStyle: " + this._strokeStyle + "\n";
161
162 rtnStr += "strokeMat: ";
163 if (this._strokeMaterial)
164 rtnStr += this._strokeMaterial.getName();
165 else
166 rtnStr += "flatMaterial";
167 rtnStr += "\n";
168
169 rtnStr += "fillMat: ";
170 if (this._fillMaterial)
171 rtnStr += this._fillMaterial.getName();
172 else
173 rtnStr += "flatMaterial";
174 rtnStr += "\n";
175
176 return rtnStr;
177 }
178
179 this.import = function( importStr )
180 {
181 this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) );
182 this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) );
183 this._width = Number( this.getPropertyFromString( "width: ", importStr ) );
184 this._height = Number( this.getPropertyFromString( "height: ", importStr ) );
185 this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) );
186 this._innerRadius = Number( this.getPropertyFromString( "innerRadius: ", importStr ) );
187 this._strokeStyle = Number( this.getPropertyFromString( "strokeStyle: ", importStr ) );
188 var strokeMaterialName = Number( this.getPropertyFromString( "strokeMat: ", importStr ) );
189 var fillMaterialName = Number( this.getPropertyFromString( "fillMat: ", importStr ) );
190 this._strokeStyle = Number( this.getPropertyFromString( "strokeColor: ", importStr ) );
191 this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" );
192 this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" );
193 this._tlRadius = Number( this.getPropertyFromString( "tlRadius: ", importStr ) );
194 this._trRadius = Number( this.getPropertyFromString( "trRadius: ", importStr ) );
195 this._blRadius = Number( this.getPropertyFromString( "blRadius: ", importStr ) );
196 this._brRadius = Number( this.getPropertyFromString( "brRadius: ", importStr ) );
197
198 var strokeMat = MaterialsLibrary.getMaterial( strokeMaterialName );
199 if (!strokeMat)
200 {
201 console.log( "object material not found in library: " + strokeMaterialName );
202 strokeMat = new FlatMaterial();
203 }
204 this._strokeMaterial = strokeMat;
205
206 var fillMat = MaterialsLibrary.getMaterial( fillMaterialName );
207 if (!fillMat)
208 {
209 console.log( "object material not found in library: " + fillMaterialName );
210 fillMat = new FlatMaterial();
211 }
212 this._fillMaterial = fillMat;
213 }
214
215 this.buildBuffers = function()
216 {
217 // get the world
218 var world = this.getWorld();
219 if (!world) throw( "null world in buildBuffers" );</