aboutsummaryrefslogtreecommitdiff
path: root/js/lib/drawing
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-04-04 17:24:27 -0700
committerNivesh Rajbhandari2012-04-04 17:24:27 -0700
commit01cf259da7aaa7d70789d9a7c32111d88b477463 (patch)
tree0bff3395ac681e5f685d2267f7dbc03a8e32bc4a /js/lib/drawing
parent331ea08655245e3532e48bf160d5f68a04d8723f (diff)
parent13368ca6ebbc13adeafccd898dfffd7ce37cb28a (diff)
downloadninja-01cf259da7aaa7d70789d9a7c32111d88b477463.tar.gz
Merge branch 'refs/heads/ToolFixes' into WebGLMaterials
Conflicts: js/document/templates/montage-html/default_html.css js/mediators/element-mediator.js js/panels/properties.reel/properties.js js/tools/BrushTool.js js/tools/LineTool.js js/tools/PenTool.js js/tools/SelectionTool.js js/tools/ShapeTool.js js/tools/TranslateObject3DTool.js Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js/lib/drawing')
-rwxr-xr-xjs/lib/drawing/world.js307
1 files changed, 57 insertions, 250 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index fec6a478..945c9883 100755
--- a/js/lib/drawing/world.js
+++ b/js/lib/drawing/world.js
@@ -144,45 +144,45 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
144 144
145 // post-load processing of the scene 145 // post-load processing of the scene
146 this.init = function() { 146 this.init = function() {
147 var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle), 147 var ctx1 = RDGE.globals.engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle),
148 ctx2 = g_Engine.getContext(); 148 ctx2 = RDGE.globals.engine.getContext();
149 if (ctx1 != ctx2) console.log( "***** different contexts *****" ); 149 if (ctx1 != ctx2) console.log( "***** different contexts *****" );
150 this.renderer = ctx1.renderer; 150 this.renderer = ctx1.renderer;
151 this.renderer._world = this; 151 this.renderer._world = this;
152 152
153 // create a camera, set its perspective, and then point it at the origin 153 // create a camera, set its perspective, and then point it at the origin
154 var cam = new camera(); 154 var cam = new RDGE.camera();
155 this._camera = cam; 155 this._camera = cam;
156 cam.setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar()); 156 cam.setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar());
157 cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], vec3.up()); 157 cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], RDGE.vec3.up());
158 158
159 // make this camera the active camera 159 // make this camera the active camera
160 this.renderer.cameraManager().setActiveCamera(cam); 160 this.renderer.cameraManager().setActiveCamera(cam);
161 161
162 // change clear color 162 // change clear color
163 //this.renderer.setClearFlags(g_Engine.getContext().DEPTH_BUFFER_BIT); 163 //this.renderer.setClearFlags(RDGE.globals.engine.getContext().DEPTH_BUFFER_BIT);
164 this.renderer.setClearColor([0.0, 0.0, 0.0, 0.0]); 164 this.renderer.setClearColor([0.0, 0.0, 0.0, 0.0]);
165 //this.renderer.NinjaWorld = this; 165 //this.renderer.NinjaWorld = this;
166 166
167 // create an empty scene graph 167 // create an empty scene graph
168 this.myScene = new SceneGraph(); 168 this.myScene = new RDGE.SceneGraph();
169 169
170 // create some lights 170 // create some lights
171 // light 1 171 // light 1
172 this.light = createLightNode("myLight"); 172 this.light = RDGE.createLightNode("myLight");
173 this.light.setPosition([0,0,1.2]); 173 this.light.setPosition([0,0,1.2]);
174 this.light.setDiffuseColor([0.75,0.9,1.0,1.0]); 174 this.light.setDiffuseColor([0.75,0.9,1.0,1.0]);
175 175
176 // light 2 176 // light 2
177 this.light2 = createLightNode("myLight2"); 177 this.light2 = RDGE.createLightNode("myLight2");
178 this.light2.setPosition([-0.5,0,1.2]); 178 this.light2.setPosition([-0.5,0,1.2]);
179 this.light2.setDiffuseColor([1.0,0.9,0.75,1.0]); 179 this.light2.setDiffuseColor([1.0,0.9,0.75,1.0]);
180 180
181 // create a light transform 181 // create a light transform
182 var lightTr = createTransformNode("lightTr"); 182 var lightTr = RDGE.createTransformNode("lightTr");
183 183
184 // create and attach a material - materials hold the light data 184 // create and attach a material - materials hold the light data
185 lightTr.attachMaterial(createMaterialNode("lights")); 185 lightTr.attachMaterial(RDGE.createMaterialNode("lights"));
186 186
187 // enable light channels 1, 2 - channel 0 is used by the default shader 187 // enable light channels 1, 2 - channel 0 is used by the default shader
188 lightTr.materialNode.enableLightChannel(1, this.light); 188 lightTr.materialNode.enableLightChannel(1, this.light);
@@ -195,9 +195,9 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
195 this.myScene.addNode(lightTr); 195 this.myScene.addNode(lightTr);
196 196
197 // Add the scene to the engine - necessary if you want the engine to draw for you 197 // Add the scene to the engine - necessary if you want the engine to draw for you
198 //g_Engine.AddScene("myScene" + this._canvas.id, this.myScene); 198 //RDGE.globals.engine.AddScene("myScene" + this._canvas.id, this.myScene);
199 var name = this._canvas.getAttribute( "data-RDGE-id" ); 199 var name = this._canvas.getAttribute( "data-RDGE-id" );
200 g_Engine.AddScene("myScene" + name, this.myScene); 200 RDGE.globals.engine.AddScene("myScene" + name, this.myScene);
201 }; 201 };
202 202
203 // main code for handling user interaction and updating the scene 203 // main code for handling user interaction and updating the scene
@@ -209,7 +209,7 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
209 209
210 if (this._useWebGL) { 210 if (this._useWebGL) {
211 // changed the global position uniform of light 0, another way to change behavior of a light 211 // changed the global position uniform of light 0, another way to change behavior of a light
212 rdgeGlobalParameters.u_light0Pos.set( [5*Math.cos(this.elapsed), 5*Math.sin(this.elapsed), 20]); 212 RDGE.rdgeGlobalParameters.u_light0Pos.set([5 * Math.cos(this.elapsed), 5 * Math.sin(this.elapsed), 20]);
213 213
214 // orbit the light nodes around the boxes 214 // orbit the light nodes around the boxes
215 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)]); 215 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)]);
@@ -226,8 +226,8 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
226 // defining the draw function to control how the scene is rendered 226 // defining the draw function to control how the scene is rendered
227 this.draw = function() { 227 this.draw = function() {
228 if (this._useWebGL) { 228 if (this._useWebGL) {
229 g_Engine.setContext( this._canvas.rdgeid ); 229 RDGE.globals.engine.setContext( this._canvas.rdgeid );
230 var ctx = g_Engine.getContext(); 230 var ctx = RDGE.globals.engine.getContext();
231 var renderer = ctx.renderer; 231 var renderer = ctx.renderer;
232 if (renderer.unloadedTextureCount <= 0) { 232 if (renderer.unloadedTextureCount <= 0) {
233 renderer.disableCulling(); 233 renderer.disableCulling();
@@ -365,9 +365,9 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
365 if (this._useWebGL) { 365 if (this._useWebGL) {
366 rdgeStarted = true; 366 rdgeStarted = true;
367 this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" ); 367 this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" );
368 g_Engine.unregisterCanvas( this._canvas ) 368 RDGE.globals.engine.unregisterCanvas( this._canvas );
369 g_Engine.registerCanvas(this._canvas, this); 369 RDGE.globals.engine.registerCanvas(this._canvas, this);
370 RDGEStart( this._canvas ); 370 RDGE.RDGEStart( this._canvas );
371 this._canvas.task.stop() 371 this._canvas.task.stop()
372 } 372 }
373}; 373};
@@ -396,13 +396,13 @@ World.prototype.updateObject = function (obj) {
396 if (nPrims > 0) { 396 if (nPrims > 0) {
397 ctrTrNode = obj.getTransformNode(); 397 ctrTrNode = obj.getTransformNode();
398 if (ctrTrNode == null) { 398 if (ctrTrNode == null) {
399 ctrTrNode = createTransformNode("objRootNode_" + this._nodeCounter++); 399 ctrTrNode = RDGE.createTransformNode("objRootNode_" + this._nodeCounter++);
400 this._rootNode.insertAsChild( ctrTrNode ); 400 this._rootNode.insertAsChild( ctrTrNode );
401 obj.setTransformNode( ctrTrNode ); 401 obj.setTransformNode( ctrTrNode );
402 } 402 }
403 403
404 ctrTrNode.meshes.forEach(function(thisMesh) { 404 ctrTrNode.meshes.forEach(function(thisMesh) {
405 g_meshMan.deleteMesh(thisMesh.mesh.name); 405 RDGE.globals.meshMan.deleteMesh(thisMesh.mesh.name);
406 }); 406 });
407 ctrTrNode.meshes = []; 407 ctrTrNode.meshes = [];
408 408
@@ -421,11 +421,11 @@ World.prototype.updateObject = function (obj) {
421 childTrNode = children[i-1].transformNode; 421 childTrNode = children[i-1].transformNode;
422 422
423 childTrNode.meshes.forEach(function(thisMesh) { 423 childTrNode.meshes.forEach(function(thisMesh) {
424 g_meshMan.deleteMesh(thisMesh.mesh.name); 424 RDGE.globals.meshMan.deleteMesh(thisMesh.mesh.name);
425 }); 425 });
426 childTrNode.meshes = []; 426 childTrNode.meshes = [];
427 } else { 427 } else {
428 childTrNode = createTransformNode("objNode_" + this._nodeCounter++); 428 childTrNode = RDGE.createTransformNode("objNode_" + this._nodeCounter++);
429 ctrTrNode.insertAsChild(childTrNode); 429 ctrTrNode.insertAsChild(childTrNode);
430 } 430 }
431 431
@@ -466,7 +466,7 @@ World.prototype.addObject = function( obj ) {
466 catch(e) { 466 catch(e) {
467 alert( "Exception in GLWorld.addObject " + e ); 467 alert( "Exception in GLWorld.addObject " + e );
468 } 468 }
469} 469};
470 470
471World.prototype.restartRenderLoop = function() { 471World.prototype.restartRenderLoop = function() {
472 //console.log( "restartRenderLoop" ); 472 //console.log( "restartRenderLoop" );
@@ -527,7 +527,7 @@ World.prototype.clearTree = function() {
527 if (this._useWebGL) { 527 if (this._useWebGL) {
528 var root = this._rootNode; 528 var root = this._rootNode;
529 root.children = new Array(); 529 root.children = new Array();
530 g_Engine.unregisterCanvas( this._canvas.rdgeid ) 530 RDGE.globals.engine.unregisterCanvas( this._canvas.rdgeid );
531 531
532 this.update( 0 ); 532 this.update( 0 );
533 this.draw(); 533 this.draw();
@@ -540,9 +540,10 @@ World.prototype.updateMaterials = function( obj, time ) {
540 var matArray = obj.getMaterialArray(); 540 var matArray = obj.getMaterialArray();
541 if (matArray) { 541 if (matArray) {
542 var n = matArray.length; 542 var n = matArray.length;
543 for (var i=0; i<n; i++) 543 for (var i=0; i<n; i++) {
544 matArray[i].update( time ); 544 matArray[i].update( time );
545 } 545 }
546 }
546 547
547 this.updateMaterials( obj.getNext(), time ); 548 this.updateMaterials( obj.getNext(), time );
548 this.updateMaterials( obj.getChild(), time ); 549 this.updateMaterials( obj.getChild(), time );
@@ -553,9 +554,8 @@ World.prototype.getNDCOrigin = function() {
553 var pt = MathUtils.transformPoint( [0,0,0], this.getCameraMatInverse() ); 554 var pt = MathUtils.transformPoint( [0,0,0], this.getCameraMatInverse() );
554 var projMat = Matrix.makePerspective( this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar()); 555 var projMat = Matrix.makePerspective( this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar());
555 var ndcPt = MathUtils.transformHomogeneousPoint( pt, projMat ); 556 var ndcPt = MathUtils.transformHomogeneousPoint( pt, projMat );
556 var ndcOrigin = MathUtils.applyHomogeneousCoordinate( ndcPt );
557 557
558 return ndcOrigin; 558 return MathUtils.applyHomogeneousCoordinate( ndcPt );
559}; 559};
560 560
561World.prototype.worldToScreen = function(v) { 561World.prototype.worldToScreen = function(v) {
@@ -570,9 +570,8 @@ World.prototype.worldToScreen = function(v) {
570 var x = v2[0], y = v2[1], z = v2[2]; 570 var x = v2[0], y = v2[1], z = v2[2];
571 571
572 var h = this.getGLContext().viewportHeight/2.0, w = this.getGLContext().viewportWidth/2.0; 572 var h = this.getGLContext().viewportHeight/2.0, w = this.getGLContext().viewportWidth/2.0;
573 var x2 = w*(1 + x), y2 = h*( 1 - y ), z2 = z; <