aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/runtime/RuntimeGeomObj.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/runtime/RuntimeGeomObj.js')
-rw-r--r--js/helper-classes/RDGE/runtime/RuntimeGeomObj.js331
1 files changed, 324 insertions, 7 deletions
diff --git a/js/helper-classes/RDGE/runtime/RuntimeGeomObj.js b/js/helper-classes/RDGE/runtime/RuntimeGeomObj.js
index 2539abc1..253154f9 100644
--- a/js/helper-classes/RDGE/runtime/RuntimeGeomObj.js
+++ b/js/helper-classes/RDGE/runtime/RuntimeGeomObj.js
@@ -80,9 +80,9 @@ function RuntimeGeomObj()
80 switch (materialType) 80 switch (materialType)
81 { 81 {
82 case "flat": mat = new RuntimeFlatMaterial(); break; 82 case "flat": mat = new RuntimeFlatMaterial(); break;
83 83 case "radialGradient": mat = new RuntimeRadialGradientMaterial(); break;
84 case "radialGradient":
85 case "linearGradient": mat = new RuntimeLinearGradientMaterial(); break; 84 case "linearGradient": mat = new RuntimeLinearGradientMaterial(); break;
85 case "bumpMetal": mat = new RuntimeBumpMetalMaterial(); break;
86 86
87 case "water": 87 case "water":
88 case "tunnel": 88 case "tunnel":
@@ -113,6 +113,101 @@ function RuntimeGeomObj()
113 importStr = importStr.substr( endIndex ); 113 importStr = importStr.substr( endIndex );
114 } 114 }
115 } 115 }
116
117 ////////////////////////////////////////////////////////////////////
118 // vector function
119
120 this.vecAdd = function( dimen, a, b )
121 {
122 var rtnVec;
123 if ((a.length < dimen) || (b.length < dimen))
124 {
125 throw new Error( "dimension error in vecAdd" );
126 }
127
128 rtnVec = [];
129 for (var i=0; i<dimen; i++)
130 rtnVec[i] = a[i] + b[i];
131
132 return rtnVec;
133 }
134
135
136 this.vecSubtract = function( dimen, a, b )
137 {
138 var rtnVec;
139 if ((a.length < dimen) || (b.length < dimen))
140 {
141 throw new Error( "dimension error in vecSubtract" );
142 }
143
144 rtnVec = [];
145 for (var i=0; i<dimen; i++)
146 rtnVec[i] = a[i] - b[i];
147
148 return rtnVec;
149 }
150
151 this.vecDot = function( dimen, v0, v1 )
152 {
153 if ((v0.length < dimen) || (v1.length < dimen))
154 {
155 throw new Error( "dimension error in vecDot" );
156 }
157
158 var sum = 0.0;
159 for (var i=0; i<dimen; i++)
160 sum += v0[i] * v1[i];
161
162 return sum;
163 }
164
165 this.vecMag = function( dimen, vec )
166 {
167 var sum = 0.0;
168 for (var i=0; i<dimen; i++)
169 sum += vec[i]*vec[i];
170 return Math.sqrt( sum );
171 }
172
173 this.vecScale = function(dimen, vec, scale)
174 {
175 for (var i=0; i<dimen; i++)
176 vec[i] *= scale;
177
178 return vec;
179 }
180
181 this.vecNormalize = function(dimen, vec, len)
182 {
183 var rtnVec;
184 if (!len) len = 1.0;
185
186 var sum = 0.0;
187 for (var i=0; i<dimen; i++)
188 sum += vec[i]*vec[i];
189 sum = Math.sqrt( sum );
190
191 if (Math.abs(sum) >= 0.001)
192 {
193 var scale = len/sum;
194 rtnVec = [];
195 for (var i=0; i<dimen; i++)
196 rtnVec[i] = vec[i]*scale;
197 }
198
199 return rtnVec;
200 },
201
202 this.transformPoint = function( srcPt, mat )
203 {
204 var pt = srcPt.slice(0);
205 var x = this.vecDot(3, pt, [mat[0], mat[4], mat[ 8]] ) + mat[12],
206 y = this.vecDot(3, pt, [mat[1], mat[5], mat[ 9]] ) + mat[13],
207 z = this.vecDot(3, pt, [mat[2], mat[6], mat[10]] ) + mat[14];
208
209 return [x, y, z];
210 }
116} 211}
117 212
118function getPropertyFromString( prop, str ) 213function getPropertyFromString( prop, str )
@@ -183,7 +278,7 @@ function RuntimeRectangle()
183 rad = tlRad - inset; 278 rad = tlRad - inset;
184 if (rad < 0) rad = 0; 279 if (rad < 0) rad = 0;
185 pt[1] += rad; 280 pt[1] += rad;
186 if (MathUtils.fpSign(rad) == 0) pt[1] = inset; 281 if (Math.abs(rad) < 0.001) pt[1] = inset;
187 ctx.moveTo( pt[0], pt[1] ); 282 ctx.moveTo( pt[0], pt[1] );
188 283
189 // get the bottom left point 284 // get the bottom left point
@@ -194,7 +289,7 @@ function RuntimeRectangle()
194 ctx.lineTo( pt[0], pt[1] ); 289 ctx.lineTo( pt[0], pt[1] );
195 290
196 // get the bottom left curve 291 // get the bottom left curve
197 if (MathUtils.fpSign(rad) > 0) 292 if (rad > 0.001)
198 ctx.quadraticCurveTo( inset, height-inset, inset+rad, height-inset ); 293 ctx.quadraticCurveTo( inset, height-inset, inset+rad, height-inset );
199 294
200 // do the bottom of the rectangle 295 // do the bottom of the rectangle
@@ -205,7 +300,7 @@ function RuntimeRectangle()
205 ctx.lineTo( pt[0], pt[1] ); 300 ctx.lineTo( pt[0], pt[1] );
206 301
207 // get the bottom right arc 302 // get the bottom right arc
208 if (MathUtils.fpSign(rad) > 0) 303 if (rad > 0.001)
209 ctx.quadraticCurveTo( width-inset, height-inset, width-inset, height-inset-rad ); 304 ctx.quadraticCurveTo( width-inset, height-inset, width-inset, height-inset-rad );
210 305
211 // get the right of the rectangle 306 // get the right of the rectangle
@@ -216,7 +311,7 @@ function RuntimeRectangle()
216 ctx.lineTo( pt[0], pt[1] ); 311 ctx.lineTo( pt[0], pt[1] );
217 312
218 // do the top right corner 313 // do the top right corner
219 if (MathUtils.fpSign(rad) > 0) 314 if (rad > 0.001)
220 ctx.quadraticCurveTo( width-inset, inset, width-inset-rad, inset ); 315 ctx.quadraticCurveTo( width-inset, inset, width-inset-rad, inset );
221 316
222 // do the top of the rectangle 317 // do the top of the rectangle
@@ -227,7 +322,7 @@ function RuntimeRectangle()
227 ctx.lineTo( pt[0], pt[1] ); 322 ctx.lineTo( pt[0], pt[1] );
228 323
229 // do the top left corner 324 // do the top left corner
230 if (MathUtils.fpSign(rad) > 0) 325 if (rad > 0.001)
231 ctx.quadraticCurveTo( inset, inset, inset, inset+rad ); 326 ctx.quadraticCurveTo( inset, inset, inset, inset+rad );
232 else 327 else
233 ctx.lineTo( inset, 2*inset ); 328 ctx.lineTo( inset, 2*inset );
@@ -287,5 +382,227 @@ function RuntimeOval()
287 // inherit the members of RuntimeGeomObj 382 // inherit the members of RuntimeGeomObj
288 this.inheritedFrom = RuntimeGeomObj; 383 this.inheritedFrom = RuntimeGeomObj;
289 this.inheritedFrom(); 384 this.inheritedFrom();
385
386 this.import = function( importStr )
387 {
388 this._xOffset = Number( getPropertyFromString( "xoff: ", importStr ) );
389 this._yOffset = Number( getPropertyFromString( "yoff: ", importStr ) );
390 this._width = Number( getPropertyFromString( "width: ", importStr ) );
391 this._height = Number( getPropertyFromString( "height: ", importStr ) );
392 this._strokeWidth = Number( getPropertyFromString( "strokeWidth: ", importStr ) );
393 this._innerRadius = Number( getPropertyFromString( "innerRadius: ", importStr ) );
394 this._strokeStyle = getPropertyFromString( "strokeStyle: ", importStr );
395 var strokeMaterialName = getPropertyFromString( "strokeMat: ", importStr );
396 var fillMaterialName = getPropertyFromString( "fillMat: ", importStr );
397 this._fillColor = eval( "[" + getPropertyFromString( "fillColor: ", importStr ) + "]" );
398 this._strokeColor = eval( "[" + getPropertyFromString( "strokeColor: ", importStr ) + "]" );
399
400 this.importMaterials( importStr );
401 }
402
403 this.render = function()
404 {
405 // get the world
406 var world = this.getWorld();
407 if (!world) throw( "null world in buildBuffers" );
408
409 // get the context
410 var ctx = world.get2DContext();
411 if (!ctx) return;
412
413 // declare some variables
414 var p0, p1;
415 var x0, y1, x1, y1;
416
417 // create the matrix
418 var lineWidth = this._strokeWidth;
419 var innerRad = this._innerRadius;