aboutsummaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authorhwc4872012-03-20 16:33:11 -0700
committerhwc4872012-03-20 16:33:11 -0700
commit6d0b1c5d8fe71244f93c2f994e1097b454df2766 (patch)
tree4d3a104ff3f34e97413c737f9012ed2d6ce724c4 /assets
parent98a02c1ac6f189aba93d7cce64ba5bdbc0617f6c (diff)
downloadninja-6d0b1c5d8fe71244f93c2f994e1097b454df2766.tar.gz
Runtime canvas & WebGL fixes.
Diffstat (limited to 'assets')
-rw-r--r--assets/canvas-runtime.js64
1 files changed, 51 insertions, 13 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js
index adff0e8c..5ea2a85f 100644
--- a/assets/canvas-runtime.js
+++ b/assets/canvas-runtime.js
@@ -505,6 +505,8 @@ function RuntimeGeomObj()
505 505
506 this.importMaterials = function(jObj) 506 this.importMaterials = function(jObj)
507 { 507 {
508 if (!jObj || !jObj.materials) return;
509
508 var nMaterials = jObj.nMaterials; 510 var nMaterials = jObj.nMaterials;
509 var matArray = jObj.materials; 511 var matArray = jObj.materials;
510 for (var i=0; i<nMaterials; i++) 512 for (var i=0; i<nMaterials; i++)
@@ -645,6 +647,37 @@ function RuntimeGeomObj()
645 647
646 return [x, y, z]; 648 return [x, y, z];
647 } 649 }
650
651 this.MatrixIdentity = function(dimen)
652 {
653 var mat = [];
654
655 for (var i = 0; i<dimen*dimen; i++) {
656 mat.push(0);
657 }
658
659 var index = 0;
660 for (var j = 0; j<dimen; j++) {
661 mat[index] = 1.0;
662 index += dimen + 1;
663 }
664
665 return mat;
666 };
667
668
669 this.MatrixRotationZ = function( angle )
670 {
671 var mat = this.MatrixIdentity(4);
672 //glmat4.rotateZ(mat, angle);
673 var sn = Math.sin(angle),
674 cs = Math.cos(angle);
675 mat[0] = cs; mat[4] = -sn;
676 mat[1] = sn; mat[5] = cs;
677
678 return mat;
679 };
680
648} 681}
649 682
650/////////////////////////////////////////////////////////////////////// 683///////////////////////////////////////////////////////////////////////
@@ -844,12 +877,17 @@ function RuntimeOval()
844 // translate 877 // translate
845 var xCtr = 0.5*world.getViewportWidth() + this._xOffset, 878 var xCtr = 0.5*world.getViewportWidth() + this._xOffset,
846 yCtr = 0.5*world.getViewportHeight() + this._yOffset; 879 yCtr = 0.5*world.getViewportHeight() + this._yOffset;
880 var mat = this.MatrixIdentity( 4 );
881 mat[0] = xScale; mat[12] = xCtr;
882 mat[5] = yScale; mat[13] = yCtr;
883 /*
847 var mat = [ 884 var mat = [
848 [ xScale, 0.0, 0.0, xCtr], 885 [ xScale, 0.0, 0.0, xCtr],
849 [ 0.0, yScale, 0.0, yCtr], 886 [ 0.0, yScale, 0.0, yCtr],
850 [ 0.0, 0.0, 1.0, 0.0], 887 [ 0.0, 0.0, 1.0, 0.0],
851 [ 0.0, 0.0, 0.0, 1.0] 888 [ 0.0, 0.0, 0.0, 1.0]
852 ]; 889 ];
890 */
853 891
854 // get a bezier representation of the circle 892 // get a bezier representation of the circle
855 var bezPts = this.circularArcToBezier( [0,0,0], [1,0,0], 2.0*Math.PI ); 893 var bezPts = this.circularArcToBezier( [0,0,0], [1,0,0], 2.0*Math.PI );
@@ -1005,7 +1043,7 @@ function RuntimeOval()
1005 var d = rad*cs + h; 1043 var d = rad*cs + h;
1006 1044
1007 var rtnPts = [ this.vecAdd(dimen, pt, ctr) ]; 1045 var rtnPts = [ this.vecAdd(dimen, pt, ctr) ];
1008 var rotMat = Matrix.RotationZ( dAngle ); 1046 var rotMat = this.MatrixRotationZ( dAngle );
1009 for ( var i=0; i<nSegs; i++) 1047 for ( var i=0; i<nSegs; i++)
1010 { 1048 {
1011 // get the next end point 1049 // get the next end point
@@ -1207,14 +1245,14 @@ function RuntimeRadialGradientMaterial()
1207 1245
1208 this.import = function( jObj ) 1246 this.import = function( jObj )
1209 { 1247 {
1210 var color1 = jObj.color1, 1248 this._color1 = jObj.color1,
1211 color2 = jObj.color2, 1249 this._color2 = jObj.color2,
1212 color3 = jObj.color3, 1250 this._color3 = jObj.color3,
1213 color4 = jObj.color4, 1251 this._color4 = jObj.color4,
1214 colorStop1 = jObj.colorStop1, 1252 this._colorStop1 = jObj.colorStop1,
1215 colorStop2 = jObj.colorStop2, 1253 this._colorStop2 = jObj.colorStop2,
1216 colorStop3 = jObj.colorStop3, 1254 this._colorStop3 = jObj.colorStop3,
1217 colorStop4 = jObj.colorStop4; 1255 this._colorStop4 = jObj.colorStop4;
1218 1256
1219 if (this._angle !== undefined) 1257 if (this._angle !== undefined)
1220 this._angle = jObj.angle; 1258 this._angle = jObj.angle;
@@ -1394,10 +1432,10 @@ function RuntimeUberMaterial()
1394 { 1432 {
1395 if (jObj.materialProps) 1433 if (jObj.materialProps)
1396 { 1434 {
1397 var ambientColor = jObj.materialProps.ambientColor; this.setProperty( "ambientColor", ambientColor ); 1435 this._ambientColor = jObj.materialProps.ambientColor;
1398 var diffuseColor = jObj.materialProps.diffuseColor; this.setProperty( "diffuseColor", diffuseColor ); 1436 this._diffuseColor = jObj.materialProps.diffuseColor;
1399 var specularColor = jObj.materialProps.specularColor; this.setProperty( "specularColor", specularColor ); 1437 this._specularColor = jObj.materialProps.specularColor;
1400 var specularPower = jObj.materialProps.specularPower; this.setProperty( "specularPower", specularPower ); 1438 this._specularPower = jObj.materialProps.specularPower;
1401 } 1439 }
1402 1440
1403 var lightArray = jObj.lights; 1441 var lightArray = jObj.lights;