aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/runtime
diff options
context:
space:
mode:
authorhwc4872012-03-05 15:16:52 -0800
committerhwc4872012-03-05 15:16:52 -0800
commitec10bf44c711e9c552780d2cd9ac0baef21de445 (patch)
tree1a48fef7db5c560e997ce3d345fa351dc878a8bb /js/helper-classes/RDGE/runtime
parentcad4d6cb3f667f6174ec05cecead675b244285b9 (diff)
downloadninja-ec10bf44c711e9c552780d2cd9ac0baef21de445.tar.gz
WebGL & Canvas2D file IO
Diffstat (limited to 'js/helper-classes/RDGE/runtime')
-rw-r--r--js/helper-classes/RDGE/runtime/GLRuntime.js4
-rw-r--r--js/helper-classes/RDGE/runtime/RuntimeGeomObj.js331
-rw-r--r--js/helper-classes/RDGE/runtime/RuntimeMaterial.js103
3 files changed, 421 insertions, 17 deletions
diff --git a/js/helper-classes/RDGE/runtime/GLRuntime.js b/js/helper-classes/RDGE/runtime/GLRuntime.js
index e0fff4a8..58cb4e33 100644
--- a/js/helper-classes/RDGE/runtime/GLRuntime.js
+++ b/js/helper-classes/RDGE/runtime/GLRuntime.js
@@ -131,7 +131,7 @@ function GLRuntime( canvas, importStr )
131 this.elapsed += dt; 131 this.elapsed += dt;
132 132
133 // changed the global position uniform of light 0, another way to change behavior of a light 133 // changed the global position uniform of light 0, another way to change behavior of a light
134 //rdgeGlobalParameters.u_light0Pos.set( [5*Math.cos(this.elapsed), 5*Math.sin(this.elapsed), 20]); 134 rdgeGlobalParameters.u_light0Pos.set( [5*Math.cos(this.elapsed), 5*Math.sin(this.elapsed), 20]);
135 135
136 // orbit the light nodes around the boxes 136 // orbit the light nodes around the boxes
137 //this.light.setPosition([1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), 1.2*Math.cos(this.elapsed*2.0)]); 137 //this.light.setPosition([1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), 1.2*Math.cos(this.elapsed*2.0)]);
@@ -328,6 +328,8 @@ function GLRuntime( canvas, importStr )
328 } 328 }
329 329
330 // start RDGE or load Canvas 2D objects 330 // start RDGE or load Canvas 2D objects
331 var index = importStr.indexOf( "scenedata: " );
332 this._useWebGL = (index >= 0);
331 if (this._useWebGL) 333 if (this._useWebGL)
332 { 334 {
333 var id = canvas.getAttribute( "data-RDGE-id" ); 335 var id = canvas.getAttribute( "data-RDGE-id" );
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