diff options
Diffstat (limited to 'js/helper-classes/RDGE/GLLine.js')
-rw-r--r-- | js/helper-classes/RDGE/GLLine.js | 126 |
1 files changed, 84 insertions, 42 deletions
diff --git a/js/helper-classes/RDGE/GLLine.js b/js/helper-classes/RDGE/GLLine.js index 9eaa69d1..5ec51230 100644 --- a/js/helper-classes/RDGE/GLLine.js +++ b/js/helper-classes/RDGE/GLLine.js | |||
@@ -27,13 +27,9 @@ function GLLine( world, xOffset, yOffset, width, height, slope, strokeSize, stro | |||
27 | 27 | ||
28 | this._strokeWidth = 0.25; | 28 | this._strokeWidth = 0.25; |
29 | 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"; | 30 | this._strokeStyle = "Solid"; |
31 | this._scaleX = 1.0; | ||
32 | this._scaleY = 1.0; | ||
37 | 33 | ||
38 | if (arguments.length > 0) | 34 | if (arguments.length > 0) |
39 | { | 35 | { |
@@ -50,13 +46,9 @@ function GLLine( world, xOffset, yOffset, width, height, slope, strokeSize, stro | |||
50 | this._strokeColor = strokeColor; | 46 | this._strokeColor = strokeColor; |
51 | 47 | ||
52 | this._strokeStyle = strokeStyle; | 48 | this._strokeStyle = strokeStyle; |
49 | this._scaleX = (world.getViewportWidth())/(world.getViewportHeight()); | ||
53 | } | 50 | } |
54 | 51 | ||
55 | this._scaleX = 1.0; | ||
56 | this._scaleY = 1.0; | ||
57 | |||
58 | this._scaleX = (world._viewportWidth)/(world._viewportHeight); | ||
59 | |||
60 | this._strokeVerticesLen = 0; | 52 | this._strokeVerticesLen = 0; |
61 | 53 | ||
62 | this.m_world = world; | 54 | this.m_world = world; |
@@ -83,11 +75,16 @@ function GLLine( world, xOffset, yOffset, width, height, slope, strokeSize, stro | |||
83 | this.getStrokeMaterial = function() { return this._strokeMaterial; } | 75 | this.getStrokeMaterial = function() { return this._strokeMaterial; } |
84 | this.setStrokeMaterial = function(m) { this._strokeMaterial = m; } | 76 | this.setStrokeMaterial = function(m) { this._strokeMaterial = m; } |
85 | 77 | ||
86 | this.getStrokeColor = function() { return this._strokeColor; } | 78 | this.getStrokeColor = function() { return this._strokeColor; } |
87 | //this.setStrokeColor = function(c) { this._strokeColor = c; } | 79 | //this.setStrokeColor = function(c) { this._strokeColor = c; } |
88 | 80 | ||
89 | this.getStrokeStyle = function() { return this._strokeStyle; } | 81 | this.getStrokeStyle = function() { return this._strokeStyle; } |
90 | this.setStrokeStyle = function(s) { this._strokeStyle = s; } | 82 | this.setStrokeStyle = function(s) { this._strokeStyle = s; } |
83 | |||
84 | this.getFillMaterial = function() { return null; } | ||
85 | |||
86 | this.setStrokeMaterial = function(m) { this._strokeMaterial = m; } | ||
87 | this.getStrokeMaterial = function() { return this._strokeMaterial; } | ||
91 | 88 | ||
92 | this.getWidth = function() { return this._width; } | 89 | this.getWidth = function() { return this._width; } |
93 | this.setWidth = function(w) { this._width = w; } | 90 | this.setWidth = function(w) { this._width = w; } |
@@ -105,7 +102,64 @@ function GLLine( world, xOffset, yOffset, width, height, slope, strokeSize, stro | |||
105 | this.setSlope = function(m) { this._slope = m; } | 102 | this.setSlope = function(m) { this._slope = m; } |
106 | 103 | ||
107 | this.geomType = function() { return this.GEOM_TYPE_LINE; } | 104 | this.geomType = function() { return this.GEOM_TYPE_LINE; } |
108 | 105 | ||
106 | /////////////////////////////////////////////////////////////////////// | ||
107 | // Methods | ||
108 | /////////////////////////////////////////////////////////////////////// | ||
109 | this.export = function() | ||
110 | { | ||
111 | var rtnStr = "type: " + this.geomType() + "\n"; | ||
112 | |||
113 | rtnStr += "xoff: " + this._xOffset + "\n"; | ||
114 | rtnStr += "yoff: " + this._yOffset + "\n"; | ||
115 | rtnStr += "width: " + this._width + "\n"; | ||
116 | rtnStr += "height: " + this._height + "\n"; | ||
117 | rtnStr += "xAdj: " + this._xAdj + "\n"; | ||
118 | rtnStr += "yAdj: " + this._yAdj + "\n"; | ||
119 | rtnStr += "strokeWidth: " + this._strokeWidth + "\n"; | ||
120 | rtnStr += "strokeColor: " + String(this._strokeColor) + "\n"; | ||
121 | rtnStr += "strokeStyle: " + this._strokeStyle + "\n"; | ||
122 | rtnStr += "slope: " + String(this._slope) + "\n"; | ||
123 | |||
124 | rtnStr += "strokeMat: "; | ||
125 | if (this._strokeMaterial) | ||
126 | rtnStr += this._strokeMaterial.getName(); | ||
127 | else | ||
128 | rtnStr += "flatMaterial"; | ||
129 | rtnStr += "\n"; | ||
130 | |||
131 | return rtnStr; | ||
132 | } | ||
133 | |||
134 | this.import = function( importStr ) | ||
135 | { | ||
136 | this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) ); | ||
137 | this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) ); | ||
138 | this._width = Number( this.getPropertyFromString( "width: ", importStr ) ); | ||
139 | this._height = Number( this.getPropertyFromString( "height: ", importStr ) ); | ||
140 | this._xAdj = Number( this.getPropertyFromString( "xAdj: ", importStr ) ); | ||
141 | this._yAdj = Number( this.getPropertyFromString( "yAdj: ", importStr ) ); | ||
142 | this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) ); | ||
143 | var slope = this.getPropertyFromString( "slope: ", importStr ); | ||
144 | if(isNaN(Number(slope))) | ||
145 | this._slope = slope; | ||
146 | else | ||
147 | this._slope = Number(slope); | ||
148 | |||
149 | var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); | ||
150 | this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr ); | ||
151 | this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); | ||
152 | |||
153 | var strokeMat = MaterialsLibrary.getMaterial( strokeMaterialName ); | ||
154 | if (!strokeMat) | ||
155 | { | ||
156 | console.log( "object material not found in library: " + strokeMaterialName ); | ||
157 | strokeMat = new FlatMaterial(); | ||
158 | } | ||
159 | this._strokeMaterial = strokeMat; | ||
160 | |||
161 | } | ||
162 | |||
109 | /////////////////////////////////////////////////////////////////////// | 163 | /////////////////////////////////////////////////////////////////////// |
110 | // Methods | 164 | // Methods |
111 | /////////////////////////////////////////////////////////////////////// | 165 | /////////////////////////////////////////////////////////////////////// |
@@ -115,6 +169,9 @@ function GLLine( world, xOffset, yOffset, width, height, slope, strokeSize, stro | |||
115 | var world = this.getWorld(); | 169 | var world = this.getWorld(); |
116 | if (!world) throw( "null world in buildBuffers" ); | 170 | if (!world) throw( "null world in buildBuffers" ); |
117 | if (!world._useWebGL) return; | 171 | if (!world._useWebGL) return; |
172 | |||
173 | // make sure RDGE has the correct context | ||
174 | g_Engine.setContext( world.getCanvas().uuid ); | ||
118 | 175 | ||
119 | // create the gl buffer | 176 | // create the gl buffer |
120 | var gl = world.getGLContext(); | 177 | var gl = world.getGLContext(); |
@@ -190,9 +247,9 @@ function GLLine( world, xOffset, yOffset, width, height, slope, strokeSize, stro | |||
190 | xFill+x, yFill+y, 0.0, | 247 | xFill+x, yFill+y, 0.0, |
191 | -xFill+x, -yFill+y, 0.0, | 248 | -xFill+x, -yFill+y, 0.0, |
192 | 249 | ||
193 | xFill+x, yFill+y, 0.0, | 250 | xFill+x, -yFill+y, 0.0, |
194 | -xFill+x, -yFill+y, 0.0, | 251 | -xFill+x, -yFill+y, 0.0, |
195 | xFill+x, -yFill+y, 0.0 | 252 | xFill+x, yFill+y, 0.0 |
196 | ]; | 253 | ]; |
197 | } | 254 | } |
198 | else if(this._slope === "horizontal") | 255 | else if(this._slope === "horizontal") |
@@ -205,10 +262,10 @@ function GLLine( world, xOffset, yOffset, width, height, slope, strokeSize, stro | |||
205 | xFill+x, yFill+y, 0.0, | 262 | xFill+x, yFill+y, 0.0, |
206 | -xFill+x, -yFill+y, 0.0, | 263 | -xFill+x, -yFill+y, 0.0, |
207 | 264 | ||
208 | xFill+x, yFill+y, 0.0, | 265 | xFill+x, -yFill+y, 0.0, |
209 | -xFill+x, -yFill+y, 0.0, | 266 | -xFill+x, -yFill+y, 0.0, |
210 | xFill+x, -yFill+y, 0.0 | 267 | xFill+x, yFill+y, 0.0 |
211 | ]; | 268 | ]; |
212 | } | 269 | } |
213 | else if(this._slope > 0) | 270 | else if(this._slope > 0) |
214 | { | 271 | { |
@@ -218,9 +275,9 @@ function GLLine( world, xOffset, yOffset, width, height, slope, strokeSize, stro | |||
218 | -xFill+2*xAdj+x, yFill+y, 0.0, | 275 | -xFill+2*xAdj+x, yFill+y, 0.0, |
219 | xFill-2*xAdj+x, -yFill+y, 0.0, | 276 | xFill-2*xAdj+x, -yFill+y, 0.0, |
220 | 277 | ||
221 | -xFill+2*xAdj+x, yFill+y, 0.0, | 278 | xFill+x, -yFill+2*yAdj+y, 0.0, |
222 | xFill-2*xAdj+x, -yFill+y, 0.0, | 279 | xFill-2*xAdj+x, -yFill+y, 0.0, |
223 | xFill+x, -yFill+2*yAdj+y, 0.0 | 280 | -xFill+2*xAdj+x, yFill+y, 0.0 |
224 | ]; | 281 | ]; |
225 | } | 282 | } |
226 | else | 283 | else |
@@ -231,9 +288,9 @@ function GLLine( world, xOffset, yOffset, width, height, slope, strokeSize, stro | |||
231 | -xFill+2*xAdj+x, -yFill+y, 0.0, | 288 | -xFill+2*xAdj+x, -yFill+y, 0.0, |
232 | xFill-2*xAdj+x, yFill+y, 0.0, | 289 | xFill-2*xAdj+x, yFill+y, 0.0, |
233 | 290 | ||
234 | -xFill+2*xAdj+x, -yFill+y, 0.0, | 291 | xFill+x, yFill-2*yAdj+y, 0.0, |
235 | xFill-2*xAdj+x, yFill+y, 0.0, | 292 | xFill-2*xAdj+x, yFill+y, 0.0, |
236 | xFill+x, yFill-2*yAdj+y, 0.0 | 293 | -xFill+2*xAdj+x, -yFill+y, 0.0 |
237 | ]; | 294 | ]; |
238 | } | 295 | } |
239 | } | 296 | } |
@@ -267,26 +324,11 @@ function GLLine( world, xOffset, yOffset, width, height, slope, strokeSize, stro | |||
267 | } | 324 | } |
268 | 325 | ||
269 | var prim = ShapePrimitive.create(strokeVertices, strokeNormals, strokeTextures, indices, g_Engine.getContext().renderer.TRIANGLES, indices.length); | 326 | var prim = ShapePrimitive.create(strokeVertices, strokeNormals, strokeTextures, indices, g_Engine.getContext().renderer.TRIANGLES, indices.length); |
270 | this._primArray.push( prim ); | ||
271 | 327 | ||
272 | var strokeMaterial; | 328 | var strokeMaterial = this.makeStrokeMaterial(); |
273 | if (this.getStrokeMaterial()) | ||
274 | strokeMaterial = this.getStrokeMaterial().dup(); | ||
275 | else | ||
276 | strokeMaterial = new FlatMaterial(); | ||
277 | 329 | ||
278 | if (strokeMaterial) | 330 | this._primArray.push( prim ); |
279 | { | 331 | this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); |
280 | strokeMaterial.init( this.getWorld() ); | ||