aboutsummaryrefslogtreecommitdiff
path: root/js/lib/drawing
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/drawing')
-rwxr-xr-xjs/lib/drawing/world.js66
1 files changed, 33 insertions, 33 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index b20b0a5d..08f9d319 100755
--- a/js/lib/drawing/world.js
+++ b/js/lib/drawing/world.js
@@ -68,7 +68,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
68 { 68 {
69 this._2DContext = canvas.getContext( "2d" ); 69 this._2DContext = canvas.getContext( "2d" );
70 } 70 }
71 71
72 this._viewportWidth = canvas.width; 72 this._viewportWidth = canvas.width;
73 this._viewportHeight = canvas.height; 73 this._viewportHeight = canvas.height;
74 74
@@ -152,7 +152,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
152 152
153 // Flag to play/pause animation at authortime 153 // Flag to play/pause animation at authortime
154 this._previewAnimation = true; 154 this._previewAnimation = true;
155 155
156 //////////////////////////////////////////////////////////////////////////////////// 156 ////////////////////////////////////////////////////////////////////////////////////
157 // RDGE 157 // RDGE
158 // local variables 158 // local variables
@@ -175,7 +175,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
175 var camMat = Matrix.I(4); 175 var camMat = Matrix.I(4);
176 camMat[14] = this.getViewDistance(); 176 camMat[14] = this.getViewDistance();
177 this.setCameraMat( camMat ); 177 this.setCameraMat( camMat );
178 178
179 // post-load processing of the scene 179 // post-load processing of the scene
180 this.init = function() 180 this.init = function()
181 { 181 {
@@ -184,13 +184,13 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
184 if (ctx1 != ctx2) console.log( "***** different contexts *****" ); 184 if (ctx1 != ctx2) console.log( "***** different contexts *****" );
185 this.renderer = ctx1.renderer; 185 this.renderer = ctx1.renderer;
186 this.renderer._world = this; 186 this.renderer._world = this;
187 187
188 // create a camera, set its perspective, and then point it at the origin 188 // create a camera, set its perspective, and then point it at the origin
189 var cam = new RDGE.camera(); 189 var cam = new RDGE.camera();
190 this._camera = cam; 190 this._camera = cam;
191 cam.setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar()); 191 cam.setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar());
192 cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], RDGE.vec3.up()); 192 cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], RDGE.vec3.up());
193 193
194 // make this camera the active camera 194 // make this camera the active camera
195 this.renderer.cameraManager().setActiveCamera(cam); 195 this.renderer.cameraManager().setActiveCamera(cam);
196 196
@@ -198,61 +198,61 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
198 //this.renderer.setClearFlags(RDGE.globals.engine.getContext().DEPTH_BUFFER_BIT); 198 //this.renderer.setClearFlags(RDGE.globals.engine.getContext().DEPTH_BUFFER_BIT);
199 this.renderer.setClearColor([0.0, 0.0, 0.0, 0.0]); 199 this.renderer.setClearColor([0.0, 0.0, 0.0, 0.0]);
200 //this.renderer.NinjaWorld = this; 200 //this.renderer.NinjaWorld = this;
201 201
202 // create an empty scene graph 202 // create an empty scene graph
203 this.myScene = new RDGE.SceneGraph(); 203 this.myScene = new RDGE.SceneGraph();
204 204
205 // create some lights 205 // create some lights
206 // light 1 206 // light 1
207// this.light = RDGE.createLightNode("myLight"); 207// this.light = RDGE.createLightNode("myLight");
208// this.light.setPosition([0,0,1.2]); 208// this.light.setPosition([0,0,1.2]);
209// this.light.setDiffuseColor([0.75,0.9,1.0,1.0]); 209// this.light.setDiffuseColor([0.75,0.9,1.0,1.0]);
210 210
211 // light 2 211 // light 2
212// this.light2 = RDGE.createLightNode("myLight2"); 212// this.light2 = RDGE.createLightNode("myLight2");
213// this.light2.setPosition([-0.5,0,1.2]); 213// this.light2.setPosition([-0.5,0,1.2]);
214// this.light2.setDiffuseColor([1.0,0.9,0.75,1.0]); 214// this.light2.setDiffuseColor([1.0,0.9,0.75,1.0]);
215 215
216 // create a light transform 216 // create a light transform
217 var lightTr = RDGE.createTransformNode("lightTr"); 217 var lightTr = RDGE.createTransformNode("lightTr");
218 218
219 // create and attach a material - materials hold the light data 219 // create and attach a material - materials hold the light data
220 lightTr.attachMaterial(RDGE.createMaterialNode("lights")); 220 lightTr.attachMaterial(RDGE.createMaterialNode("lights"));
221 221
222 // enable light channels 1, 2 - channel 0 is used by the default shader 222 // enable light channels 1, 2 - channel 0 is used by the default shader
223// lightTr.materialNode.enableLightChannel(1, this.light); 223// lightTr.materialNode.enableLightChannel(1, this.light);
224// lightTr.materialNode.enableLightChannel(2, this.light2); 224// lightTr.materialNode.enableLightChannel(2, this.light2);
225 225
226 // all added objects are parented to the light node 226 // all added objects are parented to the light node
227 this._rootNode = lightTr; 227 this._rootNode = lightTr;
228 228
229 // add the light node to the scene 229 // add the light node to the scene
230 this.myScene.addNode(lightTr); 230 this.myScene.addNode(lightTr);
231 231
232 // Add the scene to the engine - necessary if you want the engine to draw for you 232 // Add the scene to the engine - necessary if you want the engine to draw for you
233 //RDGE.globals.engine.AddScene("myScene" + this._canvas.id, this.myScene); 233 //RDGE.globals.engine.AddScene("myScene" + this._canvas.id, this.myScene);
234 var name = this._canvas.getAttribute( "data-RDGE-id" ); 234 var name = this._canvas.getAttribute( "data-RDGE-id" );
235 RDGE.globals.engine.AddScene("myScene" + name, this.myScene); 235 RDGE.globals.engine.AddScene("myScene" + name, this.myScene);
236 }; 236 };
237 237
238 // main code for handling user interaction and updating the scene 238 // main code for handling user interaction and updating the scene
239 this.update = function(dt) 239 this.update = function(dt)
240 { 240 {
241 if (!dt) dt = 0.2; 241 if (!dt) dt = 0.2;
242 242
243 dt = 0.01; // use our own internal throttle 243 dt = 0.01; // use our own internal throttle
244 this.elapsed += dt; 244 this.elapsed += dt;
245 245
246 if (this._useWebGL) 246 if (this._useWebGL)
247 { 247 {
248 // changed the global position uniform of light 0, another way to change behavior of a light 248 // changed the global position uniform of light 0, another way to change behavior of a light
249 RDGE.rdgeGlobalParameters.u_light0Pos.set([5 * Math.cos(this.elapsed), 5 * Math.sin(this.elapsed), 20]); 249 RDGE.rdgeGlobalParameters.u_light0Pos.set([5 * Math.cos(this.elapsed), 5 * Math.sin(this.elapsed), 20]);
250 250
251 // orbit the light nodes around the boxes 251 // orbit the light nodes around the boxes
252// 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)]); 252// 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)]);
253// this.light2.setPosition([-1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), -1.2*Math.cos(this.elapsed)]); 253// this.light2.setPosition([-1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), -1.2*Math.cos(this.elapsed)]);
254 } 254 }
255 255
256 this.updateMaterials( this.getGeomRoot(), this.elapsed ); 256 this.updateMaterials( this.getGeomRoot(), this.elapsed );
257 257
258 // now update all the nodes in the scene 258 // now update all the nodes in the scene
@@ -260,7 +260,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
260 this.myScene.update(dt); 260 this.myScene.update(dt);
261 }; 261 };
262 262
263 // defining the draw function to control how the scene is rendered 263 // defining the draw function to control how the scene is rendered
264 this.draw = function() 264 this.draw = function()
265 { 265 {
266 if (this._useWebGL) 266 if (this._useWebGL)
@@ -306,12 +306,12 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
306 this.render(); 306 this.render();
307 } 307 }
308 }; 308 };
309 309
310 this.onRunState = function() { 310 this.onRunState = function() {
311// console.log( "GLWorld.onRunState" ); 311// console.log( "GLWorld.onRunState" );
312 this.restartRenderLoop(); 312 this.restartRenderLoop();
313 }; 313 };
314 314
315 this.onLoadState = function() { 315 this.onLoadState = function() {
316// console.log( "GLWorld.onLoadState" ); 316// console.log( "GLWorld.onLoadState" );
317 }; 317 };
@@ -375,7 +375,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
375 world.textureMapLoaded( name ); 375 world.textureMapLoaded( name );
376 } 376 }
377 }; 377 };
378 378
379 this.hasAnimatedMaterials = function() { 379 this.hasAnimatedMaterials = function() {
380 var root = this.getGeomRoot(); 380 var root = this.getGeomRoot();
381 var rtnVal = false; 381 var rtnVal = false;
@@ -433,7 +433,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
433 { 433 {
434 this._notifier.removeListener( obj ); 434 this._notifier.removeListener( obj );
435 } 435 }
436 436
437 // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state 437 // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state
438 // in the case of a procedurally built scene an init state is not needed for loading data 438 // in the case of a procedurally built scene an init state is not needed for loading data
439 this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" ); 439 this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" );
@@ -486,7 +486,7 @@ World.prototype.updateObject = function (obj) {
486 ctrTrNode.attachMeshNode(this.renderer.id + "_prim_" + this._nodeCounter++, prims[0]); 486 ctrTrNode.attachMeshNode(this.renderer.id + "_prim_" + this._nodeCounter++, prims[0]);
487 ctrTrNode.attachMaterial(materialNodes[0]); 487 ctrTrNode.attachMaterial(materialNodes[0]);
488 } 488 }
489 489
490 // delete all of the child nodes 490 // delete all of the child nodes
491 var i; 491 var i;
492 var childTrNode; 492 var childTrNode;
@@ -803,11 +803,11 @@ World.prototype.render = function()
803 var ctx = this.get2DContext(); 803 var ctx = this.get2DContext();
804 if (!ctx) return; 804 if (!ctx) return;
805 ctx.clearRect(0, 0, this.getViewportWidth(), this.getViewportHeight()); 805 ctx.clearRect(0, 0, this.getViewportWidth(), this.getViewportHeight());
806 806
807 // render the geometry 807 // render the geometry
808 var root = this.getGeomRoot(); 808 var root = this.getGeomRoot();
809 this.hRender( root ); 809 this.hRender( root );
810 } 810 }
811 else 811 else
812 { 812 {
813 RDGE.globals.engine.setContext( this._canvas.rdgeid ); 813 RDGE.globals.engine.setContext( this._canvas.rdgeid );
@@ -834,7 +834,7 @@ World.prototype.setViewportFromCanvas = function(canvas) {
834 this._glContext.viewportHeight = canvas.height; 834 this._glContext.viewportHeight = canvas.height;
835 835
836 this.getCamera().setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar()); 836 this.getCamera().setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar());
837 837
838 this.renderer.setViewPort(0, 0, canvas.width, canvas.height); 838 this.renderer.setViewPort(0, 0, canvas.width, canvas.height);
839 } 839 }
84