aboutsummaryrefslogtreecommitdiff
path: root/js/lib/drawing/world.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/drawing/world.js')
-rwxr-xr-xjs/lib/drawing/world.js58
1 files changed, 29 insertions, 29 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index 3d6c6fc4..7c5fb136 100755
--- a/js/lib/drawing/world.js
+++ b/js/lib/drawing/world.js
@@ -141,45 +141,45 @@ var World = function GLWorld( canvas, use3D ) {
141 141
142 // post-load processing of the scene 142 // post-load processing of the scene
143 this.init = function() { 143 this.init = function() {
144 var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle), 144 var ctx1 = RDGE.globals.engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle),
145 ctx2 = g_Engine.getContext(); 145 ctx2 = RDGE.globals.engine.getContext();
146 if (ctx1 != ctx2) console.log( "***** different contexts *****" ); 146 if (ctx1 != ctx2) console.log( "***** different contexts *****" );
147 this.renderer = ctx1.renderer; 147 this.renderer = ctx1.renderer;
148 this.renderer._world = this; 148 this.renderer._world = this;
149 149
150 // create a camera, set its perspective, and then point it at the origin 150 // create a camera, set its perspective, and then point it at the origin
151 var cam = new camera(); 151 var cam = new RDGE.camera();
152 this._camera = cam; 152 this._camera = cam;
153 cam.setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar()); 153 cam.setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar());
154 cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], vec3.up()); 154 cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], RDGE.vec3.up());
155 155
156 // make this camera the active camera 156 // make this camera the active camera
157 this.renderer.cameraManager().setActiveCamera(cam); 157 this.renderer.cameraManager().setActiveCamera(cam);
158 158
159 // change clear color 159 // change clear color
160 //this.renderer.setClearFlags(g_Engine.getContext().DEPTH_BUFFER_BIT); 160 //this.renderer.setClearFlags(RDGE.globals.engine.getContext().DEPTH_BUFFER_BIT);
161 this.renderer.setClearColor([0.0, 0.0, 0.0, 0.0]); 161 this.renderer.setClearColor([0.0, 0.0, 0.0, 0.0]);
162 //this.renderer.NinjaWorld = this; 162 //this.renderer.NinjaWorld = this;
163 163
164 // create an empty scene graph 164 // create an empty scene graph
165 this.myScene = new SceneGraph(); 165 this.myScene = new RDGE.SceneGraph();
166 166
167 // create some lights 167 // create some lights
168 // light 1 168 // light 1
169 this.light = createLightNode("myLight"); 169 this.light = RDGE.createLightNode("myLight");
170 this.light.setPosition([0,0,1.2]); 170 this.light.setPosition([0,0,1.2]);
171 this.light.setDiffuseColor([0.75,0.9,1.0,1.0]); 171 this.light.setDiffuseColor([0.75,0.9,1.0,1.0]);
172 172
173 // light 2 173 // light 2
174 this.light2 = createLightNode("myLight2"); 174 this.light2 = RDGE.createLightNode("myLight2");
175 this.light2.setPosition([-0.5,0,1.2]); 175 this.light2.setPosition([-0.5,0,1.2]);
176 this.light2.setDiffuseColor([1.0,0.9,0.75,1.0]); 176 this.light2.setDiffuseColor([1.0,0.9,0.75,1.0]);
177 177
178 // create a light transform 178 // create a light transform
179 var lightTr = createTransformNode("lightTr"); 179 var lightTr = RDGE.createTransformNode("lightTr");
180 180
181 // create and attach a material - materials hold the light data 181 // create and attach a material - materials hold the light data
182 lightTr.attachMaterial(createMaterialNode("lights")); 182 lightTr.attachMaterial(RDGE.createMaterialNode("lights"));
183 183
184 // enable light channels 1, 2 - channel 0 is used by the default shader 184 // enable light channels 1, 2 - channel 0 is used by the default shader
185 lightTr.materialNode.enableLightChannel(1, this.light); 185 lightTr.materialNode.enableLightChannel(1, this.light);
@@ -192,9 +192,9 @@ var World = function GLWorld( canvas, use3D ) {
192 this.myScene.addNode(lightTr); 192 this.myScene.addNode(lightTr);
193 193
194 // Add the scene to the engine - necessary if you want the engine to draw for you 194 // Add the scene to the engine - necessary if you want the engine to draw for you
195 //g_Engine.AddScene("myScene" + this._canvas.id, this.myScene); 195 //RDGE.globals.engine.AddScene("myScene" + this._canvas.id, this.myScene);
196 var name = this._canvas.getAttribute( "data-RDGE-id" ); 196 var name = this._canvas.getAttribute( "data-RDGE-id" );
197 g_Engine.AddScene("myScene" + name, this.myScene); 197 RDGE.globals.engine.AddScene("myScene" + name, this.myScene);
198 }; 198 };
199 199
200 // main code for handling user interaction and updating the scene 200 // main code for handling user interaction and updating the scene
@@ -206,7 +206,7 @@ var World = function GLWorld( canvas, use3D ) {
206 206
207 if (this._useWebGL) { 207 if (this._useWebGL) {
208 // changed the global position uniform of light 0, another way to change behavior of a light 208 // changed the global position uniform of light 0, another way to change behavior of a light
209 rdgeGlobalParameters.u_light0Pos.set( [5*Math.cos(this.elapsed), 5*Math.sin(this.elapsed), 20]); 209 RDGE.rdgeGlobalParameters.u_light0Pos.set([5 * Math.cos(this.elapsed), 5 * Math.sin(this.elapsed), 20]);
210 210
211 // orbit the light nodes around the boxes 211 // orbit the light nodes around the boxes
212 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)]); 212 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)]);
@@ -223,8 +223,8 @@ var World = function GLWorld( canvas, use3D ) {
223 // defining the draw function to control how the scene is rendered 223 // defining the draw function to control how the scene is rendered
224 this.draw = function() { 224 this.draw = function() {
225 if (this._useWebGL) { 225 if (this._useWebGL) {
226 g_Engine.setContext( this._canvas.rdgeid ); 226 RDGE.globals.engine.setContext( this._canvas.rdgeid );
227 var ctx = g_Engine.getContext(); 227 var ctx = RDGE.globals.engine.getContext();
228 var renderer = ctx.renderer; 228 var renderer = ctx.renderer;
229 if (renderer.unloadedTextureCount <= 0) { 229 if (renderer.unloadedTextureCount <= 0) {
230 renderer.disableCulling(); 230 renderer.disableCulling();
@@ -361,8 +361,8 @@ var World = function GLWorld( canvas, use3D ) {
361 rdgeStarted = true; 361 rdgeStarted = true;
362 var id = this._canvas.getAttribute( "data-RDGE-id" ); 362 var id = this._canvas.getAttribute( "data-RDGE-id" );
363 this._canvas.rdgeid = id; 363 this._canvas.rdgeid = id;
364 g_Engine.registerCanvas(this._canvas, this); 364 RDGE.globals.engine.registerCanvas(this._canvas, this);
365 RDGEStart( this._canvas ); 365 RDGE.RDGEStart( this._canvas );
366 this._canvas.task.stop() 366 this._canvas.task.stop()
367 } 367 }
368}; 368};
@@ -391,13 +391,13 @@ World.prototype.updateObject = function (obj) {
391 if (nPrims > 0) { 391 if (nPrims > 0) {
392 ctrTrNode = obj.getTransformNode(); 392 ctrTrNode = obj.getTransformNode();
393 if (ctrTrNode == null) { 393 if (ctrTrNode == null) {
394 ctrTrNode = createTransformNode("objRootNode_" + nodeCounter++); 394 ctrTrNode = RDGE.createTransformNode("objRootNode_" + nodeCounter++);
395 this._rootNode.insertAsChild( ctrTrNode ); 395 this._rootNode.insertAsChild( ctrTrNode );
396 obj.setTransformNode( ctrTrNode ); 396 obj.setTransformNode( ctrTrNode );
397 } 397 }
398 398
399 ctrTrNode.meshes.forEach(function(thisMesh) { 399 ctrTrNode.meshes.forEach(function(thisMesh) {
400 g_meshMan.deleteMesh(thisMesh.mesh.name); 400 RDGE.globals.meshMan.deleteMesh(thisMesh.mesh.name);
401 }); 401 });
402 ctrTrNode.meshes = []; 402 ctrTrNode.meshes = [];
403 403
@@ -416,11 +416,11 @@ World.prototype.updateObject = function (obj) {
416 childTrNode = children[i-1].transformNode; 416 childTrNode = children[i-1].transformNode;
417 417
418 childTrNode.meshes.forEach(function(thisMesh) { 418 childTrNode.meshes.forEach(function(thisMesh) {
419 g_meshMan.deleteMesh(thisMesh.mesh.name); 419 RDGE.globals.meshMan.deleteMesh(thisMesh.mesh.name);
420 }); 420 });
421 childTrNode.meshes = []; 421 childTrNode.meshes = [];
422 } else { 422 } else {
423 childTrNode = createTransformNode("objNode_" + nodeCounter++); 423 childTrNode = RDGE.createTransformNode("objNode_" + nodeCounter++);
424 ctrTrNode.insertAsChild(childTrNode); 424 ctrTrNode.insertAsChild(childTrNode);
425 } 425 }
426 426
@@ -522,7 +522,7 @@ World.prototype.clearTree = function() {
522 if (this._useWebGL) { 522 if (this._useWebGL) {
523 var root = this._rootNode; 523 var root = this._rootNode;
524 root.children = new Array(); 524 root.children = new Array();
525 g_Engine.unregisterCanvas( this._canvas.rdgeid ) 525 RDGE.globals.engine.unregisterCanvas( this._canvas.rdgeid )
526 526
527 this.update( 0 ); 527 this.update( 0 );
528 this.draw(); 528 this.draw();
@@ -657,9 +657,9 @@ World.prototype.setMVMatrix = function() {
657 gl.uniformMatrix4fv(this._shaderProgram.mvMatrixUniform, false, new Float32Array(mvMatrix)); 657 gl.uniformMatrix4fv(this._shaderProgram.mvMatrixUniform, false, new Float32Array(mvMatrix));
658 658
659 var normalMatrix = mat3.create(); 659 var normalMatrix = mat3.create();
660 // mat4.toInverseMat3(mvMatrix, normalMatrix); 660 // RDGE.mat4.toInverseMat3(mvMatrix, normalMatrix);
661 // mat4.toInverseMat3(new Float32Array(mvMatrix.flatten()), normalMatrix); 661 // RDGE.mat4.toInverseMat3(new Float32Array(mvMatrix.flatten()), normalMatrix);
662 mat4.toInverseMat3(new Float32Array(mvMatrix), normalMatrix); 662 RDGE.mat4.toInverseMat3(new Float32Array(mvMatrix), normalMatrix);
663 mat3.transpose(normalMatrix); 663 mat3.transpose(normalMatrix);
664 gl.uniformMatrix3fv(this._shaderProgram.nMatrixUniform, false, normalMatrix); 664 gl.uniformMatrix3fv(this._shaderProgram.nMatrixUniform, false, normalMatrix);
665 } 665 }
@@ -680,7 +680,7 @@ World.prototype.render = function() {
680 var root = this.getGeomRoot(); 680 var root = this.getGeomRoot();
681 this.hRender( root ); 681 this.hRender( root );
682 } else { 682 } else {
683 g_Engine.setContext( this._canvas.rdgeId ); 683 RDGE.globals.engine.setContext( this._canvas.rdgeId );
684 //this.draw(); 684 //this.draw();
685 this.restartRenderLoop(); 685 this.restartRenderLoop();
686 } 686 }
@@ -895,16 +895,16 @@ World.prototype.importSubObject = function( objStr, parentNode ) {
895 i0 += 10; 895 i0 += 10;
896 var matText = objStr.substr( i0, i1 - i0 ); 896 var matText = objStr.substr( i0, i1 - i0 );
897 var shaderDef = JSON.parse( matText ); 897 var shaderDef = JSON.parse( matText );
898 var shader = new jshader(); 898 var shader = new RDGE.jshader();
899 shader.def = shaderDef; 899 shader.def = shaderDef;
900 shader.init(); 900 shader.init();
901 901
902 // set the shader for this material 902 // set the shader for this material
903 var matNode = createMaterialNode("objMat") 903 var matNode = RDGE.createMaterialNode("objMat")
904 matNode.setShader(shader); 904 matNode.setShader(shader);
905 905
906 // create the transformation node 906 // create the transformation node
907 var trNode = createTransformNode("subObjNode_" ); 907 var trNode = RDGE.createTransformNode("subObjNode_");
908 trNode.attachMeshNode(this.renderer.id + "_prim_", meshObj); 908 trNode.attachMeshNode(this.renderer.id + "_prim_", meshObj);
909 trNode.attachMaterial(matNode); 909 trNode.attachMaterial(matNode);
910 parentNode.insertAsChild(trNode); 910 parentNode.insertAsChild(trNode);