aboutsummaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-05-03 17:07:40 -0700
committerNivesh Rajbhandari2012-05-03 17:07:40 -0700
commitc14b8d9fd1acde98ffc427b0bbdba7d1442c39a4 (patch)
treed7744f071bf1b45578244e7355898025498f93fe /assets
parent3bbb69b59877b64d4b22b4106e833e1bb45775e2 (diff)
downloadninja-c14b8d9fd1acde98ffc427b0bbdba7d1442c39a4.tar.gz
Converting canvas runtime to use prototypes for geom obj, rectangle, oval and line.
Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'assets')
-rw-r--r--assets/canvas-runtime.js1336
1 files changed, 672 insertions, 664 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js
index 104c22cc..17f8cda8 100644
--- a/assets/canvas-runtime.js
+++ b/assets/canvas-runtime.js
@@ -305,16 +305,19 @@ NinjaCvsRt.GLRuntime = function ( canvas, jObj, assetPath )
305 { 305 {
306 case 1: 306 case 1:
307 obj = new NinjaCvsRt.RuntimeRectangle(); 307 obj = new NinjaCvsRt.RuntimeRectangle();
308 obj._materials = [];
308 obj.importJSON( jObj ); 309 obj.importJSON( jObj );
309 break; 310 break;
310 311
311 case 2: // circle 312 case 2: // circle
312 obj = new NinjaCvsRt.RuntimeOval(); 313 obj = new NinjaCvsRt.RuntimeOval();
314 obj._materials = [];
313 obj.importJSON( jObj ); 315 obj.importJSON( jObj );
314 break; 316 break;
315 317
316 case 3: // line 318 case 3: // line
317 obj = new NinjaCvsRt.RuntimeLine(); 319 obj = new NinjaCvsRt.RuntimeLine();
320 obj._materials = [];
318 obj.importJSON( jObj ); 321 obj.importJSON( jObj );
319 break; 322 break;
320 323
@@ -481,204 +484,205 @@ NinjaCvsRt.RuntimeGeomObj = function ()
481 484
482 // array of materials 485 // array of materials
483 this._materials = []; 486 this._materials = [];
487};
484 488
485 /////////////////////////////////////////////////////////////////////// 489//NinjaCvsRt.RuntimeGeomObj.prototype = Object.create(Object.prototype, {});
486 // Property accessors 490///////////////////////////////////////////////////////////////////////
487 /////////////////////////////////////////////////////////////////////// 491// Property accessors
488 492///////////////////////////////////////////////////////////////////////
489 this.geomType = function() { return this.GEOM_TYPE_UNDEFINED; };
490
491 this.setWorld = function(w) { this._world = w; };
492 this.getWorld = function() { return this._world; };
493 493
494 /////////////////////////////////////////////////////////////////////// 494NinjaCvsRt.RuntimeGeomObj.prototype.geomType = function() { return this.GEOM_TYPE_UNDEFINED; };
495 // Methods
496 ///////////////////////////////////////////////////////////////////////
497 this.addChild = function( child )
498 {
499 if (!this._children) this._children = [];
500 this._children.push( child );
501 };
502 495
503 this.importJSON = function() 496NinjaCvsRt.RuntimeGeomObj.prototype.setWorld = function(w) { this._world = w; };
504 { 497NinjaCvsRt.RuntimeGeomObj.prototype.getWorld = function() { return this._world; };
505 };
506 498
507 this.importMaterials = function(jObj)
508 {
509 if (!jObj || !jObj.materials) return;
510 499
511 var nMaterials = jObj.nMaterials; 500///////////////////////////////////////////////////////////////////////
512 var matArray = jObj.materials; 501// Methods
513 for (var i=0; i<nMaterials; i++) 502///////////////////////////////////////////////////////////////////////
514 { 503NinjaCvsRt.RuntimeGeomObj.prototype.addChild = function( child )
515 var mat; 504{
516 var matObj = matArray[i].material; 505 if (!this._children) this._children = [];
517 var matNodeName = matArray[i].materialNodeName; 506 this._children.push( child );
518 var shaderName = matObj.material; 507};
519 switch (shaderName)
520 {
521 case "flat": mat = new NinjaCvsRt.RuntimeFlatMaterial(); break;
522 case "radialGradient": mat = new NinjaCvsRt.RuntimeRadialGradientMaterial(); break;
523 case "linearGradient": mat = new NinjaCvsRt.RuntimeLinearGradientMaterial(); break;
524 case "bumpMetal": mat = new NinjaCvsRt.RuntimeBumpMetalMaterial(); break;
525 case "uber": mat = new NinjaCvsRt.RuntimeUberMaterial(); break;
526 case "plasma": mat = new NinjaCvsRt.RuntimePlasmaMaterial(); break;
527
528 case "deform":
529 case "water":
530 case "paris":
531 case "raiders":
532 case "tunnel":
533 case "reliefTunnel":
534 case "squareTunnel":
535 case "twist":
536 case "fly":
537 case "julia":
538 case "mandel":
539 case "star":
540 case "zinvert":
541 case "keleidoscope":
542 case "radialBlur":
543 case "pulse": mat = new NinjaCvsRt.RuntimePulseMaterial(); break;
544
545 default:
546 console.log( "material type: " + shaderName + " is not supported" );
547 break;
548 }
549 508
550 if (mat) 509NinjaCvsRt.RuntimeGeomObj.prototype.importJSON = function()
551 { 510{
552 mat.importJSON( matObj ); 511};
553 mat._materialNodeName = matNodeName;
554 this._materials.push( mat );
555 }
556 }
557 };
558 512
559 //////////////////////////////////////////////////////////////////// 513NinjaCvsRt.RuntimeGeomObj.prototype.importMaterials = function(jObj)
560 // vector function 514{
515 if (!jObj || !jObj.materials) return;
561 516
562 this.vecAdd = function( dimen, a, b ) 517 var nMaterials = jObj.nMaterials;
563 { 518 var matArray = jObj.materials;
564 var rtnVec; 519 for (var i=0; i<nMaterials; i++)
565 if ((a.length < dimen) || (b.length < dimen)) 520 {
521 var mat;
522 var matObj = matArray[i].material;
523 var matNodeName = matArray[i].materialNodeName;
524 var shaderName = matObj.material;
525 switch (shaderName)
566 { 526 {
567 throw new Error( "dimension error in vecAdd" ); 527 case "flat": mat = new NinjaCvsRt.RuntimeFlatMaterial(); break;
528 case "radialGradient": mat = new NinjaCvsRt.RuntimeRadialGradientMaterial(); break;
529 case "linearGradient": mat = new NinjaCvsRt.RuntimeLinearGradientMaterial(); break;
530 case "bumpMetal": mat = new NinjaCvsRt.RuntimeBumpMetalMaterial(); break;
531 case "uber": mat = new NinjaCvsRt.RuntimeUberMaterial(); break;
532 case "plasma": mat = new NinjaCvsRt.RuntimePlasmaMaterial(); break;
533
534 case "deform":
535 case "water":
536 case "paris":
537 case "raiders":
538 case "tunnel":
539 case "reliefTunnel":
540 case "squareTunnel":
541 case "twist":
542 case "fly":
543 case "julia":
544 case "mandel":
545 case "star":
546 case "zinvert":
547 case "keleidoscope":
548 case "radialBlur":
549 case "pulse": mat = new NinjaCvsRt.RuntimePulseMaterial(); break;
550
551 default:
552 console.log( "material type: " + shaderName + " is not supported" );
553 break;
568 } 554 }
569 555
570 rtnVec = []; 556 if (mat)
571 for (var i=0; i<dimen; i++) 557 {
572 rtnVec[i] = a[i] + b[i]; 558 mat.importJSON( matObj );
559 mat._materialNodeName = matNodeName;
560 this._materials.push( mat );
561 }
562 }
563};
573 564
574 return rtnVec; 565////////////////////////////////////////////////////////////////////
575 }; 566// vector function
567NinjaCvsRt.RuntimeGeomObj.prototype.vecAdd = function( dimen, a, b )
568{
569 var rtnVec;
570 if ((a.length < dimen) || (b.length < dimen))
571 {
572 throw new Error( "dimension error in vecAdd" );
573 }
576 574
575 rtnVec = [];
576 for (var i=0; i<dimen; i++)
577 rtnVec[i] = a[i] + b[i];
577 578
578 this.vecSubtract = function( dimen, a, b ) 579 return rtnVec;
579 { 580};
580 var rtnVec;
581 if ((a.length < dimen) || (b.length < dimen))
582 {
583 throw new Error( "dimension error in vecSubtract" );
584 }
585 581
586 rtnVec = [];
587 for (var i=0; i<dimen; i++)
588 rtnVec[i] = a[i] - b[i];
589 582
590 return rtnVec; 583NinjaCvsRt.RuntimeGeomObj.prototype.vecSubtract = function( dimen, a, b )
591 }; 584{
585 var rtnVec;
586 if ((a.length < dimen) || (b.length < dimen))
587 {
588 throw new Error( "dimension error in vecSubtract" );
589 }
592 590
593 this.vecDot = function( dimen, v0, v1 ) 591 rtnVec = [];
594 { 592 for (var i=0; i<dimen; i++)
595 if ((v0.length < dimen) || (v1.length < dimen)) 593 rtnVec[i] = a[i] - b[i];
596 {
597 throw new Error( "dimension error in vecDot" );
598 }
599 594
600 var sum = 0.0; 595 return rtnVec;
601 for (var i=0; i<dimen; i++) 596};<