diff options
Diffstat (limited to 'js/helper-classes/RDGE/GLLine.js')
-rw-r--r-- | js/helper-classes/RDGE/GLLine.js | 446 |
1 files changed, 446 insertions, 0 deletions
diff --git a/js/helper-classes/RDGE/GLLine.js b/js/helper-classes/RDGE/GLLine.js new file mode 100644 index 00000000..9eaa69d1 --- /dev/null +++ b/js/helper-classes/RDGE/GLLine.js | |||
@@ -0,0 +1,446 @@ | |||
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 GLLine | ||
9 | // GL representation of a line. | ||
10 | // Derived from class GLGeomObj | ||
11 | /////////////////////////////////////////////////////////////////////// | ||
12 | function GLLine( world, xOffset, yOffset, width, height, slope, strokeSize, strokeColor, strokeMaterial, strokeStyle, xAdj, yAdj) | ||
13 | { | ||
14 | /////////////////////////////////////////////////////////////////////// | ||
15 | // Instance variables | ||
16 | /////////////////////////////////////////////////////////////////////// | ||
17 | this._width = 2.0; | ||
18 | this._height = 2.0; | ||
19 | this._xOffset = 0; | ||
20 | this._yOffset = 0; | ||
21 | |||
22 | // If line doesn't fit in canvas world, we had to grow the canvas by this much on either side | ||
23 | this._xAdj = 0; | ||
24 | this._yAdj = 0; | ||
25 | |||
26 | this._slope = 0; | ||
27 | |||
28 | this._strokeWidth = 0.25; | ||
29 | |||
30 | // stroke colors | ||
31 | this._strokeColor = [0.4, 0.4, 0.4, 1.0]; | ||
32 | |||
33 | // stroke materials | ||
34 | this._strokeMaterial; | ||
35 | |||
36 | this._strokeStyle = "Solid"; | ||
37 | |||
38 | if (arguments.length > 0) | ||
39 | { | ||
40 | this._width = width; | ||
41 | this._height = height; | ||
42 | this._xOffset = xOffset; | ||
43 | this._yOffset = yOffset; | ||
44 | |||
45 | this._xAdj = xAdj; | ||
46 | this._yAdj = yAdj; | ||
47 | |||
48 | this._slope = slope; | ||
49 | this._strokeWidth = strokeSize; | ||
50 | this._strokeColor = strokeColor; | ||
51 | |||
52 | this._strokeStyle = strokeStyle; | ||
53 | } | ||
54 | |||
55 | this._scaleX = 1.0; | ||
56 | this._scaleY = 1.0; | ||
57 | |||
58 | this._scaleX = (world._viewportWidth)/(world._viewportHeight); | ||
59 | |||
60 | this._strokeVerticesLen = 0; | ||
61 | |||
62 | this.m_world = world; | ||
63 | |||
64 | this._materialAmbient = [0.2, 0.2, 0.2, 1.0]; | ||
65 | this._materialDiffuse = [0.4, 0.4, 0.4, 1.0]; | ||
66 | this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; | ||
67 | |||
68 | // initialize the inherited members | ||
69 | this.inheritedFrom = GLGeomObj; | ||
70 | this.inheritedFrom(); | ||
71 | |||
72 | if(strokeMaterial) | ||
73 | { | ||
74 | this._strokeMaterial = strokeMaterial; | ||
75 | } | ||
76 | |||
77 | /////////////////////////////////////////////////////////////////////// | ||
78 | // Property Accessors | ||
79 | /////////////////////////////////////////////////////////////////////// | ||
80 | this.getStrokeWidth = function() { return this._strokeWidth; } | ||
81 | this.setStrokeWidth = function(w) { this._strokeWidth = w; } | ||
82 | |||
83 | this.getStrokeMaterial = function() { return this._strokeMaterial; } | ||
84 | this.setStrokeMaterial = function(m) { this._strokeMaterial = m; } | ||
85 | |||
86 | this.getStrokeColor = function() { return this._strokeColor; } | ||
87 | //this.setStrokeColor = function(c) { this._strokeColor = c; } | ||
88 | |||
89 | this.getStrokeStyle = function() { return this._strokeStyle; } | ||
90 | this.setStrokeStyle = function(s) { this._strokeStyle = s; } | ||
91 | |||
92 | this.getWidth = function() { return this._width; } | ||
93 | this.setWidth = function(w) { this._width = w; } | ||
94 | |||
95 | this.getHeight = function() { return this._height; } | ||
96 | this.setHeight = function(h) { this._height = h; } | ||
97 | |||
98 | this.getXAdj = function() { return this._xAdj; } | ||
99 | this.setXAdj = function(x) { this._xAdj = x; } | ||
100 | |||
101 | this.getYAdj = function() { return this._yAdj; } | ||
102 | this.setYAdj = function(y) { this._yAdj = y; } | ||
103 | |||
104 | this.getSlope = function() { return this._slope; } | ||
105 | this.setSlope = function(m) { this._slope = m; } | ||
106 | |||
107 | this.geomType = function() { return this.GEOM_TYPE_LINE; } | ||
108 | |||
109 | /////////////////////////////////////////////////////////////////////// | ||
110 | // Methods | ||
111 | /////////////////////////////////////////////////////////////////////// | ||
112 | this.buildBuffers = function() | ||
113 | { | ||
114 | // get the world | ||
115 | var world = this.getWorld(); | ||
116 | if (!world) throw( "null world in buildBuffers" ); | ||
117 | if (!world._useWebGL) return; | ||
118 | |||
119 | // create the gl buffer | ||
120 | var gl = world.getGLContext(); | ||
121 | |||
122 | this._strokeVerticesLen = 0; | ||
123 | |||
124 | var strokeVertices = []; | ||
125 | var strokeTextures = []; | ||
126 | var strokeNormals = []; | ||
127 | var strokeColors = []; | ||
128 | |||
129 | // var scaleMat = Matrix.I(3); | ||
130 | // scaleMat.elements[0][0] = this._scaleX; | ||
131 | // scaleMat.elements[1][1] = this._scaleY; | ||
132 | |||
133 | |||
134 | // get the normalized device coordinates (NDC) for | ||
135 | // all position and dimensions. | ||
136 | var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); | ||
137 | var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, | ||
138 | xFillNDC = this._width/vpw, yFillNDC = this._height/vph, | ||
139 | xAdjNDC = this._xAdj/vpw, yAdjNDC = this._yAdj/vph, | ||
140 | xStrokeNDC = this._strokeWidth/vpw, yStrokeNDC = this._strokeWidth/vph; | ||
141 | |||
142 | var aspect = world.getAspect(); | ||
143 | var zn = world.getZNear(), zf = world.getZFar(); | ||
144 | var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), | ||
145 | b = -t, | ||
146 | r = aspect*t, | ||
147 | l = -r; | ||
148 | |||
149 | // calculate the object coordinates from their NDC coordinates | ||
150 | var z = -world.getViewDistance(); | ||
151 | |||
152 | // get the position of the origin | ||
153 | var x = -z*(r-l)/(2.0*zn)*xNDC, | ||
154 | y = -z*(t-b)/(2.0*zn)*yNDC; | ||
155 | |||
156 | // get the x and y fill | ||
157 | var xFill = -z*(r-l)/(2.0*zn)*xFillNDC, | ||
158 | yFill = -z*(t-b)/(2.0*zn)*yFillNDC; | ||
159 | |||
160 | // get the x & y stroke size | ||
161 | var xStroke = -z*(r-l)/(2.0*zn)*xStrokeNDC, | ||
162 | yStroke = -z*(t-b)/(2.0*zn)*yStrokeNDC; | ||
163 | |||
164 | // get the x & y adjustments size | ||
165 | var xAdj = -z*(r-l)/(2.0*zn)*xAdjNDC*2, | ||
166 | yAdj = -z*(t-b)/(2.0*zn)*yAdjNDC*2; | ||
167 | |||
168 | |||
169 | this._primArray = []; | ||
170 | this._materialArray = []; | ||
171 | this._materialTypeArray = []; | ||
172 | this._materialNodeArray = []; | ||
173 | |||
174 | this._scaleX = (world._viewportWidth)/(world._viewportHeight); | ||
175 | |||
176 | var innerX = xFill-xStroke; | ||
177 | var innerY = yFill-yStroke; | ||
178 | |||
179 | // if( (this._strokeStyle === "Dashed") || (this._strokeStyle === "Dotted") ) | ||
180 | // { | ||
181 | // var sLen = this.createStippledStrokes(strokeVertices, this._strokeWidth, this._slope, this._strokeStyle, innerX, innerY); | ||
182 | // this._strokeVerticesLen += sLen; | ||
183 | // } | ||
184 | // else | ||
185 | { | ||
186 | if(this._slope === "vertical") | ||
187 | { | ||
188 | strokeVertices = [ | ||
189 | -xFill+x, yFill+y, 0.0, | ||
190 | xFill+x, yFill+y, 0.0, | ||
191 | -xFill+x, -yFill+y, 0.0, | ||
192 | |||
193 | xFill+x, yFill+y, 0.0, | ||
194 | -xFill+x, -yFill+y, 0.0, | ||
195 | xFill+x, -yFill+y, 0.0 | ||
196 | ]; | ||
197 | } | ||
198 | else if(this._slope === "horizontal") | ||
199 | { | ||
200 | // right now, this is the same as vertical line because, | ||
201 | // our canvas is the same size as us. | ||
202 | // But, we will need to use this when drawing in an existing GLWorld with other shapes | ||
203 | strokeVertices = [ | ||
204 | -xFill+x, yFill+y, 0.0, | ||
205 | xFill+x, yFill+y, 0.0, | ||
206 | -xFill+x, -yFill+y, 0.0, | ||
207 | |||
208 | xFill+x, yFill+y, 0.0, | ||
209 | -xFill+x, -yFill+y, 0.0, | ||
210 | xFill+x, -yFill+y, 0.0 | ||
211 | ]; | ||
212 | } | ||
213 | else if(this._slope > 0) | ||
214 | { | ||
215 | // if slope is positive, draw a line from top-left to bottom-right | ||
216 | strokeVertices = [ | ||
217 | -xFill+x, yFill-2*yAdj+y, 0.0, | ||
218 | -xFill+2*xAdj+x, yFill+y, 0.0, | ||
219 | xFill-2*xAdj+x, -yFill+y, 0.0, | ||
220 | |||
221 | -xFill+2*xAdj+x, yFill+y, 0.0, | ||
222 | xFill-2*xAdj+x, -yFill+y, 0.0, | ||
223 | xFill+x, -yFill+2*yAdj+y, 0.0 | ||
224 | ]; | ||
225 | } | ||
226 | else | ||
227 | { | ||
228 | // else slope is negative, draw a line from bottom-left to top-right | ||
229 | strokeVertices = [ | ||
230 | -xFill+x, -yFill+2*yAdj+y, 0.0, | ||
231 | -xFill+2*xAdj+x, -yFill+y, 0.0, | ||
232 |