diff options
author | hwc487 | 2012-03-05 15:16:52 -0800 |
---|---|---|
committer | hwc487 | 2012-03-05 15:16:52 -0800 |
commit | ec10bf44c711e9c552780d2cd9ac0baef21de445 (patch) | |
tree | 1a48fef7db5c560e997ce3d345fa351dc878a8bb /js/helper-classes/RDGE | |
parent | cad4d6cb3f667f6174ec05cecead675b244285b9 (diff) | |
download | ninja-ec10bf44c711e9c552780d2cd9ac0baef21de445.tar.gz |
WebGL & Canvas2D file IO
Diffstat (limited to 'js/helper-classes/RDGE')
-rwxr-xr-x | js/helper-classes/RDGE/GLCircle.js | 3 | ||||
-rwxr-xr-x | js/helper-classes/RDGE/GLWorld.js | 17 | ||||
-rwxr-xr-x | js/helper-classes/RDGE/Materials/BumpMetalMaterial.js | 2 | ||||
-rwxr-xr-x | js/helper-classes/RDGE/Materials/RadialGradientMaterial.js | 4 | ||||
-rw-r--r-- | js/helper-classes/RDGE/runtime/GLRuntime.js | 4 | ||||
-rw-r--r-- | js/helper-classes/RDGE/runtime/RuntimeGeomObj.js | 331 | ||||
-rw-r--r-- | js/helper-classes/RDGE/runtime/RuntimeMaterial.js | 103 |
7 files changed, 433 insertions, 31 deletions
diff --git a/js/helper-classes/RDGE/GLCircle.js b/js/helper-classes/RDGE/GLCircle.js index 15ed6b6d..59d0bdaf 100755 --- a/js/helper-classes/RDGE/GLCircle.js +++ b/js/helper-classes/RDGE/GLCircle.js | |||
@@ -381,7 +381,6 @@ function GLCircle() | |||
381 | // translate | 381 | // translate |
382 | var xCtr = 0.5*world.getViewportWidth() + this._xOffset, | 382 | var xCtr = 0.5*world.getViewportWidth() + this._xOffset, |
383 | yCtr = 0.5*world.getViewportHeight() + this._yOffset; | 383 | yCtr = 0.5*world.getViewportHeight() + this._yOffset; |
384 | //ctx.setTransform( xScale, 0.0, 0.0, yScale, xCtr, yCtr ); | ||
385 | var mat = Matrix.create( [ | 384 | var mat = Matrix.create( [ |
386 | [ xScale, 0.0, 0.0, xCtr], | 385 | [ xScale, 0.0, 0.0, xCtr], |
387 | [ 0.0, yScale, 0.0, yCtr], | 386 | [ 0.0, yScale, 0.0, yCtr], |
@@ -538,6 +537,8 @@ function GLCircle() | |||
538 | rtnStr += "flatMaterial"; | 537 | rtnStr += "flatMaterial"; |
539 | rtnStr += "\n"; | 538 | rtnStr += "\n"; |
540 | 539 | ||
540 | rtnStr += this.exportMaterials(); | ||
541 | |||
541 | return rtnStr; | 542 | return rtnStr; |
542 | } | 543 | } |
543 | 544 | ||
diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js index 3a779b92..ce5f0516 100755 --- a/js/helper-classes/RDGE/GLWorld.js +++ b/js/helper-classes/RDGE/GLWorld.js | |||
@@ -379,10 +379,12 @@ function GLWorld( canvas, use3D ) | |||
379 | return false; | 379 | return false; |
380 | } | 380 | } |
381 | 381 | ||
382 | 382 | this.generateUniqueNodeID = function() | |
383 | // END RDGE | 383 | { |
384 | //////////////////////////////////////////////////////////////////////////////////// | 384 | var str = String( this._nodeCounter ); |
385 | 385 | this._nodeCounter++; | |
386 | return str; | ||
387 | } | ||
386 | 388 | ||
387 | // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state | 389 | // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state |
388 | // in the case of a procedurally built scene an init state is not needed for loading data | 390 | // in the case of a procedurally built scene an init state is not needed for loading data |
@@ -395,13 +397,6 @@ function GLWorld( canvas, use3D ) | |||
395 | RDGEStart( this._canvas ); | 397 | RDGEStart( this._canvas ); |
396 | this._canvas.task.stop() | 398 | this._canvas.task.stop() |
397 | } | 399 | } |
398 | |||
399 | this.generateUniqueNodeID = function() | ||
400 | { | ||
401 | var str = String( this._nodeCounter ); | ||
402 | this._nodeCounter++; | ||
403 | return str; | ||
404 | } | ||
405 | } | 400 | } |
406 | 401 | ||
407 | 402 | ||
diff --git a/js/helper-classes/RDGE/Materials/BumpMetalMaterial.js b/js/helper-classes/RDGE/Materials/BumpMetalMaterial.js index 1a6c54c9..52332ab8 100755 --- a/js/helper-classes/RDGE/Materials/BumpMetalMaterial.js +++ b/js/helper-classes/RDGE/Materials/BumpMetalMaterial.js | |||
@@ -65,7 +65,7 @@ function BumpMetalMaterial() | |||
65 | this.setProperty = function( prop, value ) | 65 | this.setProperty = function( prop, value ) |
66 | { | 66 | { |
67 | // every material should do something with the "color" property | 67 | // every material should do something with the "color" property |
68 | if (prop === "color") prop = "lightDiff"; | 68 | if (prop === "color") return; //prop = "lightDiff"; |
69 | 69 | ||
70 | // make sure we have legitimate imput | 70 | // make sure we have legitimate imput |
71 | var ok = this.validateProperty( prop, value ); | 71 | var ok = this.validateProperty( prop, value ); |
diff --git a/js/helper-classes/RDGE/Materials/RadialGradientMaterial.js b/js/helper-classes/RDGE/Materials/RadialGradientMaterial.js index 4ebb1f30..45b260ef 100755 --- a/js/helper-classes/RDGE/Materials/RadialGradientMaterial.js +++ b/js/helper-classes/RDGE/Materials/RadialGradientMaterial.js | |||
@@ -146,8 +146,10 @@ function RadialGradientMaterial() | |||
146 | // duplcate method requirde | 146 | // duplcate method requirde |
147 | this.dup = function() { return new RadialGradientMaterial(); } | 147 | this.dup = function() { return new RadialGradientMaterial(); } |
148 | 148 | ||
149 | this.init = function() | 149 | this.init = function( world ) |
150 | { | 150 | { |
151 | this.setWorld( world ); | ||
152 | |||
151 | // set up the shader | 153 | // set up the shader |
152 | this._shader = new jshader(); | 154 | this._shader = new jshader(); |
153 | this._shader.def = radialGradientMaterialDef; | 155 | this._shader.def = radialGradientMaterialDef; |
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; | ||