diff options
Diffstat (limited to 'js/helper-classes/RDGE/GLCircle.js')
-rw-r--r-- | js/helper-classes/RDGE/GLCircle.js | 754 |
1 files changed, 754 insertions, 0 deletions
diff --git a/js/helper-classes/RDGE/GLCircle.js b/js/helper-classes/RDGE/GLCircle.js new file mode 100644 index 00000000..fc2e6460 --- /dev/null +++ b/js/helper-classes/RDGE/GLCircle.js | |||
@@ -0,0 +1,754 @@ | |||
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 GLCircle | ||
9 | // GL representation of a circle. | ||
10 | // Derived from class GLGeomObj | ||
11 | // The position and dimensions of the stroke, fill, and inner Radius should be in pixels | ||
12 | /////////////////////////////////////////////////////////////////////// | ||
13 | function GLCircle() | ||
14 | { | ||
15 | |||
16 | // initialize the inherited members | ||
17 | this.inheritedFrom = GLGeomObj; | ||
18 | this.inheritedFrom(); | ||
19 | |||
20 | this.init = function( world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, innerRadius, strokeMaterial, fillMaterial, strokeStyle) | ||
21 | { | ||
22 | /////////////////////////////////////////////////////////////////////// | ||
23 | // Instance variables | ||
24 | /////////////////////////////////////////////////////////////////////// | ||
25 | this._width = 2.0; | ||
26 | this._height = 2.0; | ||
27 | this._xOffset = 0; | ||
28 | this._yOffset = 0; | ||
29 | |||
30 | this._radius = 2.0; | ||
31 | this._strokeWidth = 0.25; | ||
32 | this._innerRadius = 0; | ||
33 | |||
34 | this._ovalHeight = this._ovalHeight = 2.0*this.radius; | ||
35 | |||
36 | // stroke and fill colors | ||
37 | this._strokeColor = [0.4, 0.4, 0.4, 1.0]; | ||
38 | this._fillColor = [0.0, 0.6, 0.0, 1.0]; | ||
39 | |||
40 | // stroke and fill materials | ||
41 | this._fillMaterial; | ||
42 | this._strokeMaterial; | ||
43 | |||
44 | this._strokeStyle = "Solid"; | ||
45 | |||
46 | this._aspectRatio = 1.0; | ||
47 | |||
48 | |||
49 | if (arguments.length > 0) | ||
50 | { | ||
51 | this._width = width; | ||
52 | this._height = height; | ||
53 | this._xOffset = xOffset; | ||
54 | this._yOffset = yOffset; | ||
55 | |||
56 | this._strokeWidth = strokeSize; | ||
57 | this._innerRadius = innerRadius; | ||
58 | this._strokeColor = strokeColor; | ||
59 | this._fillColor = fillColor; | ||
60 | |||
61 | this._strokeStyle = strokeStyle; | ||
62 | } | ||
63 | |||
64 | this.m_world = world; | ||
65 | |||
66 | if(strokeMaterial) | ||
67 | { | ||
68 | this._strokeMaterial = strokeMaterial; | ||
69 | } | ||
70 | if(fillMaterial) | ||
71 | { | ||
72 | this._fillMaterial = fillMaterial; | ||
73 | } | ||
74 | } | ||
75 | |||
76 | /////////////////////////////////////////////////////////////////////// | ||
77 | // Property Accessors | ||
78 | /////////////////////////////////////////////////////////////////////// | ||
79 | this.getStrokeWidth = function() { return this._strokeWidth; } | ||
80 | this.setStrokeWidth = function(w) { this._strokeWidth = w; } | ||
81 | |||
82 | this.getStrokeMaterial = function() { return this._strokeMaterial; } | ||
83 | this.setStrokeMaterial = function(m) { this._strokeMaterial = m; } | ||
84 | |||
85 | this.getFillMaterial = function() { return this._fillMaterial; } | ||
86 | this.setFillMaterial = function(m) { this._fillMaterial = m; } | ||
87 | |||
88 | this.getRadius = function() { return this._radius; } | ||
89 | this.setRadius = function(r) { this._radius = r; } | ||
90 | |||
91 | this.getWorld = function() { return this._world; } | ||
92 | this.setWorld = function(w) { this._world = w; } | ||
93 | |||
94 | this.getInnerRadius = function() { return this._innerRadius; } | ||
95 | this.setInnerRadius = function(r) { this._innerRadius = r; } | ||
96 | |||
97 | this.getStrokeStyle = function() { return this._strokeStyle; } | ||
98 | this.setStrokeStyle = function(s) { this._strokeStyle = s; } | ||
99 | |||
100 | this.getWidth = function() { return this._width; } | ||
101 | this.setWidth = function(w) { this._width = w; } | ||
102 | |||
103 | this.getHeight = function() { return this._height; } | ||
104 | this.setHeight = function(h) { this._height = h; } | ||
105 | |||
106 | this.geomType = function() { return this.GEOM_TYPE_CIRCLE; } | ||
107 | |||
108 | /////////////////////////////////////////////////////////////////////// | ||
109 | // Methods | ||
110 | /////////////////////////////////////////////////////////////////////// | ||
111 | |||
112 | /////////////////////////////////////////////////////////////////////// | ||
113 | // update the "color of the material | ||
114 | this.getFillColor = function() | ||
115 | { | ||
116 | return this._fillColor; | ||
117 | } | ||
118 | |||
119 | // this.setFillColor = function(c) | ||
120 | // { | ||
121 | // this._fillColor = c; | ||
122 | // } | ||
123 | |||
124 | this.getStrokeColor = function() | ||
125 | { | ||
126 | return this._strokeColor; | ||
127 | } | ||
128 | |||
129 | // this.setStrokeColor = function(c) | ||
130 | // { | ||
131 | // this._strokeColor = c; | ||
132 | // } | ||
133 | /////////////////////////////////////////////////////////////////////// | ||
134 | |||
135 | this.buildBuffers = function() | ||
136 | { | ||
137 | // get the world | ||
138 | var world = this.getWorld(); | ||
139 | if (!world) throw( "null world in buildBuffers" ); | ||
140 | |||
141 | if (!world._useWebGL) return; | ||
142 | |||
143 | // create the gl buffer | ||
144 | var gl = world.getGLContext(); | ||
145 | |||
146 | // determine the number of triangles to generate | ||
147 | var nTriangles = 60; // yes, we will do better than this | ||
148 | |||
149 | // get the normalized device coordinates (NDC) for | ||
150 | // all position and dimensions. | ||
151 | var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); | ||
152 | var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, | ||
153 | xRadNDC = this._width/vpw, yRadNDC = this._height/vph, | ||
154 | xStrokeNDC = 2*this._strokeWidth/vpw, yStrokeNDC = 2*this._strokeWidth/vph, | ||
155 | xInnRadNDC = this._innerRadius*xRadNDC, yInnRadNDC = this._innerRadius*yRadNDC; | ||
156 | |||
157 | var aspect = world.getAspect(); | ||
158 | var zn = world.getZNear(), zf = world.getZFar(); | ||
159 | var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), | ||
160 | b = -t, | ||
161 | r = aspect*t, | ||
162 | l = -r; | ||
163 | |||
164 | // calculate the object coordinates from their NDC coordinates | ||
165 | var z = -world.getViewDistance(); | ||
166 | |||
167 | // get the position of the origin | ||
168 | var x = -z*(r-l)/(2.0*zn)*xNDC, | ||
169 | y = -z*(t-b)/(2.0*zn)*yNDC; | ||
170 | |||
171 | // get the x and y radii | ||
172 | var xRad = -z*(r-l)/(2.0*zn)*xRadNDC, | ||
173 | yRad = -z*(t-b)/(2.0*zn)*yRadNDC; | ||
174 | |||
175 | // save the overall dimensions to be used in the uv calculations | ||
176 | this._ovalWidth = xRad; this._ovalHeight = yRad; | ||
177 | |||
178 | // get the x & y stroke size | ||
179 | var xStroke = -z*(r-l)/(2.0*zn)*xStrokeNDC, | ||
180 | yStroke = -z*(t-b)/(2.0*zn)*yStrokeNDC; | ||
181 | |||
182 | // get the inner radius | ||
183 | var xInnRad = -z*(r-l)/(2.0*zn)*xInnRadNDC, | ||
184 | yInnRad = -z*(t-b)/(2.0*zn)*yInnRadNDC; | ||
185 | |||
186 | // get a matrix to rotate a point around the circle | ||
187 | var angle = 2.0*Math.PI/Number(nTriangles); | ||
188 | var mat = Matrix.RotationZ( angle ); | ||
189 | var reverseRotMat = Matrix.RotationZ( -angle ); | ||
190 | |||
191 | // calculate matrices to scale the circle and stroke to fit the bounds of the ellipse | ||
192 | strokeScaleMat = Matrix.I(4); | ||
193 | strokeScaleMat[0] = xRad; | ||
194 | strokeScaleMat[5] = yRad; | ||
195 | |||
196 | fillScaleMat = Matrix.I(4); | ||
197 | fillScaleMat[0] = xRad - xStroke; | ||
198 | fillScaleMat[5] = yRad - yStroke; | ||
199 | |||
200 | innerRadiusScaleMat = Matrix.I(4); | ||
201 | innerRadiusScaleMat[0] = xInnRad; | ||
202 | innerRadiusScaleMat[5] = yInnRad; | ||
203 | |||
204 | innerStrokeScaleMat = Matrix.I(4); | ||
205 | innerStrokeScaleMat[0] = xInnRad - xStroke; | ||
206 | innerStrokeScaleMat[5] = yInnRad - yStroke; | ||
207 | |||
208 | var fillPrim, strokePrim0, strokePrim1; | ||
209 | var fillMaterial, strokeMaterial0, strokeMaterial2; | ||
210 | |||
211 | this._primArray = []; | ||
212 | this._materialArray = []; | ||
213 | this._materialTypeArray = []; | ||
214 | this._materialNodeArray = []; | ||
215 | |||
216 | ///////////////////////////////////////////////////////////// | ||
217 | // Strokes | ||
218 | if(this._strokeWidth > 0) | ||
219 | { | ||
220 | var numStrokes = 1; | ||
221 | if(this._innerRadius !== 0) | ||
222 | strokePrim0 = this.generateOvalRing(x, y, reverseRotMat, innerStrokeScaleMat, innerRadiusScaleMat, nTriangles); | ||
223 | |||
224 | strokePrim1 = this.generateOvalRing(x, y, reverseRotMat, fillScaleMat, strokeScaleMat, nTriangles); | ||
225 | } | ||
226 | |||
227 | ///////////////////////////////////////////////////////////// | ||
228 | // Fill | ||
229 | if(this._innerRadius === 0) | ||