scenejs_on_rails 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -5
  3. data/app/controllers/scenejs_controller.rb +53 -0
  4. data/app/views/scenejs/get_scenejs_data.html.erb +3 -0
  5. data/lib/scenejs_on_rails.rb +1 -1
  6. data/lib/scenejs_on_rails/rails.rb +5 -0
  7. data/lib/scenejs_on_rails/version.rb +1 -1
  8. data/vendor/assets/javascripts/scenejs.js +17307 -0
  9. data/vendor/assets/javascripts/scenejs_extras/gui.js +478 -0
  10. data/vendor/assets/javascripts/scenejs_extras/gui/README.md +4 -0
  11. data/vendor/assets/javascripts/scenejs_extras/gui/dat.gui.min.js +94 -0
  12. data/vendor/assets/javascripts/scenejs_extras/gui/gui.js +385 -0
  13. data/vendor/assets/javascripts/scenejs_lib/cityBuilder.js +457 -0
  14. data/vendor/assets/javascripts/scenejs_lib/dat.gui.min.js +94 -0
  15. data/vendor/assets/javascripts/scenejs_lib/gl-matrix-min.js +28 -0
  16. data/vendor/assets/javascripts/scenejs_lib/gl-matrix.js +4078 -0
  17. data/vendor/assets/javascripts/scenejs_lib/require.js +36 -0
  18. data/vendor/assets/javascripts/scenejs_lib/requireConfig.js +18 -0
  19. data/vendor/assets/javascripts/scenejs_lib/requireWrapperEnd.js +1 -0
  20. data/vendor/assets/javascripts/scenejs_lib/requireWrapperStart.js +2 -0
  21. data/vendor/assets/javascripts/scenejs_lib/stats.min.js +6 -0
  22. data/vendor/assets/javascripts/scenejs_lib/sylvester.js +1 -0
  23. data/vendor/assets/javascripts/scenejs_lib/webgl-debug-utils.js +839 -0
  24. data/vendor/assets/javascripts/scenejs_plugins/geometry/boundary.js +59 -0
  25. data/vendor/assets/javascripts/scenejs_plugins/geometry/box.js +72 -0
  26. data/vendor/assets/javascripts/scenejs_plugins/geometry/plane.js +126 -0
  27. data/vendor/assets/javascripts/scenejs_plugins/geometry/quad.js +37 -0
  28. data/vendor/assets/javascripts/scenejs_plugins/geometry/skybox.js +86 -0
  29. data/vendor/assets/javascripts/scenejs_plugins/geometry/sphere.js +82 -0
  30. data/vendor/assets/javascripts/scenejs_plugins/geometry/teapot.js +5853 -0
  31. data/vendor/assets/javascripts/scenejs_plugins/geometry/torus.js +139 -0
  32. data/vendor/assets/javascripts/scenejs_plugins/geometry/vectorText.js +1499 -0
  33. data/vendor/assets/javascripts/scenejs_plugins/geometry/wobblyBox.js +44 -0
  34. data/vendor/assets/javascripts/scenejs_plugins/lib/canvas2image.js +198 -0
  35. data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullEngine.js +810 -0
  36. data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullSystem.js +185 -0
  37. data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullSystemPool.js +174 -0
  38. data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullWorker.js +142 -0
  39. data/vendor/assets/javascripts/scenejs_plugins/lib/gl-matrix-min.js +28 -0
  40. data/vendor/assets/javascripts/scenejs_plugins/lib/jquery-1.8.3.min.js +2 -0
  41. data/vendor/assets/javascripts/scenejs_plugins/lib/k3d.js +1029 -0
  42. data/vendor/assets/javascripts/scenejs_plugins/lib/physics/jiglib.all.min.js +3 -0
  43. data/vendor/assets/javascripts/scenejs_plugins/lib/physics/physics.js +223 -0
  44. data/vendor/assets/javascripts/scenejs_plugins/lib/physics/worker.js +330 -0
  45. data/vendor/assets/javascripts/scenejs_plugins/node/alpha/orbitTracking.js +295 -0
  46. data/vendor/assets/javascripts/scenejs_plugins/node/alpha/orbitTrackingTarget.js +43 -0
  47. data/vendor/assets/javascripts/scenejs_plugins/node/backgrounds/gradient.js +148 -0
  48. data/vendor/assets/javascripts/scenejs_plugins/node/cameras/orbit.js +172 -0
  49. data/vendor/assets/javascripts/scenejs_plugins/node/cameras/pickFlyOrbit.js +409 -0
  50. data/vendor/assets/javascripts/scenejs_plugins/node/canvas/capture.js +107 -0
  51. data/vendor/assets/javascripts/scenejs_plugins/node/demos/color.js +30 -0
  52. data/vendor/assets/javascripts/scenejs_plugins/node/demos/redTeapot.js +52 -0
  53. data/vendor/assets/javascripts/scenejs_plugins/node/demos/spinningTeapot.js +43 -0
  54. data/vendor/assets/javascripts/scenejs_plugins/node/effects/crt.js +36 -0
  55. data/vendor/assets/javascripts/scenejs_plugins/node/effects/fog.js +159 -0
  56. data/vendor/assets/javascripts/scenejs_plugins/node/effects/snowyPeaks.js +50 -0
  57. data/vendor/assets/javascripts/scenejs_plugins/node/effects/wobble.js +42 -0
  58. data/vendor/assets/javascripts/scenejs_plugins/node/effects/xray.js +126 -0
  59. data/vendor/assets/javascripts/scenejs_plugins/node/frustum/body.js +112 -0
  60. data/vendor/assets/javascripts/scenejs_plugins/node/frustum/cull.js +42 -0
  61. data/vendor/assets/javascripts/scenejs_plugins/node/frustum/lod.js +125 -0
  62. data/vendor/assets/javascripts/scenejs_plugins/node/heightmaps/custom.js +185 -0
  63. data/vendor/assets/javascripts/scenejs_plugins/node/import/3ds.js +91 -0
  64. data/vendor/assets/javascripts/scenejs_plugins/node/import/md2.js +139 -0
  65. data/vendor/assets/javascripts/scenejs_plugins/node/import/obj.js +100 -0
  66. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building.js +352 -0
  67. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/HighRiseGlass.jpg +0 -0
  68. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/HighRiseGlassSpecular.jpg +0 -0
  69. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/highrise-windows.jpg +0 -0
  70. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/pixelcity_windows7.jpg +0 -0
  71. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/city.js +26 -0
  72. data/vendor/assets/javascripts/scenejs_plugins/node/objects/plants/ghostTree.js +387 -0
  73. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth.js +168 -0
  74. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth-lights.gif +0 -0
  75. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth-specular.gif +0 -0
  76. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth-specular.jpg +0 -0
  77. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth.jpg +0 -0
  78. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earthbump.jpg +0 -0
  79. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earthclouds.jpg +0 -0
  80. data/vendor/assets/javascripts/scenejs_plugins/node/objects/toys/drinkingBird.js +632 -0
  81. data/vendor/assets/javascripts/scenejs_plugins/node/objects/vehicles/tank.js +77670 -0
  82. data/vendor/assets/javascripts/scenejs_plugins/node/objects/vehicles/tank.js~ +77636 -0
  83. data/vendor/assets/javascripts/scenejs_plugins/node/physics/body.js +85 -0
  84. data/vendor/assets/javascripts/scenejs_plugins/node/physics/box.js +30 -0
  85. data/vendor/assets/javascripts/scenejs_plugins/node/physics/material.js +35 -0
  86. data/vendor/assets/javascripts/scenejs_plugins/node/physics/plane.js +47 -0
  87. data/vendor/assets/javascripts/scenejs_plugins/node/physics/sphere.js +32 -0
  88. data/vendor/assets/javascripts/scenejs_plugins/node/physics/system.js +44 -0
  89. data/vendor/assets/javascripts/scenejs_plugins/node/physics/teapot.js +29 -0
  90. data/vendor/assets/javascripts/scenejs_plugins/node/prims/boundary.js +73 -0
  91. data/vendor/assets/javascripts/scenejs_plugins/node/prims/box.js +87 -0
  92. data/vendor/assets/javascripts/scenejs_plugins/node/prims/cylinder.js +186 -0
  93. data/vendor/assets/javascripts/scenejs_plugins/node/prims/grid.js +47 -0
  94. data/vendor/assets/javascripts/scenejs_plugins/node/prims/plane.js +137 -0
  95. data/vendor/assets/javascripts/scenejs_plugins/node/prims/quad.js +43 -0
  96. data/vendor/assets/javascripts/scenejs_plugins/node/prims/sphere.js +107 -0
  97. data/vendor/assets/javascripts/scenejs_plugins/node/prims/teapot.js +5846 -0
  98. data/vendor/assets/javascripts/scenejs_plugins/node/prims/torus.js +149 -0
  99. data/vendor/assets/javascripts/scenejs_plugins/node/prims/vectorText.js +1508 -0
  100. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/clouds.js +19 -0
  101. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/cloudySea.js +19 -0
  102. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/custom.js +150 -0
  103. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/grimmNight.js +19 -0
  104. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/interstellarClouds.js +19 -0
  105. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/miramarClouds.js +19 -0
  106. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/stormyDays.js +19 -0
  107. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/clouds.jpg +0 -0
  108. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/cloudySea.jpg +0 -0
  109. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/grimmNight.jpg +0 -0
  110. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/interstellarClouds.jpg +0 -0
  111. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/miramarClouds.jpg +0 -0
  112. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/stormyDays.jpg +0 -0
  113. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/violentDays.jpg +0 -0
  114. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/violentDays.js +19 -0
  115. data/vendor/assets/javascripts/scenejs_plugins/texture/image.js +67 -0
  116. data/vendor/assets/javascripts/scenejs_plugins/texture/video.js +105 -0
  117. metadata +113 -1
@@ -0,0 +1,3 @@
1
+ jigLib={};jigLib.extend=function(a,b){for(proto in b.prototype){a.prototype[proto]=b.prototype[proto];}a.prototype.Super=b;};(function(a){a.JConfig={solverType:"ACCUMULATED",boxCollisionsType:"EDGEBASE",rotationType:"DEGREES",aabbDetection:true,doShockStep:false,allowedPenetration:0.01,collToll:0.05,velThreshold:0.5,angVelThreshold:5,posThreshold:0.2,orientThreshold:0.2,deactivationTime:1,numPenetrationRelaxationTimesteps:50,numCollisionIterations:4,numContactIterations:8,numConstraintIterations:15};})(jigLib);(function(a){if(typeof Float32Array!="undefined"){glMatrixArrayType=Float32Array;}else{if(typeof WebGLFloatArray!="undefined"){glMatrixArrayType=WebGLFloatArray;}else{glMatrixArrayType=Array;}}var d={};d.create=function(f){var e=new glMatrixArrayType(3);if(f){e[0]=f[0];e[1]=f[1];e[2]=f[2];}return e;};d.set=function(f,e){e[0]=f[0];e[1]=f[1];e[2]=f[2];return e;};d.add=function(f,g,e){if(!e||f==e){f[0]+=g[0];f[1]+=g[1];f[2]+=g[2];return f;}e[0]=f[0]+g[0];e[1]=f[1]+g[1];e[2]=f[2]+g[2];return e;};d.subtract=function(f,g,e){if(!e||f==e){f[0]-=g[0];f[1]-=g[1];f[2]-=g[2];return f;}e[0]=f[0]-g[0];e[1]=f[1]-g[1];e[2]=f[2]-g[2];return e;};d.negate=function(f,e){if(!e){e=f;}e[0]=-f[0];e[1]=-f[1];e[2]=-f[2];return e;};d.scale=function(f,g,e){if(!e||f==e){f[0]*=g;f[1]*=g;f[2]*=g;return f;}e[0]=f[0]*g;e[1]=f[1]*g;e[2]=f[2]*g;return e;};d.normalize=function(h,g){if(!g){g=h;}var f=h[0],j=h[1],i=h[2];var e=Math.sqrt(f*f+j*j+i*i);if(!e){g[0]=0;g[1]=0;g[2]=0;return g;}else{if(e==1){g[0]=f;g[1]=j;g[2]=i;return g;}}e=1/e;g[0]=f*e;g[1]=j*e;g[2]=i*e;return g;};d.cross=function(f,h,m){if(!m){m=f;}var l=f[0],j=f[1],i=f[2];var e=h[0],k=h[1],g=h[2];m[0]=j*g-i*k;m[1]=i*e-l*g;m[2]=l*k-j*e;return m;};d.length=function(f){var e=f[0],h=f[1],g=f[2];return Math.sqrt(e*e+h*h+g*g);};d.dot=function(e,f){return e[0]*f[0]+e[1]*f[1]+e[2]*f[2];};d.direction=function(h,i,g){if(!g){g=h;}var f=h[0]-i[0];var k=h[1]-i[1];var j=h[2]-i[2];var e=Math.sqrt(f*f+k*k+j*j);if(!e){g[0]=0;g[1]=0;g[2]=0;return g;}e=1/e;g[0]=f*e;g[1]=k*e;g[2]=j*e;return g;};d.str=function(e){return"["+e[0]+", "+e[1]+", "+e[2]+"]";};var c={};c.create=function(f){var e=new glMatrixArrayType(9);if(f){e[0]=f[0];e[1]=f[1];e[2]=f[2];e[3]=f[3];e[4]=f[4];e[5]=f[5];e[6]=f[6];e[7]=f[7];e[8]=f[8];e[9]=f[9];}return e;};c.set=function(f,e){e[0]=f[0];e[1]=f[1];e[2]=f[2];e[3]=f[3];e[4]=f[4];e[5]=f[5];e[6]=f[6];e[7]=f[7];e[8]=f[8];return e;};c.identity=function(e){e[0]=1;e[1]=0;e[2]=0;e[3]=0;e[4]=1;e[5]=0;e[6]=0;e[7]=0;e[8]=1;return e;};c.toMat4=function(f,e){if(!e){e=b.create();}e[0]=f[0];e[1]=f[1];e[2]=f[2];e[3]=0;e[4]=f[3];e[5]=f[4];e[6]=f[5];e[7]=0;e[8]=f[6];e[9]=f[7];e[10]=f[8];e[11]=0;e[12]=0;e[13]=0;e[14]=0;e[15]=1;return e;};c.str=function(e){return"["+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+", "+e[4]+", "+e[5]+", "+e[6]+", "+e[7]+", "+e[8]+"]";};var b={};b.create=function(f){var e=new glMatrixArrayType(16);if(f){e[0]=f[0];e[1]=f[1];e[2]=f[2];e[3]=f[3];e[4]=f[4];e[5]=f[5];e[6]=f[6];e[7]=f[7];e[8]=f[8];e[9]=f[9];e[10]=f[10];e[11]=f[11];e[12]=f[12];e[13]=f[13];e[14]=f[14];e[15]=f[15];}return e;};b.set=function(f,e){e[0]=f[0];e[1]=f[1];e[2]=f[2];e[3]=f[3];e[4]=f[4];e[5]=f[5];e[6]=f[6];e[7]=f[7];e[8]=f[8];e[9]=f[9];e[10]=f[10];e[11]=f[11];e[12]=f[12];e[13]=f[13];e[14]=f[14];e[15]=f[15];return e;};b.identity=function(e){e[0]=1;e[1]=0;e[2]=0;e[3]=0;e[4]=0;e[5]=1;e[6]=0;e[7]=0;e[8]=0;e[9]=0;e[10]=1;e[11]=0;e[12]=0;e[13]=0;e[14]=0;e[15]=1;return e;};b.transpose=function(h,g){if(!g||h==g){var l=h[1],j=h[2],i=h[3];var e=h[6],k=h[7];var f=h[11];h[1]=h[4];h[2]=h[8];h[3]=h[12];h[4]=l;h[6]=h[9];h[7]=h[13];h[8]=j;h[9]=e;h[11]=h[14];h[12]=i;h[13]=k;h[14]=f;return h;}g[0]=h[0];g[1]=h[4];g[2]=h[8];g[3]=h[12];g[4]=h[1];g[5]=h[5];g[6]=h[9];g[7]=h[13];g[8]=h[2];g[9]=h[6];g[10]=h[10];g[11]=h[14];g[12]=h[3];g[13]=h[7];g[14]=h[11];g[15]=h[15];return g;};b.determinant=function(s){var l=s[0],k=s[1],i=s[2],g=s[3];var u=s[4],t=s[5],r=s[6],q=s[7];var p=s[8],o=s[9],n=s[10],m=s[11];var j=s[12],h=s[13],f=s[14],e=s[15];return j*o*r*g-p*h*r*g-j*t*n*g+u*h*n*g+p*t*f*g-u*o*f*g-j*o*i*q+p*h*i*q+j*k*n*q-l*h*n*q-p*k*f*q+l*o*f*q+j*t*i*m-u*h*i*m-j*k*r*m+l*h*r*m+u*k*f*m-l*t*f*m-p*t*i*e+u*o*i*e+p*k*r*e-l*o*r*e-u*k*n*e+l*t*n*e;};b.inverse=function(z,o){if(!o){o=z;}var G=z[0],E=z[1],D=z[2],B=z[3];var h=z[4],g=z[5],f=z[6],e=z[7];var w=z[8],v=z[9],u=z[10],t=z[11];var I=z[12],H=z[13],F=z[14],C=z[15];var s=G*g-E*h;var r=G*f-D*h;var q=G*e-B*h;var p=E*f-D*g;var n=E*e-B*g;var m=D*e-B*f;var l=w*H-v*I;var k=w*F-u*I;var j=w*C-t*I;var i=v*F-u*H;var A=v*C-t*H;var y=u*C-t*F;var x=1/(s*y-r*A+q*i+p*j-n*k+m*l);o[0]=(g*y-f*A+e*i)*x;o[1]=(-E*y+D*A-B*i)*x;o[2]=(H*m-F*n+C*p)*x;o[3]=(-v*m+u*n-t*p)*x;o[4]=(-h*y+f*j-e*k)*x;o[5]=(G*y-D*j+B*k)*x;o[6]=(-I*m+F*q-C*r)*x;o[7]=(w*m-u*q+t*r)*x;o[8]=(h*A-g*j+e*l)*x;o[9]=(-G*A+E*j-B*l)*x;o[10]=(I*n-H*q+C*s)*x;o[11]=(-w*n+v*q-t*s)*x;o[12]=(-h*i+g*k-f*l)*x;o[13]=(G*i-E*k+D*l)*x;o[14]=(-I*p+H*r-F*s)*x;o[15]=(w*p-v*r+u*s)*x;return o;};b.toRotationMat=function(f,e){if(!e){e=b.create();}e[0]=f[0];e[1]=f[1];e[2]=f[2];e[3]=f[3];e[4]=f[4];e[5]=f[5];e[6]=f[6];e[7]=f[7];e[8]=f[8];e[9]=f[9];e[10]=f[10];e[11]=f[11];e[12]=0;e[13]=0;e[14]=0;e[15]=1;return e;};b.toMat3=function(f,e){if(!e){e=c.create();}e[0]=f[0];e[1]=f[1];e[2]=f[2];e[3]=f[4];e[4]=f[5];e[5]=f[6];e[6]=f[8];e[7]=f[9];e[8]=f[10];return e;};b.toInverseMat3=function(r,p){var i=r[0],h=r[1],g=r[2];var t=r[4],s=r[5],q=r[6];var m=r[8],l=r[9],k=r[10];var j=k*s-q*l;var f=-k*t+q*m;var o=l*t-s*m;var n=i*j+h*f+g*o;if(!n){return null;}var e=1/n;if(!p){p=c.create();}p[0]=j*e;p[1]=(-k*h+g*l)*e;p[2]=(q*h-g*s)*e;p[3]=f*e;p[4]=(k*i-g*m)*e;p[5]=(-q*i+g*t)*e;p[6]=o*e;p[7]=(-l*i+h*m)*e;p[8]=(s*i-h*t)*e;return p;};b.multiply=function(D,m,n){if(!n){n=D;}var K=D[0],J=D[1],H=D[2],F=D[3];var l=D[4],k=D[5],j=D[6],i=D[7];var z=D[8],y=D[9],x=D[10],w=D[11];var M=D[12],L=D[13],I=D[14],G=D[15];var u=m[0],s=m[1],q=m[2],o=m[3];var E=m[4],C=m[5],B=m[6],A=m[7];var h=m[8],g=m[9],f=m[10],e=m[11];var v=m[12],t=m[13],r=m[14],p=m[15];n[0]=u*K+s*l+q*z+o*M;n[1]=u*J+s*k+q*y+o*L;n[2]=u*H+s*j+q*x+o*I;n[3]=u*F+s*i+q*w+o*G;n[4]=E*K+C*l+B*z+A*M;n[5]=E*J+C*k+B*y+A*L;n[6]=E*H+C*j+B*x+A*I;n[7]=E*F+C*i+B*w+A*G;n[8]=h*K+g*l+f*z+e*M;n[9]=h*J+g*k+f*y+e*L;n[10]=h*H+g*j+f*x+e*I;n[11]=h*F+g*i+f*w+e*G;n[12]=v*K+t*l+r*z+p*M;n[13]=v*J+t*k+r*y+p*L;n[14]=v*H+t*j+r*x+p*I;n[15]=v*F+t*i+r*w+p*G;return n;};b.multiplyVec3=function(h,g,f){if(!f){f=g;}var e=g[0],j=g[1],i=g[2];f[0]=h[0]*e+h[4]*j+h[8]*i+h[12];f[1]=h[1]*e+h[5]*j+h[9]*i+h[13];f[2]=h[2]*e+h[6]*j+h[10]*i+h[14];return f;};b.multiplyVec4=function(i,h,g){if(!g){g=h;}var e=h[0],k=h[1],j=h[2],f=h[3];g[0]=i[0]*e+i[4]*k+i[8]*j+i[12]*f;g[1]=i[1]*e+i[5]*k+i[9]*j+i[13]*f;g[2]=i[2]*e+i[6]*k+i[10]*j+i[14]*f;g[4]=i[4]*e+i[7]*k+i[11]*j+i[15]*f;return g;};b.translate=function(r,m,k){var l=m[0],j=m[1],i=m[2];if(!k||r==k){r[12]=r[0]*l+r[4]*j+r[8]*i+r[12];r[13]=r[1]*l+r[5]*j+r[9]*i+r[13];r[14]=r[2]*l+r[6]*j+r[10]*i+r[14];r[15]=r[3]*l+r[7]*j+r[11]*i+r[15];return r;}var v=r[0],u=r[1],t=r[2],s=r[3];var h=r[4],g=r[5],f=r[6],e=r[7];var q=r[8],p=r[9],o=r[10],n=r[11];k[0]=v;k[1]=u;k[2]=t;k[3]=s;k[4]=h;k[5]=g;k[6]=f;k[7]=e;k[8]=q;k[9]=p;k[10]=o;k[11]=n;k[12]=v*l+h*j+q*i+r[12];k[13]=u*l+g*j+p*i+r[13];k[14]=t*l+f*j+o*i+r[14];k[15]=s*l+e*j+n*i+r[15];return k;};b.scale=function(h,g,f){var e=g[0],j=g[1],i=g[2];if(!f||h==f){h[0]*=e;h[1]*=e;h[2]*=e;h[3]*=e;h[4]*=j;h[5]*=j;h[6]*=j;h[7]*=j;h[8]*=i;h[9]*=i;h[10]*=i;h[11]*=i;return h;}f[0]=h[0]*e;f[1]=h[1]*e;f[2]=h[2]*e;f[3]=h[3]*e;f[4]=h[4]*j;f[5]=h[5]*j;f[6]=h[6]*j;f[7]=h[7]*j;f[8]=h[8]*i;f[9]=h[9]*i;f[10]=h[10]*i;f[11]=h[11]*i;f[12]=h[12];f[13]=h[13];f[14]=h[14];f[15]=h[15];return f;};b.rotate=function(I,G,e,o){var p=e[0],n=e[1],m=e[2];var E=Math.sqrt(p*p+n*n+m*m);if(!E){return null;}if(E!=1){E=1/E;p*=E;n*=E;m*=E;}var w=Math.sin(G);var K=Math.cos(G);var v=1-K;var O=I[0],N=I[1],M=I[2],L=I[3];var l=I[4],k=I[5],j=I[6],i=I[7];var D=I[8],C=I[9],B=I[10],A=I[11];var u=p*p*v+K,r=n*p*v+m*w,q=m*p*v-n*w;var J=p*n*v-m*w,H=n*n*v+K,F=m*n*v+p*w;var h=p*m*v+n*w,g=n*m*v-p*w,f=m*m*v+K;if(!o){o=I;}else{if(I!=o){o[12]=I[12];o[13]=I[13];o[14]=I[14];o[15]=I[15];}}o[0]=O*u+l*r+D*q;o[1]=N*u+k*r+C*q;o[2]=M*u+j*r+B*q;o[3]=L*u+i*r+A*q;o[4]=O*J+l*H+D*F;o[5]=N*J+k*H+C*F;o[6]=M*J+j*H+B*F;o[7]=L*J+i*H+A*F;o[8]=O*h+l*g+D*f;o[9]=N*h+k*g+C*f;o[10]=M*h+j*g+B*f;o[11]=L*h+i*g+A*f;return o;};b.rotateX=function(n,e,l){var q=Math.sin(e);var j=Math.cos(e);var p=n[4],o=n[5],m=n[6],k=n[7];var i=n[8],h=n[9],g=n[10],f=n[11];if(!l){l=n;}else{if(n!=l){l[0]=n[0];l[1]=n[1];l[2]=n[2];l[3]=n[3];l[12]=n[12];l[13]=n[13];l[14]=n[14];l[15]=n[15];}}l[4]=p*j+i*q;l[5]=o*j+h*q;l[6]=m*j+g*q;l[7]=k*j+f*q;l[8]=p*-q+i*j;l[9]=o*-q+h*j;l[10]=m*-q+g*j;l[11]=k*-q+f*j;return l;};b.rotateY=function(p,h,o){var q=Math.sin(h);var n=Math.cos(h);var i=p[0],g=p[1],f=p[2],e=p[3];var m=p[8],l=p[9],k=p[10],j=p[11];if(!o){o=p;}else{if(p!=o){o[4]=p[4];o[5]=p[5];o[6]=p[6];o[7]=p[7];o[12]=p[12];o[13]=p[13];o[14]=p[14];o[15]=p[15];}}o[0]=i*n+m*-q;o[1]=g*n+l*-q;o[2]=f*n+k*-q;o[3]=e*n+j*-q;o[8]=i*q+m*n;o[9]=g*q+l*n;o[10]=f*q+k*n;o[11]=e*q+j*n;return o;};b.rotateZ=function(o,h,l){var q=Math.sin(h);var j=Math.cos(h);var i=o[0],g=o[1],f=o[2],e=o[3];var p=o[4],n=o[5],m=o[6],k=o[7];if(!l){l=o;}else{if(o!=l){l[8]=o[8];l[9]=o[9];l[10]=o[10];l[11]=o[11];l[12]=o[12];l[13]=o[13];l[14]=o[14];l[15]=o[15];}}l[0]=i*j+p*q;l[1]=g*j+n*q;l[2]=f*j+m*q;l[3]=e*j+k*q;l[4]=i*-q+p*j;l[5]=g*-q+n*j;l[6]=f*-q+m*j;l[7]=e*-q+k*j;return l;};b.frustum=function(f,n,e,l,i,h,m){if(!m){m=b.create();}var j=(n-f);var g=(l-e);var k=(h-i);m[0]=(i*2)/j;m[1]=0;m[2]=0;m[3]=0;m[4]=0;m[5]=(i*2)/g;m[6]=0;m[7]=0;m[8]=(n+f)/j;m[9]=(l+e)/g;m[10]=-(h+i)/k;m[11]=-1;m[12]=0;m[13]=0;m[14]=-(h*i*2)/k;m[15]=0;return m;};b.perspective=function(g,f,j,e,h){var k=j*Math.tan(g*Math.PI/360);var i=k*f;return b.frustum(-i,i,-k,k,j,e,h);};b.ortho=function(f,n,e,l,i,h,m){if(!m){m=b.create();}var j=(n-f);var g=(l-e);var k=(h-i);m[0]=2/j;m[1]=0;m[2]=0;m[3]=0;m[4]=0;m[5]=2/g;m[6]=0;m[7]=0;m[8]=0;m[9]=0;m[10]=-2/k;m[11]=0;m[12]=-(f+n)/j;m[13]=-(l+e)/g;m[14]=-(h+i)/k;m[15]=1;return m;};b.lookAt=function(z,A,l,k){if(!k){k=b.create();}var x=z[0],v=z[1],s=z[2],j=l[0],i=l[1],h=l[2],r=A[0],q=A[1],p=A[2];if(x==r&&v==q&&s==p){return b.identity(k);}var o,n,m,y,w,u,g,f,e,t;o=x-A[0];n=v-A[1];m=s-A[2];t=1/Math.sqrt(o*o+n*n+m*m);o*=t;n*=t;m*=t;y=i*m-h*n;w=h*o-j*m;u=j*n-i*o;t=Math.sqrt(y*y+w*w+u*u);if(!t){y=0;w=0;u=0;}else{t=1/t;y*=t;w*=t;u*=t;}g=n*u-m*w;f=m*y-o*u;e=o*w-n*y;t=Math.sqrt(g*g+f*f+e*e);if(!t){g=0;f=0;e=0;}else{t=1/t;g*=t;f*=t;e*=t;}k[0]=y;k[1]=g;k[2]=o;k[3]=0;k[4]=w;k[5]=f;k[6]=n;k[7]=0;k[8]=u;k[9]=e;k[10]=m;k[11]=0;k[12]=-(y*x+w*v+u*s);k[13]=-(g*x+f*v+e*s);k[14]=-(o*x+n*v+m*s);k[15]=1;return k;};b.str=function(e){return"["+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+", "+e[4]+", "+e[5]+", "+e[6]+", "+e[7]+", "+e[8]+", "+e[9]+", "+e[10]+", "+e[11]+", "+e[12]+", "+e[13]+", "+e[14]+", "+e[15]+"]";};quat4={};quat4.create=function(f){var e=new glMatrixArrayType(4);if(f){e[0]=f[0];e[1]=f[1];e[2]=f[2];e[3]=f[3];}return e;};quat4.set=function(f,e){e[0]=f[0];e[1]=f[1];e[2]=f[2];e[3]=f[3];return e;};quat4.calculateW=function(g,f){var e=g[0],i=g[1],h=g[2];if(!f||g==f){g[3]=-Math.sqrt(Math.abs(1-e*e-i*i-h*h));return g;}f[0]=e;f[1]=i;f[2]=h;f[3]=-Math.sqrt(Math.abs(1-e*e-i*i-h*h));return f;};quat4.inverse=function(f,e){if(!e||f==e){f[0]*=1;f[1]*=1;f[2]*=1;return f;}e[0]=-f[0];e[1]=-f[1];e[2]=-f[2];e[3]=f[3];return e;};quat4.length=function(g){var e=g[0],i=g[1],h=g[2],f=g[3];return Math.sqrt(e*e+i*i+h*h+f*f);};quat4.normalize=function(i,h){if(!h){h=i;}var f=i[0],k=i[1],j=i[2],g=i[3];var e=Math.sqrt(f*f+k*k+j*j+g*g);if(e==0){h[0]=0;h[1]=0;h[2]=0;h[3]=0;return h;}e=1/e;h[0]=f*e;h[1]=k*e;h[2]=j*e;h[3]=g*e;return h;};quat4.multiply=function(f,h,o){if(!o){o=f;}var m=f[0],l=f[1],k=f[2],n=f[3];var i=h[0],g=h[1],e=h[2],j=h[3];o[0]=m*j+n*i+l*e-k*g;o[1]=l*j+n*g+k*i-m*e;o[2]=k*j+n*e+m*g-l*i;o[3]=n*j-m*i-l*g-k*e;return o;};quat4.multiplyVec3=function(f,h,r){if(!r){r=h;}var q=h[0],p=h[1],o=h[2];var m=f[0],l=f[1],k=f[2],n=f[3];var i=n*q+l*o-k*p;var g=n*p+k*q-m*o;var e=n*o+m*p-l*q;var j=-m*q-l*p-k*o;r[0]=i*n+j*-m+g*-k-e*-l;r[1]=g*n+j*-l+e*-m-i*-k;r[2]=e*n+j*-k+i*-l-g*-m;return r;};quat4.toMat3=function(e,l){if(!l){l=c.create();}var m=e[0],k=e[1],j=e[2],n=e[3];var r=m+m;var f=k+k;var o=j+j;var i=m*r;var h=m*f;var g=m*o;var q=k*f;var p=k*o;var u=j*o;var v=n*r;var t=n*f;var s=n*o;l[0]=1-(q+u);l[1]=h-s;l[2]=g+t;l[3]=h+s;l[4]=1-(i+u);l[5]=p-v;l[6]=g-t;l[7]=p+v;l[8]=1-(i+q);return l;};quat4.toMat4=function(e,l){if(!l){l=b.create();}var m=e[0],k=e[1],j=e[2],n=e[3];var r=m+m;var f=k+k;var o=j+j;var i=m*r;var h=m*f;var g=m*o;var q=k*f;var p=k*o;var u=j*o;var v=n*r;var t=n*f;var s=n*o;l[0]=1-(q+u);l[1]=h-s;l[2]=g+t;l[3]=0;l[4]=h+s;l[5]=1-(i+u);l[6]=p-v;l[7]=0;l[8]=g-t;l[9]=p+v;l[10]=1-(i+q);l[11]=0;l[12]=0;l[13]=0;l[14]=0;l[15]=1;return l;};quat4.str=function(e){return"["+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+"]";};a.GLMatrix=b;})(jigLib);(function(a){var b=function(){throw new Error("Vector3DUtil is a utility class and should not be instantiated");};b.X_AXIS=[1,0,0,0];b.Y_AXIS=[0,1,0,0];b.Z_AXIS=[0,0,1,0];b.add=function(g,e){return[g[0]+e[0],g[1]+e[1],g[2]+e[2],g[3]+e[3]];};b.subtract=function(g,e){return[g[0]-e[0],g[1]-e[1],g[2]-e[2],g[3]-e[3]];};b.decrementBy=function(g,e){g[0]-=e[0];g[1]-=e[1];g[2]-=e[2];g[3]-=e[3];};b.IncrementBy=function(g,e){g[0]+=e[0];g[1]+=e[1];g[2]+=e[2];g[3]+=e[3];};b.distance=function(l,j){var h=Math;var g=h.pow;var e=g(l[0]-j[0],2);var k=g(l[1]-j[1],2);var i=g(l[2]-j[2],2);return h.sqrt(e+k+i);};b.dotProduct=function(g,e){return g[0]*e[0]+g[1]*e[1]+g[2]*e[2];};b.crossProduct=function(g,e){return[g[1]*e[2]-g[2]*e[1],g[2]*e[0]-g[0]*e[2],g[0]*e[1]-g[1]*e[0],0];};b.get_length=function(e){var g=e[0]*e[0]+e[1]*e[1]+e[2]*e[2];return(g>0)?Math.pow(g,0.5):0;};b.get_lengthSquared=function(e){var g=e[0]*e[0]+e[1]*e[1]+e[2]*e[2];return g;};b.normalize=function(e){f=b.get_length(e);e[0]/=f;e[1]/=f;e[2]/=f;return f;};b.negate=function(e){e[0]*=-1;e[1]*=-1;e[2]*=-1;return e;};b.scaleBy=function(e,g){e[0]*=g;e[1]*=g;e[2]*=g;};b.getSum=function(g){var e=Math.abs;return e(g[0])+e(g[1])+e(g[2]);};b.limitSum=function(g,h){var e=Math.abs;c=b.getSum(g);if(h>=c){return;}f=h/c;b.scaleBy(g,f);};b.project=function(e){e[0]/=e[3];e[1]/=e[3];e[2]/=e[3];e[3]=1;};b.angleBetween=function(i,g){var h=i.slice(0);var e=g.slice(0);b.normalize(h);b.normalize(e);d=b.dotProduct(h,e);if(d<-1){d=-1;}else{if(d>1){d=1;}}return Math.acos(d);};b.equals=function(h,g,e){if(!e){return(h[0]==g[0]&&h[1]==g[1]&&h[2]==g[2]);}else{return(h[0]==g[0]&&h[1]==g[1]&&h[2]==g[2]&&h[3]==g[3]);}};b.create=function(e,j,i,g){var h=[];h[0]=(e)?e:0;h[1]=(j)?j:0;h[2]=(i)?i:0;h[3]=(g)?g:0;return h;};a.Vector3DUtil=b;})(jigLib);(function(b){var c=b.Vector3DUtil;var a=b.GLMatrix;var d=function(e){if(e){this.glmatrix=a.create(e);}else{this.glmatrix=a.create([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);}};d.prototype.glmatrix=null;d.prototype.get_determinant=function(){return a.determinant(this.glmatrix);};d.prototype.prepend=function(e){a.multiply(e.glmatrix,this.glmatrix,this.glmatrix);};d.prototype.append=function(e){a.multiply(this.glmatrix,e.glmatrix);};d.prototype.angleAxis=function(s,j){var u,p,v,t,o,f,g,q,k;s=s/(3.14159*2);var n=j[0];var m=j[1];var l=j[2];var i=Math.cos(s);var h=1-i;var e=Math.sin(s);g=n*e;q=m*e;k=l*e;u=n*n;p=m*m;v=l*l;t=n*m;o=m*l;f=l*n;var r=[(h*u)+i,(h*t)-k,(h*f)+q,0,(h*t)+k,(h*p)+i,(h*o)-g,0,(h*f)-q,(h*o)+g,(h*v)+i,0,0,0,0,1];return new d(r);};d.prototype.rotate=function(g,f){var e=this.clone();a.rotate(e.glmatrix,g,f);return e;};d.prototype.translateMatrix=function(e){return new d([1,0,0,e[0],0,1,0,e[1],0,0,1,e[2],0,0,0,1]);};d.prototype.scaleMatrix=function(e){return new d([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,1]);};d.prototype.appendRotation=function(h,g,e){h=h/(3.14159*2);c.negate(g);if(e){var f=c.negate(e.slice(0));this.appendTranslation(f[0],f[1],f[2]);}a.rotate(this.glmatrix,h,g);if(e){this.appendTranslation(e[0],e[1],e[2]);}};d.prototype.prependRotation=function(g,f,e){if(e){this.prepend(this.translateMatrix(c.negate(e.slice(0))));}this.prepend(this.angleAxis(g,f));if(e){this.prepend(this.translateMatrix(e));}};d.prototype.appendScale=function(e,g,f){a.scale(this.glmatrix,[e,g,f]);};d.prototype.prependScale=function(e,g,f){this.prepend(this.scaleMatrix([e,g,f]));};d.prototype.appendTranslation=function(e,g,f){this.append(this.translateMatrix([e,g,f]));};d.prototype.prependTranslation=function(e,g,f){this.prepend(this.translateMatrix([e,g,f]));};d.prototype.identity=function(){a.identity(this.glmatrix);};d.prototype.transpose=function(){a.transpose(this.glmatrix);};d.prototype.invert=function(){a.inverse(this.glmatrix);};d.prototype.clone=function(){return new d(this.glmatrix);};d.prototype.transformVector=function(e){return a.multiplyVec3(this.glmatrix,e);};b.Matrix3D=d;})(jigLib);(function(a){var c=a.Vector3DUtil;var b={};b.NUM_TINY=0.00001;b.NUM_HUGE=100000;b.getScaleVector=function(d,e){return[d[0]*e,d[1]*e,d[2]*e,d[3]];};b.getDivideVector=function(e,d){return(d)?[e[0]/d,e[1]/d,e[2]/d,0]:[0,0,0,0];};b.getNormal=function(d,f,e){return c.normalize(c.crossProduct(c.subtract(f,d),c.subtract(e,f)));};b.copyFromArray=function(e,d){if(d.length>=3){e=d.slice(0);}};b.getLimiteNumber=function(e,f,d){var g=e;if(g<f){g=f;}else{if(g>d){g=d;}}return g;};a.JNumber3D=b;})(jigLib);(function(b){var c=b.Vector3DUtil;var d=b.Matrix3D;var a={};a.getTranslationMatrix=function(e,h,g){var f=new d();f.appendTranslation(e,h,g);return f;};a.getScaleMatrix=function(e,h,g){var f=new d();f.prependScale(e,h,g);return f;};a.getRotationMatrix=function(e,j,i,g,f){var h=new d();h.appendRotation(g,c.create(e,j,i,0),f);return h;};a.getInverseMatrix=function(e){var f=e.clone();f.invert();return f;};a.getTransposeMatrix=function(e){var f=e.clone();f.transpose();return f;};a.getAppendMatrix3D=function(f,e){var g=f.clone();g.append(e);return g;};a.getPrependMatrix=function(f,e){var g=f.clone();g.prepend(e);return g;};a.getSubMatrix=function(f,e){var g=[16];for(var h=0;h<16;h++){g[h]=f.glmatrix[h]-e.glmatrix[h];}return new d(g);};a.getRotationMatrixAxis=function(f,e){var g=new d();g.appendRotation(f,e?e:c.X_AXIS);return g;};a.getCols=function(g){var e=g.glmatrix;var f=[];f[0]=c.create(e[0],e[4],e[8],0);f[1]=c.create(e[1],e[5],e[9],0);f[2]=c.create(e[2],e[6],e[10],0);return f;};a.multiplyVector=function(j,e){var h=e[0];var g=e[1];var f=e[2];if(h==0&&g==0&&f==0){return;}var i=j.glmatrix;e[0]=h*i[0]+g*i[1]+f*i[2]+i[3];e[1]=h*i[4]+g*i[5]+f*i[6]+i[7];e[2]=h*i[8]+g*i[9]+f*i[10]+i[11];};b.JMatrix3D=a;})(jigLib);(function(a){var c=a.Vector3DUtil;var b={};b.fromNormalAndPoint=function(f,d){var e=c.create(f[0],f[1],f[2],0);e[3]=-(e[0]*d[0]+e[1]*d[1]+e[2]*d[2]);return f;};b.getIntersectionLine=function(f,e,i){var h=f[0]*e[0]+f[1]*e[1]+f[2]*e[2]-f[3];var g=f[0]*i[0]+f[1]*i[1]+f[2]*i[2]-f[3];var d=g/(g-h);return[i[0]+(e[0]-i[0])*d,i[1]+(e[1]-i[1])*d,i[2]+(e[2]-i[2])*d,0];};b.unproject=function(j,e,f,i,g){var h=(e*f)/e;var d=c.create(i/h,-g/h,e,0);return j.transformVector(d);};})(jigLib);(function(a){var b=function(){};b.prototype.pair=null;b.prototype.impulse=null;a.ContactData=b;})(jigLib);(function(a){var b=function(d,c){this.ind0=d;this.ind1=c;};a.EdgeData=b;})(jigLib);(function(a){var b=a.Vector3DUtil;var c=function(e,d){this.position=e.slice(0);this.normal=d.slice(0);this.distance=b.dotProduct(this.position,this._normal);};c.prototype.position=null;c.prototype.normal=null;c.prototype.distance=null;c.prototype.pointPlaneDistance=function(d){return b.dotProduct(normal,d)-distance;};a.PlaneData=c;})(jigLib);(function(a){var b=function(){};b.prototype.min=null;b.prototype.max=null;b.prototype.flag=null;b.prototype.depth=null;a.SpanData=b;})(jigLib);(function(c){var b=c.PhysicsSystem;var a=function(d){if(d){this.speed=d;}this.inittime=(new Date()).getTime();this.physicsSystem=b.getInstance();};a.prototype.speed=5;a.prototype.inittime=null;a.prototype.physicsSystem=null;a.prototype.addBody=function(d){this.physicsSystem.addBody(d);};a.prototype.removeBody=function(d){physicsSystem.removeBody(d);};a.prototype.get_engine=function(){return this.physicsSystem;};a.prototype.step=function(){var d=(new Date()).getTime();deltaTime=((d-this.initTime)/1000)*this.speed;this.initTime=d;this.physicsSystem.integrate(deltaTime);};c.AbstractPhysics=a;})(jigLib);(function(b){var c=b.Matrix3D;function a(){this.matrix=new c();}a.prototype.matrix=null;a.prototype.get_transform=function(){return this.matrix;};a.prototype.set_transform=function(d){this.matrix=d;};b.ISkin3D=a;})(jigLib);(function(a){var b=function(){};b.prototype.get_minW=function(){};b.prototype.get_minH=function(){};b.prototype.get_maxW=function(){};b.prototype.get_maxH=function(){};b.prototype.get_dw=function(){};b.prototype.get_dh=function(){};b.prototype.get_sw=function(){};b.prototype.get_sh=function(){};b.prototype.get_heights=function(){};a.ITerrain=b;})(jigLib);(function(a){var d=a.Vector3DUtil;var c=a.JNumber3D;var b=function(f,e){this._minPos=f.slice(0);this._maxPos=e.slice(0);};b.prototype._minPos=null;b.prototype._maxPos=null;b.prototype.get_minPos=function(){return this._minPos;};b.prototype.set_minPos=function(e){this._minPos=e.slice(0);};b.prototype.get_maxPos=function(){return this._maxPos;};b.prototype.set_maxPos=function(e){this._maxPos=e.slice(0);};b.prototype.get_sideLengths=function(){var e=this._maxPos.slice(0);d.subtract(e,this._minPos);return e;};b.prototype.get_centrePos=function(){var e=this._minPos.slice(0);return c.getScaleVector(d.add(e,this._maxPos),0.5);};b.prototype.move=function(e){d.add(this._minPos,e);d.add(this._maxPos,e);};b.prototype.clear=function(){this._minPos=d.create(c.NUM_HUGE,c.NUM_HUGE,c.NUM_HUGE,0);this._maxPos=d.create(-c.NUM_HUGE,-c.NUM_HUGE,-c.NUM_HUGE,0);};b.prototype.clone=function(){return new b(this._minPos,this._maxPos);};b.prototype.addPoint=function(g){var f=this._minPos;var e=this._maxPos;if(g[0]<f[0]){f[0]=g[0]-c.NUM_TINY;}if(g[0]>e[0]){e[0]=g[0]+c.NUM_TINY;}if(g[1]<f[1]){f[1]=g[1]-c.NUM_TINY;}if(g[1]>e[1]){e[1]=g[1]+c.NUM_TINY;}if(g[2]<f[2]){f[2]=g[2]-c.NUM_TINY;}if(g[2]>e[2]){e[2]=g[2]+c.NUM_TINY;}};b.prototype.addBox=function(e){var f=e.getCornerPoints(e.get_currentState());this.addPoint(f[0]);this.addPoint(f[1]);this.addPoint(f[2]);this.addPoint(f[3]);this.addPoint(f[4]);this.addPoint(f[5]);this.addPoint(f[6]);this.addPoint(f[7]);};b.prototype.addSphere=function(e){var g=this._minPos;var f=this._maxPos;if(e.get_currentState().position[0]-e.get_radius()<g[0]){g[0]=(e.get_currentState().position[0]-e.get_radius())-c.NUM_TINY;}if(e.get_currentState().position[0]+e.get_radius()>f[0]){f[0]=(e.get_currentState().position[0]+e.get_radius())+c.NUM_TINY;}if(e.get_currentState().position[1]-e.get_radius()<g[1]){g[1]=(e.get_currentState().position[1]-e.get_radius())-c.NUM_TINY;}if(e.get_currentState().position[1]+e.get_radius()>f[1]){f[1]=(e.get_currentState().position[1]+e.get_radius())+c.NUM_TINY;}if(e.get_currentState().position[2]-e.get_radius()<g[2]){g[2]=(e.get_currentState().position[2]-e.get_radius())-c.NUM_TINY;}if(e.get_currentState().position[2]+e.get_radius()>f[2]){f[2]=(e.get_currentState().position[2]+e.get_radius())+c.NUM_TINY;}};b.prototype.addCapsule=function(f){var h=f.getBottomPos(f.get_currentState());var g=this._minPos;var e=this._maxPos;if(h[0]-f.get_radius()<g[0]){g[0]=(h[0]-f.get_radius())-c.NUM_TINY;}if(h[0]+f.get_radius()>e[0]){e[0]=(h[0]+f.get_radius())+c.NUM_TINY;}if(h[1]-f.get_radius()<g[1]){g[1]=(h[1]-f.get_radius())-c.NUM_TINY;}if(h[1]+f.get_radius()>e[1]){e[1]=(h[1]+f.get_radius())+c.NUM_TINY;}if(h[2]-f.get_radius()<g[2]){g[2]=(h[2]-f.get_radius())-c.NUM_TINY;}if(h[2]+f.get_radius()>e[2]){e[2]=(h[2]+f.get_radius())+c.NUM_TINY;}h=f.getEndPos(f.get_currentState());if(h[0]-f.get_radius()<g[0]){g[0]=(h[0]-f.get_radius())-c.NUM_TINY;}if(h[0]+f.get_radius()>e[0]){e[0]=(h[0]+f.get_radius())+c.NUM_TINY;}if(h[1]-f.get_radius()<g[1]){g[1]=(h[1]-f.get_radius())-c.NUM_TINY;}if(h[1]+f.get_radius()>e[1]){e[1]=(h[1]+f.get_radius())+c.NUM_TINY;}if(h[2]-f.get_radius()<g[2]){g[2]=(h[2]-f.get_radius())-c.NUM_TINY;}if(h[2]+f.get_radius()>e[2]){e[2]=(h[2]+f.get_radius())+c.NUM_TINY;}};b.prototype.addSegment=function(e){this.addPoint(e.origin);this.addPoint(e.getEnd());};b.prototype.overlapTest=function(g){var f=this._minPos;var e=this._maxPos;return((f[2]>=g.get_maxPos()[2])||(e[2]<=g.get_minPos()[2])||(f[1]>=g.get_maxPos()[1])||(e[1]<=g.get_minPos()[1])||(f[0]>=g.get_maxPos()[0])||(e[0]<=g.get_minPos()[0]))?false:true;};b.prototype.isPointInside=function(g){var f=this._minPos;var e=this._maxPos;return((g[0]>=f[0])&&(g[0]<=e[0])&&(g[1]>=f[1])&&(g[1]<=e[1])&&(g[2]>=f[2])&&(g[2]<=e[2]));};b.prototype.toString=function(){var f=this._minPos;var e=this._maxPos;return[f[0],f[1],f[2],e[0],e[1],e[2]].toString();};a.JAABox=b;})(jigLib);(function(a){var b=function(f,e,d,c){if(f.id>e.id){this.body0=f;this.body1=e;this.r=d;}else{this.body0=e;this.body1=f;this.r=c;}};b.prototype.body0=null;b.prototype.body1=null;b.prototype.r=null;a.BodyPair=b;})(jigLib);(function(a){var b=function(d,e,c){this.normalImpulse=d;this.normalImpulseAux=e;this.frictionImpulse=c;};b.prototype.normalImpulse=null;b.prototype.normalImpulseAux=null;b.prototype.frictionImpulse=null;a.CachedImpulse=b;})(jigLib);(function(a){var b=function(c,d){if(c==null){c=0.25;}if(d==null){d=0.25;}this._restitution=c;this._friction=d;};b.prototype._restitution=null;b.prototype._friction=null;b.prototype.get_restitution=function(){return this._restitution;};b.prototype.set_restitution=function(c){this._restitution=c;};b.prototype.get_friction=function(){return this._friction;};b.prototype.set_friction=function(c){this._friction=c;};a.MaterialProperties=b;})(jigLib);(function(a){var b=function(){this._controllerEnabled=false;};b.prototype._controllerEnabled=null;b.prototype.updateController=function(c){};b.prototype.enableController=function(){if(this._controllerEnabled){return;}this._controllerEnabled=true;a.PhysicsSystem.getInstance().addController(this);};b.prototype.disableController=function(){if(!this._controllerEnabled){return;}this._controllerEnabled=false;a.PhysicsSystem.getInstance().removeController(this);};b.prototype.get_controllerEnabled=function(){return this._controllerEnabled;};a.PhysicsController=b;})(jigLib);(function(c){var d=c.Matrix3D;var b=c.JMatrix3D;var a=function(){this._orientation=new d();};a.prototype.position=[0,0,0,0];a.prototype._orientation;a.prototype.linVelocity=[0,0,0,0];a.prototype.rotVelocity=[0,0,0,0];a.prototype.orientationCols=[[0,0,0,0],[0,0,0,0],[0,0,0,0]];a.prototype.get_orientation=function(){return this._orientation;};a.prototype.set_orientation=function(f){this._orientation=f;var e=this._orientation.glmatrix;this.orientationCols[0][0]=e[0];this.orientationCols[0][1]=e[1];this.orientationCols[0][2]=e[2];this.orientationCols[1][0]=e[4];this.orientationCols[1][1]=e[5];this.orientationCols[1][2]=e[6];this.orientationCols[2][0]=e[8];this.orientationCols[2][1]=e[9];this.orientationCols[2][2]=e[10];};a.prototype.getOrientationCols=function(){return b.getCols(this._orientation);};c.PhysicsState=a;})(jigLib);(function(d){var j=d.Vector3DUtil;var g=d.JConfig;var h=d.Matrix3D;var e=d.JMatrix3D;var a=d.JNumber3D;var c=d.MaterialProperties;var b=d.PhysicsState;var f=d.PhysicsSystem;var i=d.JAABox;var k=function(l){this._useDegrees=(g.rotationType=="DEGREES")?true:false;this._id=k.idCounter++;this._skin=l;this._material=new c();this._bodyInertia=new h();this._bodyInvInertia=e.getInverseMatrix(this._bodyInertia);this._currState=new b();this._oldState=new b();this._storeState=new b();this._invOrientation=e.getInverseMatrix(this._currState.get_orientation());this._currLinVelocityAux=[0,0,0,0];this._currRotVelocityAux=[0,0,0,0];this._force=[0,0,0,0];this._torque=[0,0,0,0];this._linVelDamping=[0.995,0.995,0.995,0];this._rotVelDamping=[0.5,0.5,0.5,0];this._maxLinVelocities=500;this._maxRotVelocities=50;this._velChanged=false;this._inactiveTime=0;this._doShockProcessing=true;this.isActive=this._activity=true;this._movable=true;this._origMovable=true;this.collisions=[];this._constraints=[];this._nonCollidables=[];this._storedPositionForActivation=[0,0,0,0];this._bodiesToBeActivatedOnMovement=[];this._lastPositionForDeactivation=this._currState.position.slice(0);this._lastOrientationForDeactivation=this._currState.get_orientation().clone();this._type="Object3D";this._boundingSphere=0;this._boundingBox=new i([0,0,0,0],[0,0,0,0]);this._boundingBox.clear();};k.idCounter=0;k.prototype._id=null;k.prototype._skin=null;k.prototype._type=null;k.prototype._boundingSphere=null;k.prototype._boundingBox=null;k.prototype._currState=null;k.prototype._oldState=null;k.prototype._storeState=null;k.prototype._invOrientation=null;k.prototype._currLinVelocityAux=null;k.prototype._currRotVelocityAux=null;k.prototype._mass=null;k.prototype._invMass=null;k.prototype._bodyInertia=null;k.prototype._bodyInvInertia=null;k.prototype._worldInertia=null;k.prototype._worldInvInertia=null;k.prototype._force=null;k.prototype._torque=null;k.prototype._linVelDamping=null;k.prototype._rotVelDamping=null;k.prototype._maxLinVelocities=null;k.prototype._maxRotVelocities=null;k.prototype._velChanged=null;k.prototype._activity=null;k.prototype._movable=null;k.prototype._origMovable=null;k.prototype._inactiveTime=null;k.prototype._doShockProcessing=null;k.prototype._bodiesToBeActivatedOnMovement=null;k.prototype._storedPositionForActivation=null;k.prototype._lastPositionForDeactivation=null;k.prototype._lastOrientationForDeactivation=null;k.prototype._material=null;k.prototype._rotationX=0;k.prototype._rotationY=0;k.prototype._rotationZ=0;k.prototype._useDegrees=null;k.prototype._nonCollidables=null;k.prototype._constraints=null;k.prototype.collisions=null;k.prototype.isActive=null;k.prototype.radiansToDegrees=function(l){return l*180/Math.PI;};k.prototype.degreesToRadians=function(l){return l*Math.PI/180;};k.prototype.get_rotationX=function(){return this._rotationX;};k.prototype.get_rotationY=function(){return this._rotationY;};k.prototype.get_rotationZ=function(){return this._rotationZ;};k.prototype.set_rotationX=function(l){this._rotationX=l;this.setOrientation(this.createRotationMatrix());};k.prototype.set_rotationY=function(l){this._rotationY=l;this.setOrientation(this.createRotationMatrix());};k.prototype.set_rotationZ=function(l){this._rotationZ=l;this.setOrientation(this.createRotationMatrix());};k.prototype.setRotation=function(l){this._rotationX=l[0];this._rotationY=l[1];this._rotationZ=l[2];this.setOrientation(this.createRotationMatrix());};k.prototype.pitch=function(l){this.setOrientation(e.getAppendMatrix3D(this.get_currentState().orientation,e.getRotationMatrixAxis(l,j.X_AXIS)));};k.prototype.yaw=function(l){this.setOrientation(e.getAppendMatrix3D(this.get_currentState().orientation,e.getRotationMatrixAxis(l,j.Y_AXIS)));};k.prototype.roll=function(l){this.setOrientation(e.getAppendMatrix3D(this.get_currentState().orientation,e.getRotationMatrixAxis(l,j.Z_AXIS)));};k.prototype.createRotationMatrix=function(){var l=new h();l.appendRotation(this._rotationX,j.X_AXIS);l.appendRotation(this._rotationY,j.Y_AXIS);l.appendRotation(this._rotationZ,j.Z_AXIS);return l;};k.prototype.setOrientation=function(l){this._currState.set_orientation(l.clone());this.updateInertia();this.updateState();};k.prototype.get_position=function(){return this._currState.position;};k.prototype.get_x=function(){return this._currState.position[0];};k.prototype.get_y=function(){return this._currState.position[1];};k.prototype.get_z=function(){return this._currState.position[2];};k.prototype.set_x=function(l){this._currState.position[0]=l;this.updateState();};k.prototype.set_y=function(l){this._currState.position[1]=l;this.updateState();};k.prototype.set_z=function(l){this._currState.position[2]=l;this.updateState();};k.prototype.moveTo=function(l){this._currState.position=l.slice(0);this.updateState();};k.prototype.updateState=function(){this._currState.linVelocity=[0,0,0,0];this._currState.rotVelocity=[0,0,0,0];this.copyCurrentStateToOld();this.updateBoundingBox();};k.prototype.setVelocity=function(l){this._currState.linVelocity=l.slice(0);};k.prototype.setAngVel=function(l){this._currState.rotVelocity=l.slice(0);};k.prototype.setVelocityAux=function(l){this._currLinVelocityAux=l.slice(0);};k.prototype.setAngVelAux=function(l){this._currRotVelocityAux=l.slice(0);};k.prototype.addGravity=function(){if(!this._movable){return;}this._force=j.add(this._force,a.getScaleVector(d.PhysicsSystem.getInstance().get_gravity(),this._mass));this._velChanged=true;};k.prototype.addExternalForces=function(l){this.addGravity();};k.prototype.addWorldTorque=function(l){if(!this._movable){return;}this._torque=j.add(this._torque,l);this._velChanged=true;this.setActive();};k.prototype.addBodyTorque=function(l){if(!this._movable){return;}e.multiplyVector(this._currState.get_orientation(),l);this.addWorldTorque(l);};k.prototype.addWorldForce=function(l,m){if(!this._movable){return;}this._force=j.add(this._force,l);this.addWorldTorque(j.crossProduct(j.subtract(m,this._currState.position),l));this._velChanged=true;this.setActive();};k.prototype.addBodyForce=function(l,m){if(!this._movable){return;}e.multiplyVector(this._currState.get_orientation(),l);e.multiplyVector(this._currState.get_orientation(),m);this.addWorldForce(l,j.add(this._currState.position,m));};k.prototype.clearForces=function(){this._force=[0,0,0,0];this._torque=[0,0,0,0];};k.prototype.applyWorldImpulse=function(m,n){if(!this._movable){return;}this._currState.linVelocity=j.add(this._currState.linVelocity,a.getScaleVector(m,this._invMass));var l=j.crossProduct(j.subtract(n,this._currState.position),m);e.multiplyVector(this._worldInvInertia,l);this._currState.rotVelocity=j.add(this._currState.rotVelocity,l);this._velChanged=true;};k.prototype.applyWorldImpulseAux=function(m,n){if(!this._movable){return;}this._currLinVelocityAux=j.add(this._currLinVelocityAux,a.getScaleVector(m,this._invMass));var l=j.crossProduct(j.subtract(n,this._currState.position),m);e.multiplyVector(this._worldInvInertia,l);this._currRotVelocityAux=j.add(this._currRotVelocityAux,l);this._velChanged=true;};k.prototype.applyBodyWorldImpulse=function(m,n){if(!this._movable){return;}this._currState.linVelocity=j.add(this._currState.linVelocity,a.getScaleVector(m,this._invMass));var l=j.crossProduct(n,m);e.multiplyVector(this._worldInvInertia,l);this._currState.rotVelocity=j.add(this._currState.rotVelocity,l);this._velChanged=true;};k.prototype.applyBodyWorldImpulseAux=function(m,n){if(!this._movable){return;}this._currLinVelocityAux=j.add(this._currLinVelocityAux,a.getScaleVector(m,this._invMass));var l=j.crossProduct(n,m);e.multiplyVector(this._worldInvInertia,l);this._currRotVelocityAux=j.add(this._currRotVelocityAux,l);this._velChanged=true;};k.prototype.addConstraint=function(l){if(!this.findConstraint(l)){this._constraints.push(l);}};k.prototype.removeConstraint=function(l){if(this.findConstraint(l)){this._constraints.splice(this._constraints.indexOf(l),1);}};k.prototype.removeAllConstraints=function(){this._constraints=[];};k.prototype.findConstraint=function(n){for(var m=0,l=this._constraints.length;m<l;m++){if(n==this._constraints[m]){return true;}}return false;};k.prototype.updateVelocity=function(m){if(!this._movable||!this._activity){return;}this._currState.linVelocity=j.add(this._currState.linVelocity,a.getScaleVector(this._force,this._invMass*m));var l=a.getScaleVector(this._torque,m);e.multiplyVector(this._worldInvInertia,l);this._currState.rotVelocity=j.add(this._currState.rotVelocity,l);};k.prototype.updatePositionWithAux=function(q){if(!this._movable||!this._activity){this._currLinVelocityAux=[0,0,0,0];this._currRotVelocityAux=[0,0,0,0];return;}var r=d.PhysicsSystem.getInstance().get_gravityAxis();if(r!=-1){var l=this._currLinVelocityAux.slice(0);l[(r+1)%3]*=0.1;l[(r+2)%3]*=0.1;a.copyFromArray(this._currLinVelocityAux,l);}var n=this._currState.rotVelocity.slice(0);e.multiplyVector(this._worldInertia,n);this._currState.position=j.add(this._currState.position,a.getScaleVector(j.add(this._currState.linVelocity,this._currLinVelocityAux),q));var p=j.add(this._currState.rotVelocity,this._currRotVelocityAux);var o=j.get_length(p)*180/Math.PI;if(o>0){j.normalize(p);o*=q;var m=e.getRotationMatrix(p[0],p[1],p[2],o);this._currState.set_orientation(e.getAppendMatrix3D(this._currState.get_orientation(),m));this.updateInertia();}this._currLinVelocityAux=[0,0,0,0];this._currRotVelocityAux=[0,0,0,0];e.multiplyVector(this._worldInvInertia,n);this._currState.rotVelocity=n.slice(0);this.updateBoundingBox();};k.prototype.postPhysics=function(l){};k.prototype.tryToFreeze=function(m){if(!this._movable||!this._activity){return;}if(j.get_length(j.subtract(this._currState.position,this._lastPositionForDeactivation))>g.posThreshold){this._lastPositionForDeactivation=this._currState.position.slice(0);this._inactiveTime=0;return;}var l=g.orientThreshold;var o=e.getSubMatrix(this._currState.get_orientation(),this._lastOrientationForDeactivation);var n=e.getCols(o);if(j.get_length(n[0])>l||j.get_length(n[1])>l||j.get_length(n[2])>l){this._lastOrientationForDeactivation=this._currState.get_orientation().clone();this._inactiveTime=0;return;}if(this.getShouldBeActive()){return;}this._inactiveTime+=m;if(this._inactiveTime>g.deactivationTime){this._lastPositionForDeactivation=this._currState.position.slice(0);this._lastOrientationForDeactivation=this._currState.get_orientation().clone();this.setInactive();}};k.prototype.set_mass=function(l){this._mass=l;this._invMass=1/l;this.setInertia(this.getInertiaProperties(l));};k.prototype.setInertia=function(l){this._bodyInertia=l.clone();this._bodyInvInertia=e.getInverseMatrix(this._bodyInertia.clone());this.updateInertia();};k.prototype.updateInertia=function(){this._invOrientation=e.getTransposeMatrix(this._currState.get_orientation());this._worldInertia=e.getAppendMatrix3D(this._invOrientation,e.getAppendMatrix3D(this._currState.get_orientation(),this._bodyInertia));this._worldInvInertia=e.getAppendMatrix3D(this._invOrientation,e.getAppendMatrix3D(this._currState.get_orientation(),this._bodyInvInertia));};k.prototype.get_movable=function(){return this._movable;};k.prototype.set_movable=function(l){if(this._type=="PLANE"||this._type=="TERRAIN"){return;}this._movable=l;this.isActive=this._activity=l;this._origMovable=l;};k.prototype.internalSetImmovable=function(){if(this._type=="PLANE"||this._type=="TERRAIN"){return;}this._origMovable=this._movable;this._movable=false;};k.prototype.internalRestoreImmovable=function(){if(this._type=="PLANE"||this._type=="TERRAIN"){return;}this._movable=this._origMovable;};k.prototype.getVelChanged=function(){return this._velChanged;};k.prototype.clearVelChanged=function(){this._velChanged=false;};k.prototype.setActive=function(l){if(!l){l=1;}if(this._movable){this.isActive=this._activity=true;this._inactiveTime=(1-l)*g.deactivationTime;}};k.prototype.setInactive=function(){if(this._movable){this.isActive=this._activity=false;}};k.prototype.getVelocity=function(l){return j.add(this._currState.linVelocity,j.crossProduct(this._currState.rotVelocity,l));};k.prototype.getVelocityAux=function(l){return j.add(this._currLinVelocityAux,j.crossProduct(this._currRotVelocityAux,l));};k.prototype.getShouldBeActive=function(){return((j.get_length(this._currState.linVelocity)>g.velThreshold)||(j.get_length(this._currState.rotVelocity)>g.angVelThreshold));};k.prototype.getShouldBeActiveAux=function(){return((j.get_length(this._currLinVelocityAux)>g.velThreshold)||(j.get_length(this._currRotVelocityAux)>g.angVelThreshold));};k.prototype.dampForDeactivation=function(){this._currState.linVelocity[0]*=this._linVelDamping[0];this._currState.linVelocity[1]*=this._linVelDamping[1];this._currState.linVelocity[2]*=this._linVelDamping[2];this._currState.rotVelocity[0]*=this._rotVelDamping[0];this._currState.rotVelocity[1]*=this._rotVelDamping[1];this._currState.rotVelocity[2]*=this._rotVelDamping[2];this._currLinVelocityAux[0]*=this._linVelDamping[0];this._currLinVelocityAux[1]*=this._linVelDamping[1];this._currLinVelocityAux[2]*=this._linVelDamping[2];this._currRotVelocityAux[0]*=this._rotVelDamping[0];this._currRotVelocityAux[1]*=this._rotVelDamping[1];this._currRotVelocityAux[2]*=this._rotVelDamping[2];var m=0.5;var l=this._inactiveTime/g.deactivationTime;if(l<m){return;}var n=1-((l-m)/(1-m));if(n<0){n=0;}else{if(n>1){n=1;}}this._currState.linVelocity=a.getScaleVector(this._currState.linVelocity,n);this._currState.rotVelocity=a.getScaleVector(this._currState.rotVelocity,n);};k.prototype.doMovementActivations=function(){var l=this._bodiesToBeActivatedOnMovement.length;if(l==0||j.get_length(j.subtract(this._currState.position,this._storedPositionForActivation))<g.posThreshold){return;}for(var m=0;m<l;m++){d.PhysicsSystem.getInstance().activateObject(this._bodiesToBeActivatedOnMovement[m]);}this._bodiesToBeActivatedOnMovement=[];};k.prototype.addMovementActivation=function(o,n){var l=this._bodiesToBeActivatedOnMovement.length;for(var m=0;m<l;m++){if(this._bodiesToBeActivatedOnMovement[m]==n){return;}}if(this._bodiesToBeActivatedOnMovement.length==0){this._storedPositionForActivation=o;}this._bodiesToBeActivatedOnMovement.push(n);};k.prototype.setConstraintsAndCollisionsUnsatisfied=function(){for(var m=0,l=this._constraints.length;m<l;m++){this._constraints[m].set_satisfied(false);}for(var m=0,n=this.collisions.length;m<n;m++){this.collisions[m].satisfied=false;}};k.prototype.segmentIntersect=function(m,l,n){return false;};k.prototype.getInertiaProperties=function(l){return new h();};k.prototype.updateBoundingBox=function(){};k.prototype.hitTestObject3D=function(l){var n=j.get_length(j.subtract(this._currState.position,l.get_currentState().position));var m=this._boundingSphere+l.get_boundingSphere();if(n<=m){return true;}return false;};k.prototype.findNonCollidablesBody=function(l){for(var n=0,m=this._nonCollidables.length;n<m;n++){if(l==this._nonCollidables[n]){return true;}}return false;};k.prototype.disableCollisions=function(l){if(!this.findNonCollidablesBody(l)){this._nonCollidables.push(l);}};k.prototype.enableCollisions=function(l){if(this.findNonCollidablesBody(l)){this._nonCollidables.splice(this._nonCollidables.indexOf(l),1);}};k.prototype.copyCurrentStateToOld=function(){this._oldState.position=this._currState.position.slice(0);this._oldState.set_orientation(this._currState.get_orientation().clone());this._oldState.linVelocity=this._currState.linVelocity.slice(0);this._oldState.rotVelocity=this._currState.rotVelocity.slice(0);};k.prototype.storeState=function(){this._storeState.position=this._currState.position.slice(0);this._storeState.set_orientation(this._currState.get_orientation().clone());this._storeState.linVelocity=this._currState.linVelocity.slice(0);this._storeState.rotVelocity=this._currState.rotVelocity.slice(0);};k.prototype.restoreState=function(){this._currState.position=this._storeState.position.slice(0);this._currState.set_orientation(this._storeState.get_orientation().clone());this._currState.linVelocity=this._storeState.linVelocity.slice(0);
2
+ this._currState.rotVelocity=this._storeState.rotVelocity.slice(0);};k.prototype.get_currentState=function(){return this._currState;};k.prototype.get_oldState=function(){return this._oldState;};k.prototype.get_id=function(){return this._id;};k.prototype.get_type=function(){return this._type;};k.prototype.get_skin=function(){return this._skin;};k.prototype.get_boundingSphere=function(){return this._boundingSphere;};k.prototype.get_boundingBox=function(){return this._boundingBox;};k.prototype.get_force=function(){return this._force;};k.prototype.get_mass=function(){return this._mass;};k.prototype.get_invMass=function(){return this._invMass;};k.prototype.get_worldInertia=function(){return this._worldInertia;};k.prototype.get_worldInvInertia=function(){return this._worldInvInertia;};k.prototype.get_nonCollidables=function(){return this._nonCollidables;};k.prototype.get_doShockProcessing=function(){return this._doShockProcessing;};k.prototype.set_doShockProcessing=function(l){this._doShockProcessing=l;};k.prototype.set_linVelocityDamping=function(l){this._linVelDamping[0]=a.getLimiteNumber(l[0],0,1);this._linVelDamping[1]=a.getLimiteNumber(l[1],0,1);this._linVelDamping[2]=a.getLimiteNumber(l[2],0,1);};k.prototype.get_linVelocityDamping=function(){return this._linVelDamping;};k.prototype.set_rotVelocityDamping=function(l){this._rotVelDamping[0]=a.getLimiteNumber(l[0],0,1);this._rotVelDamping[1]=a.getLimiteNumber(l[1],0,1);this._rotVelDamping[2]=a.getLimiteNumber(l[2],0,1);};k.prototype.get_rotVelocityDamping=function(){return this._rotVelDamping;};k.prototype.set_maxLinVelocities=function(l){this._maxLinVelocities=a.getLimiteNumber(Math.abs(l),0,500);};k.prototype.get_maxLinVelocities=function(){return this._maxLinVelocities;};k.prototype.set_maxRotVelocities=function(l){this._maxRotVelocities=a.getLimiteNumber(Math.abs(l),a.NUM_TINY,50);};k.prototype.get_maxRotVelocities=function(){return this._maxRotVelocities;};k.prototype.limitVel=function(){this._currState.linVelocity[0]=a.getLimiteNumber(this._currState.linVelocity[0],-this._maxLinVelocities,this._maxLinVelocities);this._currState.linVelocity[1]=a.getLimiteNumber(this._currState.linVelocity[1],-this._maxLinVelocities,this._maxLinVelocities);this._currState.linVelocity[2]=a.getLimiteNumber(this._currState.linVelocity[2],-this._maxLinVelocities,this._maxLinVelocities);};k.prototype.limitAngVel=function(){var n=Math.abs(this._currState.rotVelocity[0])/this._maxRotVelocities;var m=Math.abs(this._currState.rotVelocity[1])/this._maxRotVelocities;var l=Math.abs(this._currState.rotVelocity[2])/this._maxRotVelocities;var o=Math.max(n,m,l);if(o>1){this._currState.rotVelocity=a.getDivideVector(this._currState.rotVelocity,o);}};k.prototype.getTransform=function(){if(this._skin!=null){return this._skin.get_transform();}else{return null;}};k.prototype.updateObject3D=function(){if(this._skin!=null){this._skin.set_transform(e.getAppendMatrix3D(this._currState.get_orientation(),e.getTranslationMatrix(this._currState.position[0],this._currState.position[1],this._currState.position[2])));}};k.prototype.get_material=function(){return this._material;};k.prototype.get_restitution=function(){return this._material.get_restitution();};k.prototype.set_restitution=function(l){this._material.set_restitution(a.getLimiteNumber(l,0,1));};k.prototype.get_friction=function(){return this._material.get_friction();};k.prototype.set_friction=function(l){this._material.set_friction(a.getLimiteNumber(l,0,1));};d.RigidBody=k;})(jigLib);(function(a){var b=function(){this._effectEnabled=true;};b.prototype._effectEnabled=false;b.prototype.__defineGetter__("enabled",function(){return this._effectEnabled;});b.prototype.__defineSetter__("enabled",function(c){if(c==this._effectEnabled){return;}this._effectEnabled=c;if(c){a.PhysicsSystem.getInstance().addEffect(this);}else{a.PhysicsSystem.getInstance().removeEffect(this);}});b.prototype.Apply=function(){return;};a.JEffect=b;})(jigLib);(function(a){var b=a.Vector3DUtil;var c=function(e,f,d,h,g){this.Super();this.location=e;this.radius=f;this.force=d;if(h){this.parent=h;}if(h&&g){this.relativity=true;}this.enabled=false;};a.extend(c,a.JEffect);c.prototype.location=null;c.prototype.radius=null;c.prototype.force=null;c.prototype.parent=null;c.prototype.relativity=false;c.prototype.explode=function(){this.enabled=true;};c.prototype.Apply=function(){this.enabled=false;var g=a.PhysicsSystem.getInstance();var e=g.get_bodies();var f=e.length;var l,k,h,j;var d=[0,0,0,0];if(this.parent){this.location=this.parent.get_position();}this._affectedBodies=[];while(f--){l=e[f];if(this.parent&&l==this.parent){continue;}if(l._type!="PLANE"){k=b.distance(l.get_position(),this.location);if(k<this.radius){j=b.subtract(l.get_position(),this.location);h=(1-(k/this.radius))*this.force;b.scaleBy(j,h);if(this.relativity){d=b.add(j,d);}if(l.get_movable()){g.activateObject(l);l.addWorldForce(j,this.location);}}}else{if(this.relativity){k=l.pointPlaneDistance(this.location);if(k<this.radius){j=b.negate(l.get_normal().slice(0));h=(1-(k/this.radius))*(this.force*2);b.scaleBy(j,h);d=b.add(j,d);}}}}if(this.relativity){b.limitSum(d,this.force);b.negate(d);g.activateObject(this.parent);this.parent.applyWorldImpulse(d,this.location);}};a.Explosion=c;})(jigLib);(function(a){var c=a.Vector3DUtil;var b=function(e,f,d,g){this.Super();this.location=e;this.radius=f;this.force=d;if(g){this.parent=g;}};a.extend(b,a.JEffect);b.prototype.location=null;b.prototype.radius=null;b.prototype.force=null;b.prototype.parent=null;b.prototype.Apply=function(){var f=a.PhysicsSystem.getInstance();var d=f.get_bodies();var e=d.length-1;var k,j,g,h;if(this.parent){this.location=this.parent.get_position();}this._affectedBodies=[];do{k=d[e];if(!k.get_movable()||(this.parent&&k==this.parent)){continue;}j=c.distance(k.get_position(),this.location);if(j<this.radius){h=c.subtract(k.get_position(),this.location);g=(1-(j/this.radius))*this.force;c.scaleBy(h,g);c.negate(h);f.activateObject(k);k.applyWorldImpulse(h,this.location);}}while(e--);};a.GravityField=b;})(jigLib);(function(a){var b=a.Vector3DUtil;var c=function(d,e){this.Super();this.direction=d;if(e){this.exclusions=e;}};a.extend(c,a.JEffect);c.prototype.direction=null;c.prototype.exclusions=[];c.prototype.isExcluded=function(d){var e=this.exclusions.length;while(e--){if(this.exclusions[e]==d){return true;}}return false;};c.prototype.Apply=function(){var f=a.PhysicsSystem.getInstance();var d=f.get_bodies();var e=d.length;var g;this._affectedBodies=[];while(e--){g=d[e];if(!g.get_movable()||this.isExcluded(g)){continue;}f.activateObject(g);g.applyWorldImpulse(this.direction,g.get_position());}};a.Wind=c;})(jigLib);(function(c){var g=c.Vector3DUtil;var b=c.JMatrix3D;var d=c.JNumber3D;var h=c.RigidBody;var f=c.EdgeData;var e=c.SpanData;var a=function(k,j,l,i){c.RigidBody.call(this);this._edges=[new f(0,1),new f(3,1),new f(2,3),new f(2,0),new f(4,5),new f(5,7),new f(6,7),new f(4,6),new f(7,1),new f(5,3),new f(4,2),new f(6,0)];this._faces=[[6,7,1,0],[5,4,2,3],[3,1,7,5],[4,6,0,2],[1,3,2,0],[7,6,4,5]];this._type="BOX";this._sideLengths=g.create(j,i,l,0);this._boundingSphere=0.5*g.get_length(this._sideLengths);this.initPoints();this.set_mass(1);this.updateBoundingBox();};c.extend(a,c.RigidBody);a.prototype._sideLengths=null;a.prototype._points=null;a.prototype._edges=null;a.prototype._faces=null;a.prototype.initPoints=function(){var i=this.getHalfSideLengths();this._points=[];this._points[0]=g.create(i[0],-i[1],i[2],0);this._points[1]=g.create(i[0],i[1],i[2],0);this._points[2]=g.create(-i[0],-i[1],i[2],0);this._points[3]=g.create(-i[0],i[1],i[2],0);this._points[4]=g.create(-i[0],-i[1],-i[2],0);this._points[5]=g.create(-i[0],i[1],-i[2],0);this._points[6]=g.create(i[0],-i[1],-i[2],0);this._points[7]=g.create(i[0],i[1],-i[2],0);};a.prototype.set_sideLengths=function(i){this._sideLengths=i.slice(0);this._boundingSphere=0.5*g.get_length(this._sideLengths);this.initPoints();this.setInertia(this.getInertiaProperties(this.get_mass()));this.setActive();this.updateBoundingBox();};a.prototype.get_sideLengths=function(){return this._sideLengths;};a.prototype.get_edges=function(){return this._edges;};a.prototype.getVolume=function(){return(this._sideLengths[0]*this._sideLengths[1]*this._sideLengths[2]);};a.prototype.getSurfaceArea=function(){return 2*(this._sideLengths[0]*this._sideLengths[1]+this._sideLengths[0]*this._sideLengths[2]+this._sideLengths[1]*this._sideLengths[2]);};a.prototype.getHalfSideLengths=function(){return d.getScaleVector(this._sideLengths,0.5);};a.prototype.getSpan=function(k){var o=this.get_currentState().getOrientationCols();var n=new e();var j=Math.abs(g.dotProduct(k,o[0]))*(0.5*this._sideLengths[0]);var i=Math.abs(g.dotProduct(k,o[1]))*(0.5*this._sideLengths[1]);var q=Math.abs(g.dotProduct(k,o[2]))*(0.5*this._sideLengths[2]);var l=j+i+q;var m=g.dotProduct(this.get_currentState().position,k);n.min=m-l;n.max=m+l;return n;};a.prototype.getCornerPoints=function(p){var o;var j=[];var k=b.getTranslationMatrix(p.position[0],p.position[1],p.position[2]);k=b.getAppendMatrix3D(p.get_orientation(),k);for(var l=0,m=this._points.length;l<m;l++){var n=this._points[l];o=g.create(n[0],n[1],n[2],0);b.multiplyVector(k,o);j.push(o);}return j;};a.prototype.getCornerPointsInBoxSpace=function(l,p){var k=b.getTransposeMatrix(p.get_orientation());var q=g.subtract(l.position,p.position);b.multiplyVector(k,q);var n=b.getAppendMatrix3D(l.get_orientation(),k);var j=[];var m=b.getTranslationMatrix(q[0],q[1],q[2]);m=b.getAppendMatrix3D(n,m);for(var o=0;o<this._points.length;o++){_point=this._points[o].slice(0);b.multiplyVector(m,_point);j[o]=_point;}return j;};a.prototype.getSqDistanceToPoint=function(m,k,j){k.pos=g.subtract(j,m.position);b.multiplyVector(b.getTransposeMatrix(m.get_orientation()),k.pos);var n=0;var l=0;var i=this.getHalfSideLengths();if(k.pos[0]<-i[0]){n=k.pos[0]+i[0];l+=(n*n);k.pos[0]=-i[0];}else{if(k.pos[0]>i[0]){n=k.pos[0]-i[0];l+=(n*n);k.pos[0]=i[0];}}if(k.pos[1]<-i[1]){n=k.pos[1]+i[1];l+=(n*n);k.pos[1]=-i[1];}else{if(k.pos[1]>i[1]){n=k.pos[1]-i[1];l+=(n*n);k.pos[1]=i[1];}}if(k.pos[2]<-i[2]){n=k.pos[2]+i[2];l+=(n*n);k.pos[2]=-i[2];}else{if(k.pos[2]>i[2]){n=(k.pos[2]-i[2]);l+=(n*n);k.pos[2]=i[2];}}b.multiplyVector(m.get_orientation(),k.pos);k.pos=g.add(m.position,k.pos);return l;};a.prototype.getDistanceToPoint=function(k,j,i){return Math.sqrt(this.getSqDistanceToPoint(k,j,i));};a.prototype.pointIntersect=function(n){var m=g.subtract(n,this.get_currentState().position);var k=d.getScaleVector(this._sideLengths,0.5);var j;var l=this.get_currentState().getOrientationCols();for(var i;i<3;i++){j=l[i].slice(0);g.normalize(j);if(Math.abs(g.dotProduct(j,m))>k[i]+d.NUM_TINY){return false;}}return true;};a.prototype.getSupportVertices=function(p){var v=[];var w=[1,1,1];var x;var y=this.get_currentState().getOrientationCols();g.normalize(y[0]);g.normalize(y[1]);g.normalize(y[2]);for(var s=0;s<3;s++){w[s]=g.dotProduct(p,y[s]);if(Math.abs(w[s])>1-0.001){var u=(w[s]<0)?(s*2):(s*2)+1;for(var r=0;r<4;r++){x=this._points[this._faces[u][r]];var z=v[r]=this.get_currentState().position.slice(0);z=g.add(z,d.getScaleVector(y[0],x[0]));z=g.add(z,d.getScaleVector(y[1],x[1]));z=g.add(z,d.getScaleVector(y[2],x[2]));}return v;}}for(s=0;s<3;s++){if(Math.abs(w[s])<0.005){var q;var o=(s+1)%3;var l=(s+2)%3;x=this.get_currentState().position.slice(0);q=(w[o]>0)?-1:1;x=g.add(x,d.getScaleVector(y[o],q*this._sideLengths[o]/2));q=(w[l]>0)?-1:1;x=g.add(x,d.getScaleVector(y[l],q*this._sideLengths[l]/2));v[0]=g.add(x,d.getScaleVector(y[s],this._sideLengths[s]/2));v[1]=g.add(x,d.getScaleVector(y[s],-this._sideLengths[s]/2));return v;}}var t=v[0]=this.get_currentState().position.slice(0);q=(w[0]>0)?-1:1;v[0]=g.add(t,d.getScaleVector(y[0],q*this._sideLengths[0]/2));q=(w[1]>0)?-1:1;v[0]=g.add(t,d.getScaleVector(y[1],q*this._sideLengths[1]/2));q=(w[2]>0)?-1:1;v[0]=g.add(t,d.getScaleVector(y[2],q*this._sideLengths[2]/2));return v;};a.prototype.segmentIntersect=function(x,z,k){x.fracOut=0;x.posOut=[0,0,0,0];x.normalOut=[0,0,0,0];var j=d.NUM_HUGE;var v=-d.NUM_HUGE;var w=d.NUM_HUGE;var C=0;var i=0;var u=0;var s=g.subtract(k.position,z.origin);var y=d.getScaleVector(this._sideLengths,0.5);var B;var A;var q;var n;var m;var o=k.getOrientationCols();var r=y.slice(0);var l;for(u=0;u<3;u++){l=r[u];B=g.dotProduct(o[u],s);A=g.dotProduct(o[u],z.delta);if(Math.abs(A)>d.NUM_TINY){n=(B+l)/A;m=(B-l)/A;if(n>m){q=n;n=m;m=q;}if(n>v){v=n;C=u;}if(m<w){w=m;i=u;}if(v>w){return false;}if(w<0){return false;}}else{if(-B-l>0||-B+l<0){return false;}}}if(v>0){u=C;j=v;}else{u=i;j=w;}if(j<0){j=0;}if(j>1-d.NUM_TINY){return false;}x.fracOut=j;x.posOut=z.getPoint(j);if(g.dotProduct(o[u],z.delta)<0){x.normalOut=d.getScaleVector(o[u],-1);}else{x.normalOut=o[u];}return true;};a.prototype.getInertiaProperties=function(i){return b.getScaleMatrix((i/12)*(this._sideLengths[1]*this._sideLengths[1]+this._sideLengths[2]*this._sideLengths[2]),(i/12)*(this._sideLengths[0]*this._sideLengths[0]+this._sideLengths[2]*this._sideLengths[2]),(i/12)*(this._sideLengths[0]*this._sideLengths[0]+this._sideLengths[1]*this._sideLengths[1]));};a.prototype.updateBoundingBox=function(){this._boundingBox.clear();this._boundingBox.addBox(this);};c.JBox=a;})(jigLib);(function(c){var f=c.Vector3DUtil;var b=c.JMatrix3D;var d=c.JNumber3D;var g=c.RigidBody;var h=c.JSegment;var e=function(k,j,i){this.Super(k);this._type="CAPSULE";this._radius=j;this._length=i;this._boundingSphere=this.getBoundingSphere(j,i);this.set_mass(1);this.updateBoundingBox();};c.extend(e,c.RigidBody);e.prototype._length=null;e.prototype._radius=null;e.prototype.set_radius=function(i){this._radius=i;this._boundingSphere=getBoundingSphere(this._radius,this._length);this.setInertia(this.getInertiaProperties(this.get_mass()));this.updateBoundingBox();this.setActive();};e.prototype.get_radius=function(){return this._radius;};e.prototype.set_length=function(i){this._length=i;this._boundingSphere=getBoundingSphere(this._radius,this._length);this.setInertia(this.getInertiaProperties(this.get_mass()));this.updateBoundingBox();this.setActive();};e.prototype.get_length=function(){return this._length;};e.prototype.getBottomPos=function(j){var i=j.getOrientationCols()[1];return f.add(j.position,d.getScaleVector(i,-this._length/2-this._radius));};e.prototype.getEndPos=function(j){var i=j.getOrientationCols()[1];return f.add(j.position,d.getScaleVector(i,this._length/2+this._radius));};e.prototype.segmentIntersect=function(y,A,n){y.fracOut=0;y.posOut=[0,0,0,0];y.normalOut=[0,0,0,0];var j=A.delta;var C=f.dotProduct(j,j);var x=this._radius*this._radius;var u=n.getOrientationCols();var p=new h(getBottomPos(n),u[1]);var r=p.delta;var o=f.subtract(p.origin,A.origin);var s=f.dotProduct(r,r);if(Math.abs(s)<d.NUM_TINY){return false;}var k=f.dotProduct(r,j);var z=f.dotProduct(o,j);var q=f.dotProduct(r,o);var i=f.dotProduct(o,o);var m=f.get_lengthSquared(f.subtract(o,d.getDivideVector(d.getScaleVector(r,q),s)));if(m<x){y.fracOut=0;y.posOut=A.origin.slice(0);y.normalOut=f.subtract(y.posOut,getBottomPos(n));y.normalOut=f.subtract(y.normalOut,d.getScaleVector(u[1],f.dotProduct(y.normalOut,u[1])));f.normalize(y.normalOut);return true;}var w=s*C-(k*k);if(Math.abs(a)<d.NUM_TINY){return false;}var D=2*(q*k-s*z);var B=s*(i-x)-(q*q);var l=(D*D)-4*a*B;if(l<0){return false;}var v=(-D-Math.sqrt(l))/(2*a);if(v<0||v>1){return false;}y.fracOut=v;y.posOut=A.getPoint(v);y.normalOut=f.subtract(y.posOut,getBottomPos(n));y.normalOut=f.subtract(y.normalOut,d.getScaleVector(u[1],f.dotProduct(y.normalOut,u[1])));f.normalize(y.normalOut);return true;};e.prototype.getInertiaProperties=function(i){var l=i*Math.PI*this._radius*this._radius*this._length/this.getVolume();var j=0.25*l*this._radius*this._radius+(1/12)*l*this._length*this._length;var k=0.5*l*this._radius*this._radius;var n=j;var o=i-l;j+=(0.4*o*this._radius*this._radius+o*Math.pow(0.5*this._length,2));k+=(0.2*o*this._radius*this._radius);n+=(0.4*o*this._radius*this._radius+o*Math.pow(0.5*this._length,2));return b.getScaleMatrix(j,k,n);};e.prototype.updateBoundingBox=function(){this._boundingBox.clear();this._boundingBox.addCapsule(this);};e.prototype.getBoundingSphere=function(j,i){return Math.sqrt(Math.pow(i/2,2)+j*j)+j;};e.prototype.getVolume=function(){return(4/3)*Math.PI*this._radius*this._radius*this._radius+this._length*Math.PI*this._radius*this._radius;};c.JCapsule=e;})(jigLib);(function(c){var e=c.Vector3DUtil;var b=c.JMatrix3D;var d=c.JNumber3D;var f=c.RigidBody;var a=function(g,h){this.Super(g);if(h==undefined){this._initNormal=[0,0,-1,0];this._normal=this._initNormal.slice(0);}else{this._initNormal=h.slice(0);this._normal=this._initNormal.slice(0);}this._distance=0;this._type="PLANE";this._movable=false;};c.extend(a,c.RigidBody);a.prototype._initNormal=null;a.prototype._normal=null;a.prototype._distance=null;a.prototype.get_normal=function(){return this._normal;};a.prototype.get_distance=function(){return this._distance;};a.prototype.pointPlaneDistance=function(g){return e.dotProduct(this._normal,g)-this._distance;};a.prototype.segmentIntersect=function(j,g,l){j.fracOut=0;j.posOut=[0,0,0,0];j.normalOut=[0,0,0,0];var i=0;var k;var h=e.dotProduct(this._normal,g.delta);if(Math.abs(h)>d.NUM_TINY){k=-1*(e.dotProduct(this._normal,g.origin)-this._distance)/h;if(k<0||k>1){return false;}else{i=k;j.fracOut=i;j.posOut=g.getPoint(i);j.normalOut=this._normal.slice(0);e.normalize(j.normalOut);return true;}}else{return false;}};a.prototype.updateState=function(){this.Super.prototype.updateState.call(this);this._normal=this._initNormal.slice(0);b.multiplyVector(this._currState._orientation,this._normal);this._distance=e.dotProduct(this._currState.position,this._normal);};c.JPlane=a;})(jigLib);(function(a){var d=a.Vector3DUtil;var b=a.JNumber3D;var c=function(f,e){this.origin=f;this.dir=e;};c.prototype.origin=null;c.prototype.dir=null;c.prototype.getOrigin=function(e){return d.add(this.origin,b.getScaleVector(this.dir,e));};a.JRay=c;})(jigLib);(function(a){var d=a.Vector3DUtil;var b=a.JNumber3D;var c=a.JRay;var e=function(g,f){this.origin=g;this.delta=f;};e.prototype.origin=null;e.prototype.delta=null;e.prototype.getPoint=function(f){return d.add(this.origin,b.getScaleVector(this.delta,f));};e.prototype.getEnd=function(){return d.add(this.origin,this.delta);};e.prototype.clone=function(){return new e(this.origin,this.delta);};e.prototype.segmentSegmentDistanceSq=function(j,k){j.t0=0;j.t1=0;var r=d.subtract(this.origin,k.origin);var o=d.get_lengthSquared(this.delta);var n=-d.dotProduct(this.delta,k.delta);var i=d.get_lengthSquared(k.delta);var h=d.dotProduct(r,this.delta);var m=d.get_lengthSquared(r);var t=Math.abs(o*i-n*n);var g;var s;var q;var l;var p;if(t>=b.NUM_TINY){g=-d.dotProduct(r,k.delta);s=n*g-i*h;q=n*h-o*g;if(s>=0){if(s<=t){if(q>=0){if(q<=t){var f=1/t;s*=f;q*=f;l=s*(o*s+n*q+2*h)+q*(n*s+i*q+2*g)+m;}else{q=1;p=n+h;if(p>=0){s=0;l=i+2*g+m;}else{if(-p>=o){s=1;l=o+i+m+2*(g+p);}else{s=-p/o;l=p*s+i+2*g+m;}}}}else{q=0;if(h>=0){s=0;l=m;}else{if(-h>=o){s=1;l=o+2*h+m;}else{s=-h/o;l=h*s+m;}}}}else{if(q>=0){if(q<=t){s=1;p=n+g;if(p>=0){q=0;l=o+2*h+m;}else{if(-p>=i){q=1;l=o+i+m+2*(h+p);}else{q=-p/i;l=p*q+o+2*h+m;}}}else{p=n+h;if(-p<=o){q=1;if(p>=0){s=0;l=i+2*g+m;}else{s=-p/o;l=p*s+i+2*g+m;}}else{s=1;p=n+g;if(p>=0){q=0;l=o+2*h+m;}else{if(-p>=i){q=1;l=o+i+m+2*(h+p);}else{q=-p/i;l=p*q+o+2*h+m;}}}}}else{if(-h<o){q=0;if(h>=0){s=0;l=m;}else{s=-h/o;l=h*s+m;}}else{s=1;p=n+g;if(p>=0){q=0;l=o+2*h+m;}else{if(-p>=i){q=1;l=o+i+m+2*(h+p);}else{q=-p/i;l=p*q+o+2*h+m;}}}}}}else{if(q>=0){if(q<=t){s=0;if(g>=0){q=0;l=m;}else{if(-g>=i){q=1;l=i+2*g+m;}else{q=-g/i;l=g*q+m;}}}else{p=n+h;if(p<0){q=1;if(-p>=o){s=1;l=o+i+m+2*(g+p);}else{s=-p/o;l=p*s+i+2*g+m;}}else{s=0;if(g>=0){q=0;l=m;}else{if(-g>=i){q=1;l=i+2*g+m;}else{q=-g/i;l=g*q+m;}}}}}else{if(h<0){q=0;if(-h>=o){s=1;l=o+2*h+m;}else{s=-h/o;l=h*s+m;}}else{s=0;if(g>=0){q=0;l=m;}else{if(-g>=i){q=1;l=i+2*g+m;}else{q=-g/i;l=g*q+m;}}}}}}else{if(n>0){if(h>=0){s=0;q=0;l=m;}else{if(-h<=o){s=-h/o;q=0;l=h*s+m;}else{g=-d.dotProduct(r,k.delta);s=1;p=o+h;if(-p>=n){q=1;l=o+i+m+2*(n+h+g);}else{q=-p/n;l=o+2*h+m+q*(i*q+2*(n+g));}}}}else{if(-h>=o){s=1;q=0;l=o+2*h+m;}else{if(h<=0){s=-h/o;q=0;l=h*s+m;}else{g=-d.dotProduct(r,k.delta);s=0;if(h>=-n){q=1;l=i+2*g+m;}else{q=-h/n;l=m+q*(2*g+i*q);}}}}}j.t0=s;j.t1=q;return Math.abs(l);};e.prototype.pointSegmentDistanceSq=function(g,h){g.t=0;var j=d.subtract(h,this.origin);var i=d.dotProduct(j,this.delta);if(i<=0){i=0;}else{var f=d.get_lengthSquared(this._delta);if(i>=f){i=1;j=d.subtract(j,this._delta);}else{i/=f;j=d.subtract(j,b.getScaleVector(this._delta,i));}}g.t=i;return d.get_lengthSquared(j);};e.prototype.segmentBoxDistanceSq=function(g,f,k){g.pfLParam=0;g.pfLParam0=0;g.pfLParam1=0;g.pfLParam2=0;var j={};var i=new c(this.origin,this.delta);var h=this.sqrDistanceLine(j,i,f,k);if(j.num>=0){if(j.num<=1){g.pfLParam=j.num;g.pfLParam0=j.num0;g.pfLParam1=j.num1;g.pfLParam2=j.num2;return Math.max(h,0);}else{h=this.sqrDistancePoint(g,d.add(this.origin,this.delta),f,k);g.pfLParam=1;return Math.max(h,0);}}else{h=this.sqrDistancePoint(g,this.origin,f,k);g.pfLParam=0;return Math.max(h,0);}};e.prototype.sqrDistanceLine=function(l,s,q,o){var h=o.getOrientationCols();l.num=0;l.num0=0;l.num1=0;l.num2=0;var r=d.subtract(s.origin,o.position);var f=d.create(d.dotProduct(r,h[0]),d.dotProduct(r,h[1]),d.dotProduct(r,h[2]),0);var k=d.create(d.dotProduct(s.dir,h[0]),d.dotProduct(s.dir,h[1]),d.dotProduct(s.dir,h[2]),0);var j=f.slice(0);var p=k.slice(0);var g=[1,1,1,0];for(var n=0;n<3;n++){if(p[n]<0){j[n]=-j[n];p[n]=-p[n];g[n]=true;}else{g[n]=false;}}b.copyFromArray(f,j);b.copyFromArray(k,p);var m={};m.rkPnt=f.slice(0);m.pfLParam=0;m.rfSqrDistance=0;if(k[0]>0){if(k[1]>0){if(k[2]>0){this.caseNoZeros(m,k,q);l.num=m.pfLParam;}else{this.case0(m,0,1,2,k,q);l.num=m.pfLParam;}}else{if(k[2]>0){this.case0(m,0,2,1,k,q);l.num=m.pfLParam;}else{this.case00(m,0,1,2,k,q);l.num=m.pfLParam;}}}else{if(k[1]>0){if(k[2]>0){this.case0(m,1,2,0,k,q);l.num=m.pfLParam;}else{this.case00(m,1,0,2,k,q);l.num=m.pfLParam;}}else{if(k[2]>0){this.case00(m,2,0,1,k,q);l.num=m.pfLParam;}else{this.case000(m,q);l.num=0;}}}j=m.rkPnt.slice(0);for(n=0;n<3;n++){if(g[n]){j[n]=-j[n];}}b.copyFromArray(m.rkPnt,j);l.num0=m.rkPnt[0];l.num1=m.rkPnt[1];l.num2=m.rkPnt[2];return Math.max(m.rfSqrDistance,0);};e.prototype.sqrDistancePoint=function(h,g,k,i){var m=i.getOrientationCols();var n=d.subtract(g,i.position);var j=d.create(d.dotProduct(n,m[0]),d.dotProduct(n,m[1]),d.dotProduct(n,m[2]),0);var f=0;var o;var l=k.getHalfSideLengths();if(j[0]<-l[0]){o=j[0]+l[0];f+=(o*o);j[0]=-l[0];}else{if(j[0]>l[0]){o=j[0]-l[0];f+=(o*o);j[0]=l[0];}}if(j[1]<-l[1]){o=j[1]+l[1];f+=(o*o);j[1]=-l[1];}else{if(j[1]>l[1]){o=j[1]-l[1];f+=(o*o);j[1]=l[1];}}if(j[2]<-l[2]){o=j[2]+l[2];f+=(o*o);j[2]=-l[2];}else{if(j[2]>l[2]){o=j[2]-l[2];f+=(o*o);j[2]=l[2];}}h.pfLParam0=j[0];h.pfLParam1=j[1];h.pfLParam2=j[2];return Math.max(f,0);};e.prototype.face=function(w,t,s,r,j,f,h){var x=[0,0,0,0];var k;var o;var m;var g;var y;var q;var v=f.getHalfSideLengths();var u=v;var i=w.rkPnt;var l=j;var n=x;var p=h;n[s]=i[s]+u[s];n[r]=i[r]+u[r];b.copyFromArray(h,n);if(l[t]*n[s]>=l[s]*p[t]){if(l[t]*n[r]>=l[r]*p[t]){i[t]=u[t];o=1/l[t];i[s]-=(l[s]*p[t]*o);i[r]-=(l[r]*p[t]*o);w.pfLParam=-p[t]*o;b.copyFromArray(w.rkPnt,i);}else{k=l[t]*l[t]+l[r]*l[r];m=k*n[s]-l[s]*(l[t]*p[t]+l[r]*n[r]);if(m<=2*k*u[s]){y=m/k;k+=(l[s]*l[s]);m=n[s]-y;q=l[t]*p[t]+l[s]*m+l[r]*n[r];g=-q/k;w.rfSqrDistance+=(p[t]*p[t]+m*m+n[r]*n[r]+q*g);w.pfLParam=g;i[t]=u[t];i[s]=y-u[s];i[r]=-u[r];b.copyFromArray(w.rkPnt,i);}else{k+=(l[s]*l[s]);q=l[t]*p[t]+l[s]*p[s]+l[r]*n[r];g=-q/k;w.rfSqrDistance+=(p[t]*p[t]+p[s]*p[s]+n[r]*n[r]+q*g);w.pfLParam=g;i[t]=u[t];i[s]=u[s];i[r]=-u[r];b.copyFromArray(w.rkPnt,i);}}}else{if(l[t]*n[r]>=l[r]*p[t]){k=l[t]*l[t]+l[s]*l[s];m=k*n[r]-l[r]*(l[t]*p[t]+l[s]*n[s]);if(m<=2*k*u[r]){y=m/k;k+=(l[r]*l[r]);m=n[r]-y;q=l[t]*p[t]+l[s]*n[s]+l[r]*m;g=-q/k;w.rfSqrDistance+=(p[t]*p[t]+n[s]*n[s]+m*m+q*g);w.pfLParam=g;i[t]=u[t];i[s]=-u[s];i[r]=y-u[r];b.copyFromArray(w.rkPnt,i);}else{k+=(l[r]*l[r]);q=l[t]*p[t]+l[s]*n[s]+l[r]*p[r];g=-q/k;w.rfSqrDistance+=(p[t]*p[t]+n[s]*n[s]+p[r]*p[r]+q*g);w.pfLParam=g;i[t]=u[t];i[s]=-u[s];i[r]=u[r];b.copyFromArray(w.rkPnt,i);}}else{k=l[t]*l[t]+l[r]*l[r];m=k*n[s]-l[s]*(l[t]*p[t]+l[r]*n[r]);if(m>=0){if(m<=2*k*u[s]){y=m/k;k+=(l[s]*l[s]);m=n[s]-y;q=l[t]*p[t]+l[s]*m+l[r]*n[r];g=-q/k;w.rfSqrDistance+=(p[t]*p[t]+m*m+n[r]*n[r]+q*g);w.pfLParam=g;i[t]=u[t];i[s]=y-u[s];i[r]=-u[r];b.copyFromArray(w.rkPnt,i);}else{k+=(l[s]*l[s]);q=l[t]*p[t]+l[s]*p[s]+l[r]*n[r];g=-q/k;w.rfSqrDistance+=(p[t]*p[t]+p[s]*p[s]+n[r]*n[r]+q*g);w.pfLParam=g;i[t]=u[t];i[s]=u[s];i[r]=-u[r];b.copyFromArray(w.rkPnt,i);}return;}k=l[t]*l[t]+l[s]*l[s];m=k*n[r]-l[r]*(l[t]*p[t]+l[s]*n[s]);if(m>=0){if(m<=2*k*u[r]){y=m/k;k+=(l[r]*l[r]);m=n[r]-y;q=l[t]*p[t]+l[s]*n[s]+l[r]*m;g=-q/k;w.rfSqrDistance+=(p[t]*p[t]+n[s]*n[s]+m*m+q*g);w.pfLParam=g;i[t]=u[t];i[s]=-u[s];i[r]=y-u[r];b.copyFromArray(w.rkPnt,i);}else{k+=(l[r]*l[r]);q=l[t]*p[t]+l[s]*n[s]+l[r]*p[r];g=-q/k;w.rfSqrDistance+=(p[t]*p[t]+n[s]*n[s]+p[r]*p[r]+q*g);w.pfLParam=g;i[t]=u[t];i[s]=-u[s];i[r]=u[r];b.copyFromArray(w.rkPnt,i);}return;}k+=(l[r]*l[r]);q=l[t]*p[t]+l[s]*n[s]+l[r]*n[r];g=-q/k;w.rfSqrDistance+=(p[t]*p[t]+n[s]*n[s]+n[r]*n[r]+q*g);w.pfLParam=g;i[t]=u[t];i[s]=-u[s];i[r]=-u[r];b.copyFromArray(w.rkPnt,i);}}};e.prototype.caseNoZeros=function(i,k,o){var p=o.getHalfSideLengths();var l=d.create(i.rkPnt[0]-p[0],i.rkPnt[1]-p[1],i.rkPnt[2]-p[2],0);var g=k[0]*l[1];var j=k[1]*l[0];var n;var f;var m;var h;if(j>=g){n=k[2]*l[0];f=k[0]*l[2];if(n>=f){this.face(i,0,1,2,k,o,l);}else{this.face(i,2,0,1,k,o,l);}}else{m=k[2]*l[1];h=k[1]*l[2];if(m>=h){this.face(i,1,2,0,k,o,l);}else{this.face(i,2,0,1,k,o,l);}}};e.prototype.case0=function(x,u,t,s,i,f){var w=f.getHalfSideLengths();var v=w.slice(0);var h=x.rkPnt.slice(0);var m=i.slice(0);var q=h[u]-v[u];var p=h[t]-v[t];var j=m[t]*q;var g=m[u]*p;var r;var n;var o;if(j>=g){h[u]=v[u];var k=h[t]+v[t];r=j-m[u]*k;if(r>=0){n=1/(m[u]*m[u]+m[t]*m[t]);x.rfSqrDistance+=(r*r*n);h[t]=-v[t];x.pfLParam=-(m[u]*q+m[t]*k)*n;}else{o=1/m[u];h[t]-=(j*o);x.pfLParam=-q*o;}b.copyFromArray(x.rkPnt,h);}else{h[t]=v[t];var l=h[u]+v[u];r=g-m[t]*l;if(r>=0){n=1/(m[u]*m[u]+m[t]*m[t]);x.rfSqrDistance+=(r*r*n);h[u]=-v[u];x.pfLParam=-(m[u]*l+m[t]*p)*n;}else{o=1/m[t];h[u]-=(g*o);x.pfLParam=-p*o;}b.copyFromArray(x.rkPnt,h);}if(h[s]<-v[s]){r=h[s]+v[s];x.rfSqrDistance+=(r*r);h[s]=-v[s];}else{if(h[s]>v[s]){r=h[s]-v[s];x.rfSqrDistance+=(r*r);h[s]=v[s];}}b.copyFromArray(x.rkPnt,h);};e.prototype.case00=function(j,i,h,g,k,m){var o=0;var n=m.getHalfSideLengths();var f=n.slice(0);var l=j.rkPnt.slice(0);var p=k.slice(0);j.pfLParam=(f[i]-l[i])/p[i];l[i]=f[i];if(l[h]<-f[h]){o=l[h]+f[h];j.rfSqrDistance+=(o*o);l[h]=-f[h];}else{if(l[h]>f[h]){o=l[h]-f[h];j.rfSqrDistance+=(o*o);l[h]=f[h];}}if(l[g]<-f[g]){o=l[g]+f[g];j.rfSqrDistance+=(o*o);l[g]=-f[g];}else{if(l[g]>f[g]){o=l[g]-f[g];j.rfSqrDistance+=(o*o);l[g]=f[g];}}b.copyFromArray(j.rkPnt,l);};e.prototype.case000=function(g,f){var h=0;var i=f.getHalfSideLengths();if(g.rkPnt[0]<-i[0]){h=g.rkPnt[0]+i[0];g.rfSqrDistance+=(h*h);g.rkPnt[0]=-i[0];}else{if(g.rkPnt[0]>i[0]){h=g.rkPnt[0]-i[0];g.rfSqrDistance+=(h*h);g.rkPnt[0]=i[0];}}if(g.rkPnt[1]<-i[1]){h=g.rkPnt[1]+i[1];g.rfSqrDistance+=(h*h);g.rkPnt[1]=-i[1];}else{if(g.rkPnt[1]>i[1]){h=g.rkPnt[1]-i[1];g.rfSqrDistance+=(h*h);g.rkPnt[1]=i[1];}}if(g.rkPnt[2]<-i[2]){h=g.rkPnt[2]+i[2];g.rfSqrDistance+=(h*h);g.rkPnt[2]=-i[2];}else{if(g.rkPnt[2]>i[2]){h=g.rkPnt[2]-i[2];g.rfSqrDistance+=(h*h);g.rkPnt[2]=i[2];}}};a.JSegment=e;})(jigLib);(function(c){var d=c.Vector3DUtil;var b=c.JMatrix3D;var e=c.RigidBody;var a=function(g,f){this.Super(g);this._type="SPHERE";this._radius=f;this._boundingSphere=this._radius;this.set_mass(1);this.updateBoundingBox();};c.extend(a,c.RigidBody);a.prototype.name=null;a.prototype._radius=null;a.prototype.set_radius=function(f){this._radius=f;this._boundingSphere=this._radius;this.setInertia(this.getInertiaProperties(this.get_mass()));this.setActive();this.updateBoundingBox();};a.prototype.get_radius=function(){return this._radius;};a.prototype.segmentIntersect=function(m,n,i){m.fracOut=0;m.posOut=[0,0,0,0];m.normalOut=[0,0,0,0];var j=0;var g=n.delta;var t=d.subtract(n.origin,i.position);var l=this._radius*this._radius;var u=d.get_lengthSquared(g);if(u<l){m.fracOut=0;m.posOut=n.origin.slice(0);m.normalOut=d.subtract(m.posOut,i.position);d.normalize(m.normalOut);return true;}var h=d.dotProduct(t,g);var k=d.get_lengthSquared(t);var o=h*h-u*(k-l);if(o<0){return false;}var q=Math.sqrt(o);var f=(-h-q)/u;var p=(-h+q)/u;if(f>1||p<0){return false;}j=Math.max(f,0);m.fracOut=j;m.posOut=n.getPoint(j);m.normalOut=d.subtract(m.posOut,i.position);d.normalize(m.normalOut);return true;};a.prototype.getInertiaProperties=function(f){var g=0.4*f*this._radius*this._radius;return b.getScaleMatrix(g,g,g);};a.prototype.updateBoundingBox=function(){this._boundingBox.clear();this._boundingBox.addSphere(this);};c.JSphere=a;})(jigLib);(function(a){var c=a.Vector3DUtil;var b=a.JNumber3D;var d=a.RigidBody;var e=function(f){this.Super(null);this._terrain=f;this.set_movable(false);this._type="TERRAIN";};a.extend(e,a.RigidBody);e.prototype._terrain=null;e.prototype.get_terrainMesh=function(){return this._terrain;};e.prototype.getHeightByIndex=function(g,f){g=this.limiteInt(g,0,_terrain.sw);f=this.limiteInt(f,0,_terrain.sh);return _terrain.heights[g][f];};e.prototype.getHeightAndNormalByPoint=function(t){var s=this.limiteInt(t[0],this._terrain.minW,this._terrain.maxW);var o=this.limiteInt(t[2],this._terrain.minH,this._terrain.maxH);var k=((s-_terrain.minW)/this._terrain.dw)|0;var f=((o-_terrain.minH)/this._terrain.dh)|0;k=this.limiteInt(k,0,this._terrain.sw);f=this.limiteInt(f,0,this._terrain.sh);var i=k+1;var u=f+1;i=this.limiteInt(i,0,this._terrain.sw);u=this.limiteInt(u,0,this._terrain.sh);var j=1-(s-(k*this._terrain.dw+this._terrain.minW))/this._terrain.dw;var g=(o-(f*this._terrain.dh+this._terrain.minH))/this._terrain.dh;j=b.getLimiteNumber(j,0,1);g=b.getLimiteNumber(g,0,1);var r=this._terrain.heights[k][f];var q=this._terrain.heights[k][u];var n=this._terrain.heights[i][f];var m=this._terrain.heights[i][u];var l={};l.height=0;l.normal=[0,0,0,0];var p;if(j<g||k==i||f==u){l.normal=c.crossProduct([0,m-n,this._terrain.dh,0],[this._terrain.dw,m-q,0,0]);c.normalize(l.normal);p=new PlaneData([(i*this._terrain.dw+this._terrain.minW),m,(u*this._terrain.dh+this._terrain.minH),0],l.normal);l.height=p.pointPlaneDistance(t);}else{l.normal=c.crossProduct([0,q-r,this._terrain.dh,0],[this._terrain.dw,n-r,0,0]);c.normalize(l.normal);p=new PlaneData([(k*this._terrain.dw+this._terrain.minW),r,(f*this._terrain.dh+this._terrain.minH),0],l.normal);l.height=p.pointPlaneDistance(t);}return l;};e.prototype.getHeightByPoint=function(f){return this.getHeightAndNormalByPoint(f).height;};e.prototype.getNormalByPoint=function(f){return this.getHeightAndNormalByPoint(f).normal;};e.prototype.getSurfacePosByPoint=function(f){return[f[0],this.getHeightAndNormalByPoint(f).height,f[2],0];};e.prototype.segmentIntersect=function(i,f,j){i.fracOut=0;i.posOut=[0,0,0,0];i.normalOut=[0,0,0,0];if(f.delta[1]>-b.NUM_TINY){return false;}var m=this.getHeightAndNormalByPoint(f.origin);if(m.height<0){return false;}var l=getHeightAndNormalByPoint(f.getEnd());if(l.height>0){return false;}var h=-l.height;var g=1/(b.NUM_TINY+m.height);var k=1/(b.NUM_TINY+l.height);c.scaleBy(m.normal,g);c.scaleBy(l.normal,k);i.normalOut=c.add(m.normal,l.normal);c.scaleBy(i.normalOut,1/(g+k));i.fracOut=m.height/(m.height+h+b.NUM_TINY);i.posOut=f.getPoint(i.fracOut);return true;};e.prototype.limiteInt=function(g,h,f){var i=g;if(i<h){i=h;}else{if(i>f){i=f;}}return i;};a.JTerrain=e;})(jigLib);(function(a){var b=function(){this.accumulatedFrictionImpulse=[0,0,0,0];};b.prototype.initialPenetration=null;b.prototype.r0;b.prototype.r1;b.prototype.position;b.prototype.minSeparationVel=0;b.prototype.denominator=0;b.prototype.accumulatedNormalImpulse=0;b.prototype.accumulatedNormalImpulseAux=0;b.prototype.accumulatedFrictionImpulse=null;a.CollPointInfo=b;})(jigLib);(function(a){var c=a.MaterialProperties;var b=function(){this.mat=new c();this.pointInfo=[];};b.prototype.mat=null;b.prototype.objInfo=null;b.prototype.dirToBody=null;b.prototype.pointInfo=null;b.prototype.satisfied=null;a.CollisionInfo=b;})(jigLib);(function(a){var b=function(){};b.prototype.body0=null;b.prototype.body1=null;a.CollDetectInfo=b;})(jigLib);(function(a){var b=function(){};b.prototype.name=null;b.prototype.type0=null;b.prototype.type1=null;b.prototype.collDetect=function(d,c){};a.CollDetectFunctor=b;})(jigLib);(function(d){var m=d.Vector3DUtil;var b=d.JNumber3D;var f=d.JMatrix3D;var i=d.JConstraint;var o=d.JSegment;var g=d.JConfig;var h=d.JSphere;var c=d.MaterialProperties;var a=d.PhysicsState;var e=d.EdgeData;var j=d.SpanData;var k=d.CollPointInfo;var n=d.CollisionInfo;var l=function(){this.name="BoxBox";this.type0="BOX";this.type1="BOX";};d.extend(l,d.CollDetectFunctor);l.prototype.combinationDist=null;l.prototype.disjoint=function(u,r,x,w){var t=x.getSpan(r);var s=w.getSpan(r);var p=t.min;var v=t.max;var y=s.min;var q=s.max;var z=Math.min;if(p>(q+g.collToll+b.NUM_TINY)||y>(v+g.collToll+b.NUM_TINY)){u.flag=true;return true;}if((v>q)&&(y>p)){u.depth=z(v-y,q-p);}else{if((q>v)&&(p>y)){u.depth=z(q-p,v-y);}else{u.depth=(v<q)?v:q;u.depth-=(p>y)?p:y;}}u.flag=false;return false;};l.prototype.addPoint=function(t,s,p){for(var r=0,q=t.length;r<q;r++){var u=t[r];if(m.get_lengthSquared(m.subtract(u,s))<p){u=b.getDivideVector(m.add(u,s),2);return false;}}t.push(s);return true;};l.prototype.getSupportPoint=function(v,t){var r=v.get_currentState().getOrientationCols();var u=m.dotProduct(t,r[0]);var q=m.dotProduct(t,r[1]);var x=m.dotProduct(t,r[2]);var w=v.get_currentState().position.slice(0);var s=v.get_sideLengths();if(u<-b.NUM_TINY){w=m.add(w,b.getScaleVector(r[0],0.5*s[0]));}else{if(u>=b.NUM_TINY){w=m.subtract(w,b.getScaleVector(r[0],0.5*s[0]));}}if(q<-b.NUM_TINY){w=m.add(w,b.getScaleVector(r[1],0.5*s[1]));}else{if(q>b.NUM_TINY){w=m.subtract(w,b.getScaleVector(r[1],0.5*s[1]));}}if(x<-b.NUM_TINY){w=m.add(w,b.getScaleVector(r[2],0.5*s[2]));}else{if(x>b.NUM_TINY){w=m.subtract(w,b.getScaleVector(r[2],0.5*s[2]));}}return w;};l.prototype.getAABox2EdgeIntersectionPoints=function(t,x,H,J,I){var E;var G;var w;var u;var p;var s=0;var C;var q=m.subtract(I,J);m.normalize(q);var F=[];var r=[];var y=J;var D=I;var A=q;var B=b.getScaleVector(x,0.5);for(var z=2;z>=0;z--){if(Math.abs(A[z])<0.1){continue;}E=(z+1)%3;G=(z+2)%3;r=[-B[z],B[z]];for(var v=1;v>=0;v--){w=y[z]-r[v];u=D[z]-r[v];p=-1;if(w*u<-b.NUM_TINY){p=-w/(u-w);}else{if(Math.abs(w)<b.NUM_TINY){p=0;}else{if(Math.abs(u)<b.NUM_TINY){p=1;}}}if(p>=0){C=m.add(b.getScaleVector(J,1-p),b.getScaleVector(I,p));F=C;if((F[E]>-B[E]-b.NUM_TINY)&&(F[E]<B[E]+b.NUM_TINY)&&(F[G]>-B[G]-b.NUM_TINY)&&(F[G]<B[G]+b.NUM_TINY)){C=C.splice(0);f.multiplyVector(H.get_orientation(),C);C=m.add(C,H.position);this.addPoint(t,C,combinationDist);if(++s==2){return s;}}}}}return s;};l.prototype.getBox2BoxEdgesIntersectionPoints=function(x,B,z,t){var y=0;var u;var C=(t)?B.get_currentState():B.get_oldState();var s=(t)?z.get_currentState():z.get_oldState();var q=z.getCornerPointsInBoxSpace(s,C);var A=z.get_edges();var r;var p;for(var w=0;w<A.length;w++){var v=A[w];r=q[v.ind0];p=q[v.ind1];y+=this.getAABox2EdgeIntersectionPoints(x,B.get_sideLengths(),C,r,p);if(y>=8){return y;}}return y;};l.prototype.getBoxBoxIntersectionPoints=function(s,q,p,r){this.getBox2BoxEdgesIntersectionPoints(s,q,p,r);this.getBox2BoxEdgesIntersectionPoints(s,p,q,r);return m.get_length(s);};l.prototype.collDetect=function(ac,D){var R=ac.body0;var P=ac.body1;if(!R.hitTestObject3D(P)){return;}if(g.aabbDetection&&!R.get_boundingBox().overlapTest(P.get_boundingBox())){return;}var aj=b.NUM_TINY;var v=b.NUM_HUGE;var z=R.get_currentState().getOrientationCols();var M=P.get_currentState().getOrientationCols();var U=[z[0],z[1],z[2],M[0],M[1],M[2],m.crossProduct(z[0],M[0]),m.crossProduct(z[1],M[0]),m.crossProduct(z[2],M[0]),m.crossProduct(z[0],M[1]),m.crossProduct(z[1],M[1]),m.crossProduct(z[2],M[1]),m.crossProduct(z[0],M[2]),m.crossProduct(z[1],M[2]),m.crossProduct(z[2],M[2])];var y;var ab=[];var Z=0;var A=U.length;for(Z=0;Z<A;Z++){var ad=ab[Z]=new j();ad.depth=v;y=m.get_lengthSquared(U[Z]);if(y<aj){continue;}var q=U[Z].slice(0);m.normalize(q);if(this.disjoint(ab[Z],q,R,P)){return;}}var I=v;var O=-1;A=U.length;for(Z=0;Z<A;Z++){y=m.get_lengthSquared(U[Z]);if(y<aj){continue;}if(ab[Z].depth<I){I=ab[Z].depth;O=Z;}}if(O==-1){return;}var w=U[O].splice(0);if(m.dotProduct(m.subtract(P.get_currentState().position,R.get_currentState().position),w)>0){w=b.getScaleVector(w,-1);}var ag=true;var aa=[];var S=R.get_sideLengths();var X=P.get_sideLengths();combinationDist=0.05*Math.min(Math.min(S[0],S[1],S[2]),Math.min(X[0],X[1],X[2]));combinationDist+=(g.collToll*3.464);combinationDist*=combinationDist;if(I>-b.NUM_TINY){this.getBoxBoxIntersectionPoints(aa,R,P,false);}if(aa.length==0){ag=false;this.getBoxBoxIntersectionPoints(aa,R,P,true);}var K=m.subtract(m.subtract(R.get_currentState().position,R.get_oldState().position),m.subtract(P.get_currentState().position,P.get_oldState().position));var p=m.dotProduct(K,w);var J=I+p;var F=[];switch(O){case 0:case 1:case 2:F=this.getSupportPoint(P,b.getScaleVector(w,-1));break;case 3:case 4:case 5:F=this.getSupportPoint(R,w);break;case 6:case 7:case 8:case 9:case 10:case 11:case 12:case 13:case 14:Z=O-6;var T=(Z/3)|0;var Q=Z-T*3;var E=this.getSupportPoint(R,w);var C=this.getSupportPoint(P,b.getScaleVector(w,-1));var V=m.crossProduct(w,M[Q]);var L=m.dotProduct(V,C);var ae=m.dotProduct(z[T],V);if(Math.abs(ae)<b.NUM_TINY){return;}var W=(L-m.dotProduct(E,V))/ae;E=m.add(E,b.getScaleVector(z[T],W));F=m.add(E,b.getScaleVector(w,0.5*I));break;}var ai;if(aa.length>0){ai=[];var B=b.NUM_HUGE;var H=-b.NUM_HUGE;var r;var u;var af;var x;var s;for(var Y=0;Y<aa.length;Y++){s=aa[Y];r=m.get_length(m.subtract(s,F));if(r<B){B=r;}if(r>H){H=r;}}if(H<B+b.NUM_TINY){H=B+b.NUM_TINY;}Z=0;for(var Y=0;Y<aa.length;Y++){s=aa[Y];r=m.get_length(m.subtract(s,F));af=(r-B)/(H-B);u=(1-af)*J;x=new k();if(ag){x.r0=m.subtract(s,R.get_oldState().position);x.r1=m.subtract(s,P.get_oldState().position);}else{x.r0=m.subtract(s,R.get_currentState().position);x.r1=m.subtract(s,P.get_currentState().position);}x.initialPenetration=u;ai[Z++]=x;}}else{x=new k();x.r0=m.subtract(F,R.get_currentState().position);x.r1=m.subtract(F,P.get_currentState().position);x.initialPenetration=J;ai=[];ai[0]=x;}var ah=new n();ah.objInfo=ac;ah.dirToBody=w;ah.pointInfo=ai;var G=new c();G.set_restitution(Math.sqrt(R.get_material().get_restitution()*P.get_material().get_restitution()));G.set_friction(Math.sqrt(R.get_material().get_friction()*P.get_material().get_friction()));ah.mat=G;D.push(ah);ac.body0.collisions.push(ah);ac.body1.collisions.push(ah);};d.CollDetectBoxBox=l;})(jigLib);(function(e){var i=e.Vector3DUtil;var a=e.JNumber3D;var g=e.JConstraint;var f=e.JConfig;var b=e.JPlane;var k=e.JSegment;var d=e.JBox;var c=e.MaterialProperties;var l=e.RigidBody;var h=e.CollPointInfo;var j=e.CollisionInfo;var m=function(){this.name="BoxPlane";this.type0="BOX";this.type1="PLANE";};e.extend(m,e.CollDetectFunctor);m.prototype.collDetect=function(q,A){var v;if(q.body0.get_type()=="PLANE"){v=q.body0;q.body0=q.body1;q.body1=v;}var t=q.body0;var u=q.body1;var B=u.pointPlaneDistance(t.get_currentState().position);if(B>t.get_boundingSphere()+f.collToll){return;}var D=t.getCornerPoints(t.get_currentState());var w=t.getCornerPoints(t.get_oldState());var r=[];var p;var o;var n;var z;var x;for(var s=0;s<8;s++){o=D[s];n=w[s];z=-1*u.pointPlaneDistance(o);x=-1*u.pointPlaneDistance(n);if(Math.max(z,x)>-f.collToll){p=new h();p.r0=i.subtract(n,t.get_oldState().position);p.r1=i.subtract(n,u.get_oldState().position);p.initialPenetration=x;r.push(p);}}if(r.length>0){var y=new j();y.objInfo=q;y.dirToBody=u.get_normal();y.pointInfo=r;var C=new c();C.set_restitution(Math.sqrt(t.get_material().get_restitution()*u.get_material().get_restitution()));C.set_friction(Math.sqrt(t.get_material().get_friction()*u.get_material().get_friction()));y.mat=C;A.push(y);q.body0.collisions.push(y);q.body1.collisions.push(y);}};e.CollDetectBoxPlane=m;})(jigLib);(function(e){var i=e.Vector3DUtil;var a=e.JNumber3D;var h=e.JConstraint;var g=e.JConfig;var f=e.JTerrain;var d=e.JBox;var c=e.MaterialProperties;var j=e.RigidBody;var b=function(){this.name="BoxTerrain";this.type0="BOX";this.type1="TERRAIN";};e.extend(b,e.CollDetectFunctor);b.prototype.collDetect=function(o,y){var t;if(o.body0.type=="TERRAIN"){t=o.body0;o.body0=o.body1;o.body1=t;}var s=o.body0;var m=o.body1;var v=s.getCornerPoints(s.oldState);var A=s.getCornerPoints(s.currentState);var u=[0,0,0,0];var r;var x;var l;var k;var p=[];var n;for(var q=0;q<8;q++){l=A[q];r=m.getHeightAndNormalByPoint(l);if(r.height<g.collToll){k=v[q];x=m.getHeightByPoint(k);u=i.add(u,r.normal);n=new CollPointInfo();n.r0=i.subtract(k,s.oldState.position);n.r1=i.subtract(k,m.oldState.position);n.initialPenetration=-x;p.push(n);}}if(p.length>0){i.normalize(u);var w=new CollisionInfo();w.objInfo=o;w.dirToBody=u;w.pointInfo=p;var z=new c();z.restitution=Math.sqrt(s.material.restitution*m.material.restitution);z.friction=Math.sqrt(s.material.friction*m.material.friction);w.mat=z;y.push(w);o.body0.collisions.push(w);o.body1.collisions.push(w);}};e.CollDetectBoxTerrain=b;})(jigLib);(function(e){var k=e.Vector3DUtil;var f=e.JMatrix3D;var a=e.JNumber3D;var h=e.JConstraint;var g=e.JConfig;var i=e.JCapsule;var m=e.JSegment;var d=e.JBox;var b=e.MaterialProperties;var n=e.RigidBody;var j=e.CollPointInfo;var l=e.CollisionInfo;var c=function(){this.name="CapsuleBox";this.type0="CAPSULE";this.type1="BOX";};e.extend(c,e.CollDetectFunctor);c.prototype.collDetect=function(G,E){var y;if(G.body0.get_type()=="BOX"){y=G.body0;G.body0=G.body1;G.body1=y;}var x=G.body0;var w=G.body1;if(!x.hitTestObject3D(w)){return;}if(g.aabbDetection&&!x.get_boundingBox().overlapTest(w.get_boundingBox())){return;}var D=[];var t;var o=[0,0,0,0];var r=new m(x.getEndPos(x.get_oldState()),a.getScaleVector(x.get_oldState().getOrientationCols()[1],-k.get_length(x)));var A=new m(x.getEndPos(x.get_currentState()),a.getScaleVector(x.get_currentState().getOrientationCols()[1],-k.get_length(x)));var q=x.get_radius();var J={};var I=r.segmentBoxDistanceSq(J,w,w.get_oldState());var u={};var s=A.segmentBoxDistanceSq(u,w,w.get_currentState());var p=w.get_oldState().getOrientationCols();if(Math.min(I,s)<Math.pow(q+g.collToll,2)){var v=r.getPoint(Number(J.pfLParam));var H=w.get_oldState().position.slice(0);H=k.add(H,a.getScaleVector(p[0],J.pfLParam0));H=k.add(H,a.getScaleVector(p[1],J.pfLParam1));H=k.add(H,a.getScaleVector(p[2],J.pfLParam2));var B=Math.sqrt(I);var K=q-B;var z;if(B>a.NUM_TINY){z=k.subtract(v,H);k.normalize(z);}else{if(k.get_length(k.subtract(v,w.get_oldState().position))>a.NUM_TINY){z=k.subtract(v,w.get_oldState().position);k.normalize(z);}else{z=k.Y_AXIS;f.multiplyVector(f.getRotationMatrix(0,0,1,360*Math.random()),z);}}o=k.add(o,z);t=new j();t.r0=k.subtract(H,x.get_oldState().position);t.r1=k.subtract(H,w.get_oldState().position);t.initialPenetration=K;D.push(t);}r=new m(x.getBottomPos(x.get_oldState()),a.getScaleVector(x.get_oldState().getOrientationCols()[1],k.get_length(x)));A=new m(x.getBottomPos(x.get_currentState()),a.getScaleVector(x.get_currentState().getOrientationCols()[1],k.get_length(x)));J={};I=r.segmentBoxDistanceSq(J,w,w.get_oldState());u={};s=A.segmentBoxDistanceSq(u,w,w.get_currentState());if(Math.min(I,s)<Math.pow(q+g.collToll,2)){v=r.getPoint(Number(J.pfLParam));H=w.get_oldState().position.slice(0);H=k.add(H,a.getScaleVector(p[0],J.pfLParam0));H=k.add(H,a.getScaleVector(p[1],J.pfLParam1));H=k.add(H,a.getScaleVector(p[2],J.pfLParam2));B=Math.sqrt(I);K=q-B;if(B>a.NUM_TINY){z=k.subtract(v,H);k.normalize(z);}else{if(k.get_length(k.subtract(v,w.get_oldState().position))>a.NUM_TINY){z=k.subtract(v,w.get_oldState().position);k.normalize(z);}else{z=k.Y_AXIS;f.multiplyVector(f.getRotationMatrix(0,0,1,360*Math.random()),z);}}o=k.add(o,z);t=new j();t.r0=k.subtract(H,x.get_oldState().position);t.r1=k.subtract(H,w.get_oldState().position);t.initialPenetration=K;D.push(t);}if(D.length>0){o.normalize();var C=new l();C.objInfo=G;C.dirToBody=o;C.pointInfo=D;var F=new b();F.set_restitution(Math.sqrt(x.get_material().get_restitution()*w.get_material().get_restitution()));F.set_friction(Math.sqrt(x.get_material().get_friction()*w.get_material().get_friction()));C.mat=F;E.push(C);G.body0.collisions.push(C);G.body1.collisions.push(C);}};e.CollDetectCapsuleBox=c;})(jigLib);(function(d){var j=d.Vector3DUtil;var e=d.JMatrix3D;var a=d.JNumber3D;var g=d.JConstraint;var f=d.JConfig;var h=d.JCapsule;var l=d.JSegment;var c=d.MaterialProperties;var m=d.RigidBody;var i=d.CollPointInfo;var k=d.CollisionInfo;var b=function(){this.name="CapsuleCapsule";this.type0="CAPSULE";this.type1="CAPSULE";};d.extend(b,d.CollDetectFunctor);b.prototype.collDetect=function(E,C){var H=E.body0;var G=E.body1;if(!H.hitTestObject3D(G)){return;}if(f.aabbDetection&&!H.get_boundingBox().overlapTest(G.get_boundingBox())){return;}var B=[];var u;var n=[0,0,0,0];var p=new l(H.getEndPos(H.get_oldState()),a.getScaleVector(H.get_oldState().getOrientationCols()[1],-j.get_length(H)));var y=new l(H.getEndPos(H.get_currentState()),a.getScaleVector(H.get_currentState().getOrientationCols()[1],-j.get_length(H)));var o=new l(G.getEndPos(G.get_oldState()),a.getScaleVector(G.get_oldState().getOrientationCols()[1],-j.get_length(G)));var x=new l(G.getEndPos(G.get_currentState()),a.getScaleVector(G.get_currentState().getOrientationCols()[1],-j.get_length(G)));var q=H.get_radius()+G.get_radius();var J={};var I=p.segmentSegmentDistanceSq(J,o);var v={};var t=y.segmentSegmentDistanceSq(J,x);if(Math.min(I,t)<Math.pow(q+f.collToll,2)){var s=p.getPoint(J.t0);var r=o.getPoint(J.t1);var F=j.subtract(s,r);var z=Math.sqrt(I);var K=q-z;if(z>a.NUM_TINY){F=a.getDivideVector(F,z);}else{F=j.Y_AXIS;e.multiplyVector(e.getRotationMatrix(0,0,1,360*Math.random()),F);}var w=j.add(r,a.getScaleVector(F,G.get_radius()-0.5*K));n=j.add(n,F);u=new i();u.r0=j.subtract(w,H.get_oldState().position);u.r1=j.subtract(w,G.get_oldState().position);u.initialPenetration=K;B.push(u);}p=new l(H.getBottomPos(H.get_oldState()),a.getScaleVector(H.get_oldState().getOrientationCols()[1],j.get_length(H)));y=new l(H.getBottomPos(H.get_currentState()),a.getScaleVector(H.get_currentState().getOrientationCols()[1],j.get_length(H)));o=new l(G.getBottomPos(G.get_oldState()),a.getScaleVector(G.get_oldState().getOrientationCols()[1],j.get_length(G)));x=new l(G.getBottomPos(G.get_currentState()),a.getScaleVector(G.get_currentState().getOrientationCols()[1],j.get_length(G)));J={};I=p.segmentSegmentDistanceSq(J,o);v={};t=y.segmentSegmentDistanceSq(J,x);if(Math.min(I,t)<Math.pow(q+f.collToll,2)){s=p.getPoint(J.t0);r=o.getPoint(J.t1);F=j.subtract(s,r);z=Math.sqrt(I);K=q-z;if(z>a.NUM_TINY){F=a.getDivideVector(F,z);}else{F=j.Y_AXIS;e.multiplyVector(e.getRotationMatrix(0,0,1,360*Math.random()),F);}w=j.add(r,a.getScaleVector(F,G.get_radius()-0.5*K));n=j.add(n,F);u=new i();u.r0=j.subtract(w,H.get_oldState().position);u.r1=j.subtract(w,G.get_oldState().position);u.initialPenetration=K;B.push(u);}if(B.length>0){j.normalize(n);var A=new k();A.objInfo=E;A.dirToBody=n;A.pointInfo=B;var D=new c();D.set_restitution(Math.sqrt(H.get_material().get_restitution()*G.get_material().get_restitution()));D.set_friction(Math.sqrt(H.get_material().get_friction()*G.get_material().get_friction()));A.mat=D;C.push(A);E.body0.collisions.push(A);E.body1.collisions.push(A);}};d.CollDetectCapsuleCapsule=b;})(jigLib);(function(c){var j=c.Vector3DUtil;var a=c.JNumber3D;var g=c.JConstraint;var e=c.JConfig;var h=c.JCapsule;var d=c.JPlane;var b=c.MaterialProperties;var l=c.RigidBody;var i=c.CollPointInfo;var k=c.CollisionInfo;var f=function(){this.name="CapsulePlane";this.type0="CAPSULE";this.type1="PLANE";};c.extend(f,c.CollDetectFunctor);f.prototype.collDetect=function(m,z){var u;if(m.body0.get_type()=="PLANE"){u=m.body0;m.body0=m.body1;m.body1=u;}var r=m.body0;var t=m.body1;var q=[];var n;var s=r.getBottomPos(r.get_oldState());var y=t.pointPlaneDistance(s);var x=r.getBottomPos(r.get_currentState());var p=t.pointPlaneDistance(x);if(Math.min(y,p)<r.get_radius()+e.collToll){var v=r.get_radius()-y;var o=j.subtract(s,a.getScaleVector(t.get_normal(),r.get_radius()));n=new i();n.r0=j.subtract(o,r.get_oldState().position);n.r1=j.subtract(o,t.get_oldState().position);n.initialPenetration=v;q.push(n);}s=r.getEndPos(r.get_oldState());x=r.getEndPos(r.get_currentState());y=t.pointPlaneDistance(s);p=t.pointPlaneDistance(x);if(Math.min(y,p)<r.get_radius()+e.collToll){v=r.get_radius()-y;o=j.subtract(s,a.getScaleVector(t.get_normal(),r.get_radius()));n=new i();n.r0=j.subtract(o,r.get_oldState().position);n.r1=j.subtract(o,t.get_oldState().position);n.initialPenetration=v;q.push(n);}if(q.length>0){var w=new k();w.objInfo=m;w.dirToBody=t.get_normal();w.pointInfo=q;var A=new b();A.set_restitution(Math.sqrt(r.get_material().get_restitution()*t.get_material().get_restitution()));A.set_friction(Math.sqrt(r.get_material().get_friction()*t.get_material().get_friction()));w.mat=A;z.push(w);m.body0.collisions.push(w);m.body1.collisions.push(w);}};c.CollDetectCapsulePlane=f;})(jigLib);(function(c){var h=c.Vector3DUtil;var a=c.JNumber3D;var f=c.JConstraint;var e=c.JConfig;var g=c.JCapsule;var d=c.JTerrain;var b=c.MaterialProperties;var j=c.RigidBody;var i=function(){this.name="BoxTerrain";this.type0="CAPSULE";this.type1="TERRAIN";};c.extend(i,c.CollDetectFunctor);i.prototype.collDetect=function(l,w){var s;if(l.body0.type=="TERRAIN"){s=l.body0;l.body0=l.body1;l.body1=s;}var p=l.body0;var k=l.body1;var o=[];var m;var y=[0,0,0,0];var x=p.getBottomPos(p.oldState);var v=p.getBottomPos(p.currentState);var r=k.getHeightAndNormalByPoint(x);var q=k.getHeightAndNormalByPoint(v);if(Math.min(r.height,q.height)<e.collToll+p.radius){var t=p.radius-r.height;var n=h.subtract(x,a.getScaleVector(q.normal,p.radius));m=new CollPointInfo();m.r0=h.subtract(n,p.oldState.position);m.r1=h.subtract(n,k.oldState.position);m.initialPenetration=t;o.push(m);y=h.add(y,q.normal);}x=p.getEndPos(p.oldState);v=p.getEndPos(p.currentState);r=k.getHeightAndNormalByPoint(x);q=k.getHeightAndNormalByPoint(v);if(Math.min(r.height,q.height)<e.collToll+p.radius){t=p.radius-r.height;n=h.subtract(x,a.getScaleVector(q.normal,p.radius));m=new CollPointInfo();m.r0=h.subtract(n,p.oldState.position);m.r1=h.subtract(n,k.oldState.position);m.initialPenetration=t;o.push(m);y=h.add(y,q.normal);}if(o.length>0){h.normalize(y);var u=new CollisionInfo();u.objInfo=l;u.dirToBody=y;u.pointInfo=o;var z=new b();z.restitution=Math.sqrt(p.material.restitution*k.material.restitution);z.friction=Math.sqrt(p.material.friction*k.material.friction);u.mat=z;w.push(u);l.body0.collisions.push(u);l.body1.collisions.push(u);}};c.CollDetectCapsuleTerrain=i;})(jigLib);(function(b){var f=b.Vector3DUtil;var e=b.JNumber3D;var a=b.JConfig;var h=b.MaterialProperties;var c=b.CollPointInfo;var d=b.CollisionInfo;var g=function(){this.name="SphereBox";this.type0="SPHERE";this.type1="BOX";};b.extend(g,b.CollDetectFunctor);g.prototype.collDetect=function(j,u){var q;if(j.body0.get_type()=="BOX"){q=j.body0;j.body0=j.body1;j.body1=q;}var n=j.body0;var o=j.body1;if(!n.hitTestObject3D(o)){return;}if(a.aabbDetection&&!n.get_boundingBox().overlapTest(o.get_boundingBox())){return;}var p={};var x={};var v=o.getDistanceToPoint(o.get_oldState(),p,n.get_oldState().position);var m=o.getDistanceToPoint(o.get_currentState(),x,n.get_currentState().position);var r=n.get_radius()-v;var t=n.get_radius()-m;if(Math.max(r,t)>-a.collToll){var l;var k=[];if(v<-e.NUM_TINY){l=f.subtract(f.subtract(p.pos,n.get_oldState().position),p.pos);f.normalize(l);}else{if(v>e.NUM_TINY){l=f.subtract(n.get_oldState().position,p.pos);f.normalize(l);}else{l=f.subtract(n.get_oldState().position,o.get_oldState().position);f.normalize(l);}}var i=new c();i.r0=f.subtract(p.pos,n.get_oldState().position);i.r1=f.subtract(p.pos,o.get_oldState().position);i.initialPenetration=r;k.push(i);var s=new d();s.objInfo=j;s.dirToBody=l;s.pointInfo=k;var w=new h();w.set_restitution(Math.sqrt(n.get_material().get_restitution()*o.get_material().get_restitution()));w.set_friction(Math.sqrt(n.get_material().get_friction()*o.get_material().get_friction()));s.mat=w;u.push(s);j.body0.collisions.push(s);j.body1.collisions.push(s);}};b.CollDetectSphereBox=g;})(jigLib);(function(c){var i=c.Vector3DUtil;var d=c.JMatrix3D;var a=c.JNumber3D;var g=c.JConstraint;var e=c.JConfig;var f=c.JSphere;var k=c.JSegment;var b=c.MaterialProperties;var m=c.RigidBody;var h=c.CollPointInfo;var j=c.CollisionInfo;var l=function(){this.name="SphereCapsule";this.type0="SPHERE";this.type1="CAPSULE";};c.extend(l,c.CollDetectFunctor);l.prototype.collDetect=function(D,B){var w;if(D.body0.get_type()=="CAPSULE"){w=D.body0;D.body0=D.body1;D.body1=w;}var p=D.body0;var v=D.body1;if(!p.hitTestObject3D(v)){return;}if(e.aabbDetection&&!p.get_boundingBox().overlapTest(v.get_boundingBox())){return;}var o=new k(v.getBottomPos(v.get_oldState()),a.getScaleVector(v.get_oldState().getOrientationCols()[1],i.get_length(v)+2*v.get_radius()));var x=new k(v.getBottomPos(v.get_currentState()),a.getScaleVector(v.get_currentState().getOrientationCols()[1],i.get_length(v)+2*v.get_radius()));var n=p.get_radius()+v.get_radius();var G={};var F=o.pointSegmentDistanceSq(G,p.get_oldState().position);var s={};var q=x.pointSegmentDistanceSq(s,p.get_currentState().position);if(Math.min(F,q)<Math.pow(n+e.collToll,2)){var u=o.getPoint(G.t);var E=i.subtract(p.get_oldState().position,u);var y=Math.sqrt(F);var H=n-y;if(y>a.NUM_TINY){E=a.getDivideVector(E,y);}else{E=i.Y_AXIS;d.multiplyVector(d.getRotationMatrix(0,0,1,360*Math.random()),E);}var t=i.add(u,a.getScaleVector(E,v.get_radius()-0.5*H));var A=[];var r=new h();r.r0=i.subtract(t,p.get_oldState().position);r.r1=i.subtract(t,v.get_oldState().position);r.initialPenetration=H;A.push(r);var z=new j();z.objInfo=D;z.dirToBody=E;z.pointInfo=A;var C=new b();C.set_restitution(Math.sqrt(p.get_material().get_restitution()*v.get_material().get_restitution()));C.set_friction(Math.sqrt(p.get_material().get_friction()*v.get_material().get_friction()));z.mat=C;B.push(z);D.body0.collisions.push(z);D.body1.collisions.push(z);}};c.CollDetectSphereCapsule=l;})(jigLib);(function(d){var i=d.Vector3DUtil;var a=d.JNumber3D;var g=d.JConstraint;var e=d.JConfig;var f=d.JSphere;var c=d.MaterialProperties;var k=d.RigidBody;var h=d.CollPointInfo;var j=d.CollisionInfo;var b=function(){this.name="SpherePlane";this.type0="SPHERE";this.type1="PLANE";};d.extend(b,d.CollDetectFunctor);b.prototype.collDetect=function(m,v){var t;if(m.body0.get_type()=="PLANE"){t=m.body0;m.body0=m.body1;m.body1=t;}var q=m.body0;var s=m.body1;var w=s.pointPlaneDistance(q.get_oldState().position);var o=s.pointPlaneDistance(q.get_currentState().position);if(Math.min(o,w)>q.get_boundingSphere()+e.collToll){return;}var p=[];var l;var r=q.get_radius()-w;var n=i.subtract(q.get_oldState().position,a.getScaleVector(s.get_normal(),q.get_radius()));l=new h();l.r0=i.subtract(n,q.get_oldState().position);l.r1=i.subtract(n,s.get_oldState().position);l.initialPenetration=r;p.push(l);var u=new j();u.objInfo=m;u.dirToBody=s.get_normal();u.pointInfo=p;var x=new c();x.set_restitution(Math.sqrt(q.get_material().get_restitution()*s.get_material().get_restitution()));x.set_friction(Math.sqrt(q.get_material().get_friction()*s.get_material().get_friction()));u.mat=x;v.push(u);m.body0.collisions.push(u);m.body1.collisions.push(u);};d.CollDetectSpherePlane=b;})(jigLib);(function(d){var j=d.Vector3DUtil;var e=d.JMatrix3D;var a=d.JNumber3D;var h=d.JConstraint;var f=d.JConfig;var g=d.JSphere;var b=d.MaterialProperties;var i=d.CollPointInfo;var k=d.CollisionInfo;var c=function(){this.name="SphereSphere";this.type0="SPHERE";this.type1="SPHERE";};d.extend(c,d.CollDetectFunctor);c.prototype.collDetect=function(r,x){var m=r.body0;var A=r.body1;var n=j.subtract(m.get_oldState().position,A.get_oldState().position);var p=j.subtract(m.get_currentState().position,A.get_currentState().position);var z=j.get_lengthSquared(n);var o=j.get_lengthSquared(p);var l=m.get_radius()+A.get_radius();if(Math.min(z,o)<Math.pow(l+f.collToll,2)){var w=Math.sqrt(z);var u=l-w;if(w>a.NUM_TINY){n=a.getDivideVector(n,w);}else{n=j.Y_AXIS;e.multiplyVector(e.getRotationMatrix(0,0,1,360*Math.random()),n);}var t=j.add(A.get_oldState().position,a.getScaleVector(n,A.get_radius()-0.5*u));var s=[];var q=new i();q.r0=j.subtract(t,m.get_oldState().position);q.r1=j.subtract(t,A.get_oldState().position);q.initialPenetration=u;s.push(q);var v=new k();v.objInfo=r;v.dirToBody=n;v.pointInfo=s;var y=new b();y.set_restitution(Math.sqrt(m.get_material().get_restitution()*A.get_material().get_restitution()));y.set_friction(Math.sqrt(m.get_material().get_friction()*A.get_material().get_friction()));v.mat=y;x.push(v);r.body0.collisions.push(v);r.body1.collisions.push(v);}};d.CollDetectSphereSphere=c;})(jigLib);(function(c){var i=c.Vector3DUtil;var a=c.JNumber3D;var g=c.JConstraint;var e=c.JConfig;var f=c.JSphere;var d=c.JTerrain;var b=c.MaterialProperties;var j=c.RigidBody;var h=function(){this.name="SphereTerrain";this.type0="SPHERE";this.type1="TERRAIN";};c.extend(h,c.CollDetectFunctor);h.prototype.collDetect=function(n,v){var s;if(n.body0.type=="TERRAIN"){s=n.body0;n.body0=n.body1;n.body1=s;}var p=n.body0;var k=n.body1;var r=k.getHeightAndNormalByPoint(p.currentState.position);if(r.height<e.collToll+p.radius){var u=k.getHeightByPoint(p.oldState.position);var q=p.radius-u;var l=i.subtract(p.oldState.position,a.getScaleVector(r.normal,p.radius));var o=[];var m=new CollPointInfo();m.r0=i.subtract(l,p.oldState.position);m.r1=i.subtract(l,k.oldState.position);m.initialPenetration=q;o.push(m);var t=new CollisionInfo();t.objInfo=n;t.dirToBody=r.normal;t.pointInfo=o;var w=new b();w.restitution=Math.sqrt(p.material.restitution*k.material.restitution);w.friction=Math.sqrt(p.material.friction*k.material.friction);t.mat=w;v.push(t);n.body0.collisions.push(t);n.body1.collisions.push(t);}};c.CollDetectSphereTerrain=h;})(jigLib);(function(p){var l=p.JSegment;var i=p.RigidBody;var g=p.Vector3DUtil;var f=p.JNumber3D;var s=p.JConstraint;var t=p.CollDetectBoxBox;var o=p.CollDetectBoxPlane;var h=p.CollDetectBoxTerrain;var c=p.CollDetectCapsuleBox;var k=p.CollDetectCapsuleCapsule;var e=p.CollDetectCapsulePlane;var d=p.CollDetectCapsuleTerrain;var r=p.CollDetectSphereBox;var b=p.CollDetectSphereCapsule;var n=p.CollDetectSpherePlane;var m=p.CollDetectSphereSphere;var q=p.CollDetectSphereTerrain;var a=p.CollDetectInfo;var j=function(){this.collBody=[];detectionFunctors=[];detectionFunctors["BOX"]=[];detectionFunctors["BOX"]["BOX"]=new t();detectionFunctors["BOX"]["SPHERE"]=new r();detectionFunctors["BOX"]["CAPSULE"]=new c();detectionFunctors["BOX"]["PLANE"]=new o();detectionFunctors["BOX"]["TERRAIN"]=new h();detectionFunctors["SPHERE"]=[];detectionFunctors["SPHERE"]["BOX"]=new r();detectionFunctors["SPHERE"]["SPHERE"]=new m();detectionFunctors["SPHERE"]["CAPSULE"]=new b();detectionFunctors["SPHERE"]["PLANE"]=new n();detectionFunctors["SPHERE"]["TERRAIN"]=new q();detectionFunctors["CAPSULE"]=[];detectionFunctors["CAPSULE"]["CAPSULE"]=new k();detectionFunctors["CAPSULE"]["BOX"]=new c();detectionFunctors["CAPSULE"]["SPHERE"]=new b();detectionFunctors["CAPSULE"]["PLANE"]=new e();detectionFunctors["CAPSULE"]["TERRAIN"]=new d();detectionFunctors["PLANE"]=[];detectionFunctors["PLANE"]["BOX"]=new o();detectionFunctors["PLANE"]["SPHERE"]=new n();detectionFunctors["PLANE"]["CAPSULE"]=new e();detectionFunctors["TERRAIN"]=[];detectionFunctors["TERRAIN"]["SPHERE"]=new q();detectionFunctors["TERRAIN"]["BOX"]=new h();detectionFunctors["TERRAIN"]["CAPSULE"]=new d();this.detectionFunctors=detectionFunctors;};j.prototype.detectionFunctors=null;j.prototype.collBody=null;j.prototype.addCollisionBody=function(u){if(!this.findBody(u)){this.collBody.push(u);}};j.prototype.removeCollisionBody=function(u){if(this.findBody(u)){this.collBody.splice(this.collBody.indexOf(u),1);}};j.prototype.removeAllCollisionBodies=function(){this.collBody=[];};j.prototype.detectCollisions=function(u,x){if(!u.isActive){return;}var y;var z;for(var w=0,A=this.collBody.length;w<A;w++){var v=this.collBody[w];if(u!=v&&this.checkCollidables(u,v)&&this.detectionFunctors[u.get_type()][v.get_type()]!=undefined){y=new a();y.body0=u;y.body1=v;z=detectionFunctors[y.body0.get_type()][y.body1.get_type()];z.collDetect(y,x);}}};j.prototype.detectAllCollisions=function(u,D){var x;var B;var z;var E;for(var C=0,w=u.length;C<w;C++){var y=u[C];z=y.id;E=y.get_type();for(var A=0;A<this.collBody.length;A++){var v=this.collBody[A];if(y==v){continue;}if(v.isActive&&z>v.id){continue;}if(this.checkCollidables(y,v)&&this.detectionFunctors[E][v.get_type()]!=undefined){x=new a();x.body0=y;x.body1=v;B=detectionFunctors[x.body0.get_type()][x.body1.get_type()];B.collDetect(x,D);}}}};j.prototype.segmentIntersect=function(x,u,w){x.fracOut=f.NUM_HUGE;x.posOut=[0,0,0,0];x.normalOut=[0,0,0,0];var z={};for(var y=0,A=this.collBody.length;y<A;y++){var v=this.collBody[y];if(v!=w&&this.segmentBounding(u,v)){if(v.segmentIntersect(z,u,v.get_currentState())){if(z.fracOut<x.fracOut){x.posOut=z.posOut;x.normalOut=z.normalOut;x.fracOut=z.fracOut;x.bodyOut=v;}}}}if(x.fracOut>1){return false;}if(x.fracOut<0){x.fracOut=0;}else{if(x.fracOut>1){x.fracOut=1;}}return true;};j.prototype.segmentBounding=function(u,y){var z=u.getPoint(0.5);var v=g.get_length(u.delta)/2;if(y.get_type()!="PLANE"&&y.get_type()!="TERRAIN"){var x=g.get_length(g.subtract(z,y.get_currentState().position));var w=v+y.get_boundingSphere();if(x<=w){return true;}else{return false;}}else{return true;}};j.prototype.findBody=function(u){for(var w=0,x=this.collBody.length;w<x;w++){var v=this.collBody[w];if(u==v){return true;}}return false;};j.prototype.checkCollidables=function(y,w){if(y.get_nonCollidables().length==0&&w.get_nonCollidables().length==0){return true;}var v=y.get_nonCollidables();for(var x=0,u=v.length;x<u;x++){var A=v[x];if(w==A){return false;}}v=w.get_nonCollidables();for(var x=0,u=v.length;x<u;x++){var z=v[x];if(y==z){return false;}}return true;};p.CollisionSystem=j;})(jigLib);(function(a){var b=function(){this._constraintEnabled=false;this.enableConstraint();};b.prototype._satisfied=null;b.prototype._constraintEnabled=null;b.prototype.set_satisfied=function(c){this._satisfied=c;};b.prototype.get_satisfied=function(){return this._satisfied;};b.prototype.preApply=function(c){this._satisfied=false;};b.prototype.apply=function(c){return false;};b.prototype.enableConstraint=function(){if(this._constraintEnabled){return;}this._constraintEnabled=true;a.PhysicsSystem.getInstance().addConstraint(this);};b.prototype.disableConstraint=function(){if(!this._constraintEnabled){return;}this._constraintEnabled=false;a.PhysicsSystem.getInstance().removeConstraint(this);};b.prototype.get_constraintEnabled=function(){return this._constraintEnabled;};a.JConstraint=b;})(jigLib);(function(b){var e=b.Vector3DUtil;var a=b.JMatrix3D;var c=b.JNumber3D;var d=function(h,i,f,g,j){if(!j){j=1;}this.Super();this._body0=h;this._body0Pos=i;this._body1=f;this._body1Pos=g;this._maxDistance=j;h.addConstraint(this);f.addConstraint(this);};b.extend(d,b.JConstraint);d.prototype._maxVelMag=20;d.prototype._minVelForProcessing=0.01;d.prototype._body0=null;d.prototype._body1=null;d.prototype._body0Pos=null;d.prototype._body1Pos=null;d.prototype._maxDistance=null;d.prototype.r0=null;d.prototype.r1=null;d.prototype._worldPos=null;d.prototype._currentRelPos0=null;d.prototype.preApply=function(h){this.set_satisfied(false);this.r0=this._body0Pos.slice(0);this.r1=this._body1Pos.slice(0);a.multiplyVector(this._body0.get_currentState().get_orientation(),this.r0);a.multiplyVector(this._body1.get_currentState().get_orientation(),this.r1);var g=e.add(this._body0.get_currentState().position,this.r0);var f=e.add(this._body1.get_currentState().position,this.r1);this._worldPos=c.getScaleVector(e.add(g,f),0.5);this._currentRelPos0=e.subtract(g,f);};d.prototype.apply=function(g){this.set_satisfied(true);if(!this._body0.isActive&&!this._body1.isActive){return false;}var l=this._body0.getVelocity(this.r0);var k=this._body1.getVelocity(this.r1);var n=e.add(this._currentRelPos0,c.getScaleVector(e.subtract(l,k),g));var m=n.slice(0);var s=e.get_length(m);if(s<=c.NUM_TINY){return false;}if(s>this._maxDistance){m=c.getScaleVector(m,this._maxDistance/s);}var q=c.getDivideVector(e.subtract(m,this._currentRelPos0),g);var f=e.subtract(e.subtract(l,k),q);var j=e.get_length(f);if(j>this._maxVelMag){f=c.getScaleVector(f,this._maxVelMag/j);j=this._maxVelMag;}else{if(j<this._minVelForProcessing){return false;}}var p=c.getDivideVector(f,j);var r=e.crossProduct(this.r0,p);a.multiplyVector(this._body0.get_worldInvInertia(),r);var o=e.crossProduct(this.r1,p);a.multiplyVector(this._body1.get_worldInvInertia(),o);var i=this._body0.get_invMass()+this._body1.get_invMass()+e.dotProduct(p,e.crossProduct(r,this.r0))+e.dotProduct(p,e.crossProduct(o,this.r1));if(i<c.NUM_TINY){return false;}var h=c.getScaleVector(p,-j/i);this._body0.applyWorldImpulse(h,this._worldPos);this._body1.applyWorldImpulse(c.getScaleVector(h,-1),this._worldPos);this._body0.setConstraintsAndCollisionsUnsatisfied();this._body1.setConstraintsAndCollisionsUnsatisfied();this.set_satisfied(true);return true;};b.JConstraintMaxDistance=d;})(jigLib);(function(c){var e=c.Vector3DUtil;var b=c.JMatrix3D;var d=c.JNumber3D;var a=function(i,k,g,h,j,f){this.Super();this._body0=i;this._body0Pos=k;this._body1=g;this._body1Pos=h;this._allowedDistance=(j)?j:1;this._timescale=(f)?f:1;if(this._timescale<d.NUM_TINY){_timescale=d.NUM_TINY;}i.addConstraint(this);g.addConstraint(this);};c.extend(a,c.JConstraint);a.prototype._maxVelMag=20;a.prototype._minVelForProcessing=0.01;a.prototype._body0=null;a.prototype._body1=null;a.prototype._body0Pos=null;a.prototype._body1Pos=null;a.prototype._timescale=null;a.prototype._allowedDistance=null;a.prototype.r0=null;a.prototype.r1=null;a.prototype._worldPos=null;a.prototype._vrExtra=null;a.prototype.preApply=function(j){this.set_satisfied(false);this.r0=this._body0Pos.slice(0);b.multiplyVector(this._body0.get_currentState().get_orientation(),this.r0);this.r1=this._body1Pos.slice(0);b.multiplyVector(this._body1.get_currentState().get_orientation(),this.r1);var g=e.add(this._body0.get_currentState().position,this.r0);var f=e.add(this._body1.get_currentState().position,this.r1);this._worldPos=d.getScaleVector(e.add(g,f),0.5);var i=e.subtract(g,f);var h=e.get_length(i);if(h>this._allowedDistance){this._vrExtra=d.getScaleVector(i,(h-this._allowedDistance)/(h*Math.max(this._timescale,j)));}else{this._vrExtra=[0,0,0,0];}};a.prototype.apply=function(h){this.set_satisfied(true);if(!this._body0.isActive&&!this._body1.isActive){return false;}var m=this._body0.getVelocity(this.r0);var l=this._body1.getVelocity(this.r1);var f=e.add(this._vrExtra,e.subtract(m,l));var k=e.get_length(f);if(k<this._minVelForProcessing){return false;}if(k>this._maxVelMag){f=d.getScaleVector(f,this._maxVelMag/k);k=this._maxVelMag;}var n=d.getDivideVector(f,k);var p=e.crossProduct(this.r0,n);b.multiplyVector(this._body0.get_worldInvInertia(),p);var o=e.crossProduct(this.r1,n);b.multiplyVector(this._body1.get_worldInvInertia(),o);var j=this._body0.get_invMass()+this._body1.get_invMass()+e.dotProduct(n,e.crossProduct(p,this.r0))+e.dotProduct(n,e.crossProduct(o,this.r1));if(j<d.NUM_TINY){return false;}var i=d.getScaleVector(n,-k/j);var g=d.getScaleVector(i,-1);this._body0.applyWorldImpulse(i,this._worldPos);this._body1.applyWorldImpulse(g,this._worldPos);this._body0.setConstraintsAndCollisionsUnsatisfied();this._body1.setConstraintsAndCollisionsUnsatisfied();this.set_satisfied(true);return true;};c.JConstraintPoint=a;})(jigLib);(function(c){var e=c.Vector3DUtil;var b=c.JMatrix3D;var d=c.JNumber3D;var a=function(f,g,h){this.Super();this._body=f;this._pointOnBody=g;this._worldPosition=h;f.addConstraint(this);};c.extend(a,c.JConstraint);a.prototype.minVelForProcessing=0.001;a.prototype.allowedDeviation=0.01;a.prototype.timescale=4;a.prototype._body=null;a.prototype._pointOnBody=null;a.prototype._worldPosition=null;a.prototype.set_worldPosition=function(f){this._worldPosition=f;};a.prototype.get_worldPosition=function(){return this._worldPosition;};a.prototype.apply=function(f){this.set_satisfied(true);var k=this._pointOnBody.slice(0);b.multiplyVector(this._body.get_currentState().get_orientation(),k);k=e.add(k,this._body.get_currentState().position);var m=e.subtract(k,this._body.get_currentState().position);var q=e.add(this._body.get_currentState().linVelocity,e.crossProduct(this._body.get_currentState().rotVelocity,m));var g;var p;var j=e.subtract(k,this._worldPosition);var r=e.get_length(j);if(r>this.allowedDeviation){p=d.getDivideVector(j,r);g=d.getScaleVector(p,(this.allowedDeviation-r)/(this.timescale*f));}else{g=[0,0,0,0];}var o=e.subtract(q,g);var l=e.get_length(o);if(l<this.minVelForProcessing){return false;}o=d.getDivideVector(o,l);var n=e.crossProduct(m,o);b.multiplyVector(this._body.get_worldInvInertia(),n);var i=this._body.get_invMass()+e.dotProduct(o,e.crossProduct(n,m));if(i<d.NUM_TINY){return false;}var h=-l/i;this._body.applyWorldImpulse(d.getScaleVector(o,h),k);this._body.setConstraintsAndCollisionsUnsatisfied();this.set_satisfied(true);return true;};c.JConstraintWorldPoint=a;})(jigLib);(function(c){var f=c.Vector3DUtil;var b=c.JMatrix3D;var d=c.JNumber3D;var e=c.JConstraintMaxDistance;var a=c.JConstraintPoint;var g=function(u,r,x,C,l,o,i,I,k){this._body0=u;this._body1=r;this._hingeAxis=x.slice(0);this._hingePosRel0=C.slice(0);this._usingLimit=false;this._hingeEnabled=false;this._broken=false;this._damping=k;this._extraTorque=0;f.normalize(this._hingeAxis);var j=f.add(this._body0.get_currentState().position,f.subtract(this._hingePosRel0,this._body1.get_currentState().position));var q=f.add(this._hingePosRel0,d.getScaleVector(this._hingeAxis,l));var p=f.subtract(this._hingePosRel0,d.getScaleVector(this._hingeAxis,l));var F=f.add(j,d.getScaleVector(this._hingeAxis,l));var D=f.subtract(j,d.getScaleVector(this._hingeAxis,l));var t=1/20;var A=0.005;var m=I*l;this.sidePointConstraints=[];this.sidePointConstraints[0]=new e(this._body0,q,this._body1,F,m);this.sidePointConstraints[1]=new e(this._body0,p,this._body1,D,m);this.midPointConstraint=new a(this._body0,this._hingePosRel0,this._body1,j,A,t);if(o<=this.MAX_HINGE_ANGLE_LIMIT){var h=f.Y_AXIS;if(f.dotProduct(h,this._hingeAxis)>0.1){h[0]=1;h[1]=0;h[2]=0;}var w=f.crossProduct(this._hingeAxis,h);h=f.crossProduct(w,this._hingeAxis);f.normalize(h);var E=10*l;var B=d.getScaleVector(h,E);var H=0.5*(o-i);var z=B.slice(0);b.multiplyVector(b.getRotationMatrix(this._hingeAxis[0],this._hingeAxis[1],this._hingeAxis[2],-H),z);var v=0.5*(o+i);var s=E*2*Math.sin(0.5*v*Math.PI/180);var G=f.add(this._body1.get_currentState().position,this._hingePosRel0);var n=f.add(G,f.subtract(B,this._body0.get_currentState().position));var y=f.add(G,f.subtract(z,this._body1.get_currentState().position));this.maxDistanceConstraint=new e(this._body0,n,this._body1,y,s);this._usingLimit=true;}if(this._damping<=0){this._damping=-1;}else{this._damping=d.getLimiteNumber(this._damping,0,1);}this.enableHinge();};c.extend(g,c.PhysicsController);g.prototype.MAX_HINGE_ANGLE_LIMIT=150;g.prototype._hingeAxis=null;g.prototype._hingePosRel0=null;g.prototype._body0=null;g.prototype._body1=null;g.prototype._usingLimit=null;g.prototype._hingeEnabled=null;g.prototype._broken=null;g.prototype._damping=null;g.prototype._extraTorque=null;g.prototype.sidePointConstraints=null;g.prototype.midPointConstraint=null;g.prototype.maxDistanceConstraint=null;g.prototype.enableHinge=function(){if(this._hingeEnabled){return;}this.midPointConstraint.enableConstraint();this.sidePointConstraints[0].enableConstraint();this.sidePointConstraints[1].enableConstraint();if(this._usingLimit&&!this._broken){this.maxDistanceConstraint.enableConstraint();}this.enableController();this._hingeEnabled=true;};g.prototype.disableHinge=function(){if(!this._hingeEnabled){return;}this.midPointConstraint.disableConstraint();this.sidePointConstraints[0].disableConstraint();this.sidePointConstraints[1].disableConstraint();if(this._usingLimit&&!this._broken){this.maxDistanceConstraint.disableConstraint();}this.disableController();this._hingeEnabled=false;};g.prototype.breakHinge=function(){if(this._broken){return;}if(this._usingLimit){this.maxDistanceConstraint.disableConstraint();}this._broken=true;};g.prototype.mendHinge=function(){if(!this._broken){return;}if(this._usingLimit){this.maxDistanceConstraint.enableConstraint();}this._broken=false;};g.prototype.setExtraTorque=function(h){this._extraTorque=h;};g.prototype.getHingeEnabled=function(){return this._hingeEnabled;};g.prototype.isBroken=function(){return this._broken;};g.prototype.getHingePosRel0=function(){return this._hingePosRel0;};g.prototype.updateController=function(i){if(this._damping>0){var j=f.subtract(this._body1.get_currentState().rotVelocity,this._body0.get_currentState().rotVelocity);f.normalize(j);var o=f.dotProduct(this._body0.get_currentState().rotVelocity,j);var n=f.dotProduct(this._body1.get_currentState().rotVelocity,j);var l=0.5*(o+n);var h=1-this._damping;var q=l+(o-l)*h;var p=l+(n-l)*h;var m=f.add(this._body0.get_currentState().rotVelocity,d.getScaleVector(j,q-o));var k=f.add(this._body1.get_currentState().rotVelocity,d.getScaleVector(j,p-n));this._body0.setAngVel(m);this._body1.setAngVel(k);}if(this._extraTorque!=0){var r=this._hingeAxis.slice(0);b.multiplyVector(this._body0.get_currentState().get_orientation(),r);r=d.getScaleVector(r,this._extraTorque);this._body0.addWorldTorque(r);this._body1.addWorldTorque(d.getScaleVector(r,-1));}};c.HingeJoint=g;})(jigLib);(function(d){var k=d.Vector3DUtil;var h=d.JConfig;var j=d.CollPointInfo;var i=d.CollisionSystem;var g=d.ContactData;var e=d.JMatrix3D;var b=d.JNumber3D;var c=d.BodyPair;var a=d.CachedImpulse;var f=function(){this.setSolverType(h.solverType);this._doingIntegration=false;this._bodies=[];this._collisions=[];this._effects=[];this._activeBodies=[];this._constraints=[];this._controllers=[];this._cachedContacts=[];this._collisionSystem=new i();this.setGravity(b.getScaleVector(k.Y_AXIS,-10));};f.prototype._currentPhysicsSystem=null;f.prototype._maxVelMag=0.5;f.prototype._minVelForProcessing=0.001;f.prototype._bodies=null;f.prototype._activeBodies=null;f.prototype._collisions=null;f.prototype._constraints=null;f.prototype._controllers=null;f.prototype._effects=null;f.prototype._gravityAxis=null;f.prototype._gravity=null;f.prototype._doingIntegration=null;f.prototype.preProcessCollisionFn=function(){};f.prototype.preProcessContactFn=function(){};f.prototype.processCollisionFn=function(){};f.prototype.processContactFn=function(){};f.prototype._cachedContacts=null;f.prototype._collisionSystem=null;f.getInstance=function(){if(!f._currentPhysicsSystem){f._currentPhysicsSystem=new f();}return f._currentPhysicsSystem;};f.prototype.getAllExternalForces=function(n){for(var m=0,o=this._bodies.length;m<o;m++){this._bodies[m].addExternalForces(n);}for(var m=0,l=this._controllers.length;m<l;m++){this._controllers[m].updateController(n);}};f.prototype.getCollisionSystem=function(){return this._collisionSystem;};f.prototype.setGravity=function(l){this._gravity=l;if(this._gravity[0]==this._gravity[1]&&this._gravity[1]==this._gravity[2]){this._gravityAxis=-1;}this._gravityAxis=0;if(Math.abs(this._gravity[1])>Math.abs(this._gravity[2])){this._gravityAxis=1;}if(Math.abs(this._gravity[2])>Math.abs(this._gravity[this._gravityAxis])){this._gravityAxis=2;}};f.prototype.get_gravity=function(){return this._gravity;};f.prototype.get_gravityAxis=function(){return this._gravityAxis;};f.prototype.get_bodies=function(){return this._bodies;};f.prototype.addBody=function(l){if(!this.findBody(l)){this._bodies.push(l);this._collisionSystem.addCollisionBody(l);}};f.prototype.removeBody=function(l){if(this.findBody(l)){this._bodies.splice(this._bodies.indexOf(l),1);this._collisionSystem.removeCollisionBody(l);}};f.prototype.removeAllBodies=function(){this._bodies=[];this._collisionSystem.removeAllCollisionBodies();};f.prototype.addConstraint=function(l){if(!this.findConstraint(l)){this._constraints.push(l);}};f.prototype.removeConstraint=function(l){if(this.findConstraint(l)){this._constraints.splice(this._constraints.indexOf(l),1);}};f.prototype.removeAllConstraints=function(){this._constraints=[];};f.prototype.addEffect=function(l){if(!this.findEffect(l)){this._effects.push(l);}};f.prototype.removeEffect=function(l){if(this.findEffect(l)){this._effects.splice(this._effects.indexOf(l),1);}};f.prototype.removeAllEffects=function(){this._effects=[];};f.prototype.addController=function(l){if(!this.findController(l)){this._controllers.push(l);}};f.prototype.removeController=function(l){if(this.findController(l)){this._controllers.splice(this._controllers.indexOf(l),1);}};f.prototype.removeAllControllers=function(){this._controllers=[];};f.prototype.setSolverType=function(l){switch(l){case"FAST":this.preProcessCollisionFn=this.preProcessCollisionFast;this.preProcessContactFn=this.preProcessCollisionFast;this.processCollisionFn=this.processCollision;this.processContactFn=this.processCollision;return;case"NORMAL":this.preProcessCollisionFn=this.preProcessCollisionNormal;this.preProcessContactFn=this.preProcessCollisionNormal;this.processCollisionFn=this.processCollision;this.processContactFn=this.processCollision;return;case"ACCUMULATED":this.preProcessCollisionFn=this.preProcessCollisionAccumulated;this.preProcessContactFn=this.preProcessCollisionAccumulated;this.processCollisionFn=this.processCollision;this.processContactFn=this.processCollisionAccumulated;return;default:this.preProcessCollisionFn=this.preProcessCollisionNormal;this.preProcessContactFn=this.preProcessCollisionNormal;this.processCollisionFn=this.processCollision;this.processContactFn=this.processCollision;return;}};f.prototype.findBody=function(l){var m=this._bodies.length-1;if(m>0){do{if(l==this._bodies[m]){return true;}}while(m--);}return false;};f.prototype.findConstraint=function(m){var l=this._constraints.length-1;if(l>0){do{if(m==this._constraints[l]){return true;}}while(l--);}return false;};f.prototype.findEffect=function(m){var l=this._effects.length-1;if(l>0){do{if(m==this._effects[l]){return true;}}while(l--);}return false;};f.prototype.findController=function(l){var m=this._controllers.length-1;if(m>0){do{if(l==this._controllers[m]){return true;}}while(m--);}return false;};f.prototype.preProcessCollisionFast=function(x,n){x.satisfied=false;var m=x.objInfo.body0;var l=x.objInfo.body1;var s=x.dirToBody;var z=h.numPenetrationRelaxationTimesteps*n;var w=0;var y;var q;var p=x.pointInfo.length;var r=b.NUM_TINY;if(p>1){var v=[0,0,0,0];var t=[0,0,0,0];var B=0;for(var o=0;o<p;o++){y=x.pointInfo[o];v=k.add(v,y.r0);t=k.add(t,y.r1);B+=y.initialPenetration;}v=b.getDivideVector(v,p);t=b.getDivideVector(t,p);B/=p;var A=new j();A.r0=v;A.r1=t;A.initialPenetration=B;x.pointInfo=[A];}y=x.pointInfo[0];if(!m.get_movable()){y.denominator=0;}else{q=k.crossProduct(y.r0,s);e.multiplyVector(m.get_worldInvInertia(),q);y.denominator=m.get_invMass()+k.dotProduct(s,k.crossProduct(q,y.r0));}if(l.get_movable()){q=k.crossProduct(y.r1,s);e.multiplyVector(l.get_worldInvInertia(),q);y.denominator+=(l.get_invMass()+k.dotProduct(s,k.crossProduct(q,y.r1)));}if(y.denominator<r){y.denominator=r;}if(y.initialPenetration>h.allowedPenetration){y.minSeparationVel=(y.initialPenetration-h.allowedPenetration)/z;}else{w=-0.1*(y.initialPenetration-h.allowedPenetration)/h.allowedPenetration;if(w<r){w=r;}else{if(w>1){w=1;}}var u=(n>r)?n:r;y.minSeparationVel=w*(y.initialPenetration-h.allowedPenetration)/u;}if(y.minSeparationVel>this._maxVelMag){y.minSeparationVel=this._maxVelMag;}};f.prototype.preProcessCollisionNormal=function(u,n){u.satisfied=false;var m=u.objInfo.body0;var l=u.objInfo.body1;var r=u.dirToBody;var w=h.numPenetrationRelaxationTimesteps*n;var t=0;var v;var q;var p=u.pointInfo.length;for(var o=0;o<p;o++){v=u.pointInfo[o];if(!m.get_movable()){v.denominator=0;}else{q=k.crossProduct(v.r0,r);e.multiplyVector(m.get_worldInvInertia(),q);v.denominator=m.get_invMass()+k.dotProduct(r,k.crossProduct(q,v.r0));}if(l.get_movable()){q=k.crossProduct(v.r1,r);e.multiplyVector(l.get_worldInvInertia(),q);v.denominator+=(l.get_invMass()+k.dotProduct(r,k.crossProduct(q,v.r1)));}if(v.denominator<b.NUM_TINY){v.denominator=b.NUM_TINY;}if(v.initialPenetration>h.allowedPenetration){v.minSeparationVel=(v.initialPenetration-h.allowedPenetration)/w;}else{t=-0.1*(v.initialPenetration-h.allowedPenetration)/h.allowedPenetration;if(t<b.NUM_TINY){t=b.NUM_TINY;}else{if(t>1){t=1;}}var s=(n>b.NUM_TINY)?n:b.NUM_TINY;v.minSeparationVel=t*(v.initialPenetration-h.allowedPenetration)/s;}if(v.minSeparationVel>this._maxVelMag){v.minSeparationVel=this._maxVelMag;}}};f.prototype.preProcessCollisionAccumulated=function(q,y){q.satisfied=false;var x=q.objInfo.body0;var v=q.objInfo.body1;var r=q.dirToBody;var w=h.numPenetrationRelaxationTimesteps*y;var p;var t;var H;var E=0;var F=b.NUM_TINY;var u=h.allowedPenetration;var D=q.pointInfo.length;for(var C=0;C<D;C++){t=q.pointInfo[C];H=t.initialPenetration-u;if(!x.get_movable()){t.denominator=0;}else{p=k.crossProduct(t.r0,r);e.multiplyVector(x.get_worldInvInertia(),p);t.denominator=x.get_invMass()+k.dotProduct(r,k.crossProduct(p,t.r0));}if(v.get_movable()){p=k.crossProduct(t.r1,r);e.multiplyVector(v.get_worldInvInertia(),p);t.denominator+=(v.get_invMass()+k.dotProduct(r,k.crossProduct(p,t.r1)));}if(t.denominator<F){t.denominator=F;}if(t.initialPenetration>u){t.minSeparationVel=H/w;}else{E=-0.1*H/u;if(E<F){E=F;}else{if(E>1){E=1;}}var B=(y>F)?y:F;t.minSeparationVel=E*H/B;}t.accumulatedNormalImpulse=0;t.accumulatedNormalImpulseAux=0;t.accumulatedFrictionImpulse=[0,0,0,0];var o=0.04;var G=new c(x,v,[0,0,0,0],[0,0,0,0]);for(var A=0,n=this._cachedContacts.length;A<n;A++){var l=this._cachedContacts[A];var z=l.pair;if(G.body0!=z.body0||G.body1==z.body1){continue;}var m=(z.body0==x)?k.get_lengthSquared(k.subtract(z.r,t.r0)):k.get_lengthSquared(k.subtract(z.r,t.r1));if(m<o){o=m;t.accumulatedNormalImpulse=this._cachedContacts[A].impulse.normalImpulse;t.accumulatedNormalImpulseAux=this._cachedContacts[A].impulse.normalImpulseAux;t.accumulatedFrictionImpulse=this._cachedContacts[A].impulse.frictionImpulse;if(this._cachedContacts[A].pair.body0!=x){t.accumulatedFrictionImpulse=b.getScaleVector(t.accumulatedFrictionImpulse,-1);}}}var s;if(t.accumulatedNormalImpulse!=0){s=b.getScaleVector(r,t.accumulatedNormalImpulse);s=k.add(s,t.accumulatedFrictionImpulse);x.applyBodyWorldImpulse(s,t.r0);v.applyBodyWorldImpulse(b.getScaleVector(s,-1),t.r1);}if(t.accumulatedNormalImpulseAux!=0){s=b.getScaleVector(r,t.accumulatedNormalImpulseAux);x.applyBodyWorldImpulseAux(s,t.r0);v.applyBodyWorldImpulseAux(b.getScaleVector(s,-1),t.r1);}}};f.prototype.processCollision=function(r,D){r.satisfied=true;var A=r.objInfo.body0;var z=r.objInfo.body1;var v=false;var t=r.dirToBody;var G=0;var H=0;var n=0;var C=0;var x;var u;var s;var y;var F=r.pointInfo.length;for(var E=0;E<F;E++){y=r.pointInfo[E];u=A.getVelocity(y.r0);s=z.getVelocity(y.r1);H=k.dotProduct(k.subtract(u,s),t);if(H>y.minSeparationVel){continue;}n=-1*r.mat.get_restitution()*H;if(n<this._minVelForProcessing){n=y.minSeparationVel;}G=n-H;if(G<=this._minVelForProcessing){continue;}C=G/y.denominator;v=true;x=b.getScaleVector(t,C);A.applyBodyWorldImpulse(x,y.r0);z.applyBodyWorldImpulse(b.getScaleVector(x,-1),y.r1);var p;var B=u.slice(0);if(z.get_movable()){B=k.subtract(u,s);}var q=k.subtract(B,b.getScaleVector(t,k.dotProduct(B,t)));var w=k.get_length(q);if(w>this._minVelForProcessing){var o=b.getDivideVector(q,-w);var l=0;if(A.get_movable()){p=k.crossProduct(y.r0,o);e.multiplyVector(A.get_worldInvInertia(),p);l=A.get_invMass()+k.dotProduct(o,k.crossProduct(p,y.r0));}if(z.get_movable()){p=k.crossProduct(y.r1,o);e.multiplyVector(z.get_worldInvInertia(),p);l+=(z.get_invMass()+k.dotProduct(o,k.crossProduct(p,y.r1)));}if(l>b.NUM_TINY){var m=w/l;o=b.getScaleVector(o,m);A.applyBodyWorldImpulse(o,y.r0);z.applyBodyWorldImpulse(b.getScaleVector(o,-1),y.r1);}}}if(v){A.setConstraintsAndCollisionsUnsatisfied();z.setConstraintsAndCollisionsUnsatisfied();}return v;};f.prototype.processCollisionAccumulated=function(r,I){r.satisfied=true;var w=false;var u=r.dirToBody;var F=r.objInfo.body0;var E=r.objInfo.body1;var O=0;var Q=0;var H=0;var z;var v;var t;var A;var M=r.pointInfo.length;for(var K=0;K<M;K++){A=r.pointInfo[K];v=F.getVelocity(A.r0);t=E.getVelocity(A.r1);Q=k.dotProduct(k.subtract(v,t),u);O=-Q;if(A.minSeparationVel<0){O+=A.minSeparationVel;}if(Math.abs(O)>this._minVelForProcessing){H=O/A.denominator;var C=A.accumulatedNormalImpulse;var J=(C+H);if(J<0){J=0;}A.accumulatedNormalImpulse=J;var s=J-C;z=b.getScaleVector(u,s);F.applyBodyWorldImpulse(z,A.r0);E.applyBodyWorldImpulse(b.getScaleVector(z,-1),A.r1);w=true;}v=F.getVelocityAux(A.r0);t=E.getVelocityAux(A.r1);Q=k.dotProduct(k.subtract(v,t),u);O=-Q;if(A.minSeparationVel>0){O+=A.minSeparationVel;}if(Math.abs(O)>this._minVelForProcessing){H=O/A.denominator;C=A.accumulatedNormalImpulseAux;var D=A.accumulatedNormalImpulseAux+H;if(D<0){D=0;}A.accumulatedNormalImpulseAux=D;s=D-C;z=b.getScaleVector(u,s);F.applyBodyWorldImpulseAux(z,A.r0);E.applyBodyWorldImpulseAux(b.getScaleVector(z,-1),A.r1);w=true;}if(A.accumulatedNormalImpulse>0){v=F.getVelocity(A.r0);t=E.getVelocity(A.r1);var p;var G=k.subtract(v,t);var q=k.subtract(G,b.getScaleVector(u,k.dotProduct(G,u)));var y=k.get_length(q);if(y>this._minVelForProcessing){var o=b.getScaleVector(b.getDivideVector(q,y),-1);var m=0;if(F.get_movable()){p=k.crossProduct(A.r0,o);e.multiplyVector(F.get_worldInvInertia(),p);m=F.invMass+k.dotProduct(o,k.crossProduct(p,A.r0));}if(E.get_movable()){p=k.crossProduct(A.r1,o);e.multiplyVector(E.get_worldInvInertia(),p);m+=(E.invMass+k.dotProduct(o,k.crossProduct(p,A.r1)));}if(m>b.NUM_TINY){var n=y/m;var l=b.getScaleVector(o,n);var P=A.accumulatedFrictionImpulse.slice(0);A.accumulatedFrictionImpulse=k.add(A.accumulatedFrictionImpulse,l);var L=k.get_length(A.accumulatedFrictionImpulse);var B=r.mat.friction*A.accumulatedNormalImpulse;if(L>b.NUM_TINY&&L>B){A.accumulatedFrictionImpulse=b.getScaleVector(A.accumulatedFrictionImpulse,B/L);}var x=k.subtract(A.accumulatedFrictionImpulse,P);F.applyBodyWorldImpulse(x,A.r0);E.applyBodyWorldImpulse(b.getScaleVector(x,-1),A.r1);}}}}if(w){F.setConstraintsAndCollisionsUnsatisfied();E.setConstraintsAndCollisionsUnsatisfied();}return w;};f.prototype.sortPositionX=function(m,l){if(m.get_currentState().position[0]<l.get_currentState().position[0]){return -1;}else{if(m.get_currentState().position[0]>l.get_currentState().position[0]){return 1;}else{return 0;}}};f.prototype.sortPositionY=function(m,l){if(m.get_currentState().position[1]<l.get_currentState().position[1]){return -1;}else{if(m.get_currentState().position[1]>l.get_currentState().position[1]){return 1;}else{return 0;}}};f.prototype.sortPositionZ=function(m,l){if(m.get_currentState().position[2]<l.get_currentState().position[2]){return -1;}else{if(m.get_currentState().position[2]>l.get_currentState().position[2]){return 1;}else{return 0;}}};f.prototype.doShockStep=function(o){if(Math.abs(this._gravity[0])>Math.abs(this._gravity[1])&&Math.abs(this._gravity[0])>Math.abs(this._gravity[2])){this._bodies=this._bodies.sort(this.sortPositionX);this._collisionSystem.collBody=this._collisionSystem.collBody.sort(this.sortPositionX);}else{if(Math.abs(this._gravity[1])>Math.abs(this._gravity[2])&&Math.abs(this._gravity[1])>Math.abs(this._gravity[0])){this._bodies=this._bodies.sort(this.sortPositionY);this._collisionSystem.collBody=this._collisionSystem.collBody.sort(this.sortPositionY);}else{if(Math.abs(this._gravity[2])>Math.abs(this._gravity[0])&&Math.abs(this._gravity[2])>Math.abs(this._gravity[1])){this._bodies=this._bodies.sort(this.sortPositionZ);this._collisionSystem.collBody=this._collisionSystem.collBody.sort(this.sortPositionZ);}}}var p;var l;var q=true;var r=[];var n;var m;while(q){q=false;for(var t=0;t<this._bodies.length;t++){var u=this._bodies[t];if(u.get_movable()&&u.get_doShockProcessing()){if(u.collisions.length==0||!u.isActive){u.internalSetImmovable();}else{l=false;r=u.collisions;for(var s=0;s<r.length;s++){p=r[s];n=p.objInfo.body0;m=p.objInfo.body1;if((n==u&&!m.get_movable())||(m==u&&!n.get_movable())){this.preProcessCollisionFast(p,o);this.processCollision(p,o);l=true;}}if(l){u.internalSetImmovable();q=true;}}}}}for(var t=0;t<this._bodies.length;t++){u=this._bodies[t];u.internalRestoreImmovable();r=u.collisions;for(var s=0;s<r.length;s++){p=r[s];this.preProcessCollisionFn(p,o);this.processCollisionFn(p,o);}}};f.prototype.updateContactCache=function(){this._cachedContacts=[];var q;var s;var l;for(var o=0,m=this._collisions.length;o<m;o++){var r=this._collisions[o];for(var n=0,p=r.pointInfo.length;n<p;n++){q=r.pointInfo[n];s=(r.objInfo.body0.id>r.objInfo.body1.id)?q.accumulatedFrictionImpulse:b.getScaleVector(q.accumulatedFrictionImpulse,-1);l=new g();l.pair=new c(r.objInfo.body0,r.objInfo.body1,q.r0,q.r1);l.impulse=new a(q.accumulatedNormalImpulse,q.accumulatedNormalImpulseAux,q.accumulatedFrictionImpulse);this._cachedContacts.push(l);}}};f.prototype.handleAllConstraints=function(l,u,w){var x=this._collisions.length;var t;var p;for(var q=0,v=this._constraints.length;q<v;q++){this._constraints[q].preApply(l);}if(w){for(var q=0,v=this._collisions.length;q<v;q++){this.preProcessContactFn(this._collisions[q],l);this._collisions[q].mat.set_restitution(0);this._collisions[q].satisfied=false;}}else{for(var q=0,v=this._collisions.length;q<v;q++){this.preProcessCollisionFn(this._collisions[q],l);}}var s;
3
+ var n;var r;for(var m=0;m<u;m++){n=false;for(var q=0,v=this._collisions.length;q<v;q++){t=this._collisions[q];if(!t.satisfied){if(w){s=this.processContactFn(t,l);n=n||s;}else{s=this.processCollisionFn(t,l);n=n||s;}}}for(var q=0,v=this._constraints.length;q<v;q++){var p=this._constraints[q];if(!p.get_satisfied()){s=p.apply(l);n=n||s;}}this.tryToActivateAllFrozenObjects();if(w){r=this._collisions.length;for(var o=x;o<r;o++){this._collisions[o].mat.set_restitution(0);this._collisions[o].satisfied=false;this.preProcessContactFn(this._collisions[o],l);}}else{r=this._collisions.length;for(o=x;o<r;o++){this.preProcessCollisionFn(this._collisions[o],l);}}x=this._collisions.length;if(!n){break;}}};f.prototype.handleAllEffects=function(){var m;var l=this._effects.length-1;if(l<0){return;}do{m=this._effects[l];if(m.enabled){m.Apply();}}while(l--);};f.prototype.activateObject=function(n){if(!n.get_movable()||n.isActive){return;}n.setActive();this._activeBodies.push(n);var p=this._collisions.length;this._collisionSystem.detectCollisions(n,this._collisions);var m;var q;for(var o=p,l=this._collisions.length;o<l;o++){m=this._collisions[o].objInfo.body0;q=this._collisions[o].dirToBody;if(m==n){m=this._collisions[o].objInfo.body1;q=b.getScaleVector(this._collisions[o].dirToBody,-1);}if(!m.isActive&&k.dotProduct(m.get_force(),q)<-b.NUM_TINY){this.activateObject(m);}}};f.prototype.dampAllActiveBodies=function(){for(var l=0,m=this._activeBodies.length;l<m;l++){_activeBody=this._activeBodies[l];_activeBody.dampForDeactivation();}};f.prototype.tryToActivateAllFrozenObjects=function(){for(var l=0,n=this._bodies.length;l<n;l++){var m=this._bodies[l];if(!m.isActive){if(m.getShouldBeActive()){this.activateObject(m);}else{if(m.getVelChanged()){m.setVelocity([0,0,0,0]);m.setAngVel([0,0,0,0]);m.clearVelChanged();}}}}};f.prototype.activateAllFrozenObjectsLeftHanging=function(){var l;for(var n=0,q=this._bodies.length;n<q;n++){var p=this._bodies[n];if(p.isActive){p.doMovementActivations();if(p.collisions.length>0){for(var m=0,o=p.collisions.length;m<o;m++){l=p.collisions[m].objInfo.body0;if(l==p){l=p.collisions[m].objInfo.body1;}if(!l.isActive){p.addMovementActivation(p.get_currentState().position,l);}}}}}};f.prototype.updateAllVelocities=function(m){for(var l=0,n=this._activeBodies.length;l<n;l++){_activeBody=this._activeBodies[l];_activeBody.updateVelocity(m);}};f.prototype.updateAllPositions=function(m){for(var l=0,n=this._activeBodies.length;l<n;l++){_activeBody=this._activeBodies[l];_activeBody.updatePositionWithAux(m);}};f.prototype.notifyAllPostPhysics=function(m){for(var l=0,n=this._bodies.length;l<n;l++){_body=this._bodies[l];_body.postPhysics(m);}};f.prototype.updateAllObject3D=function(){for(var l=0,m=this._bodies.length;l<m;l++){_body=this._bodies[l];_body.updateObject3D();}};f.prototype.limitAllVelocities=function(){for(var l=0,m=this._activeBodies.length;l<m;l++){_activeBody=this._activeBodies[l];_activeBody.limitVel();_activeBody.limitAngVel();}};f.prototype.tryToFreezeAllObjects=function(m){for(var l=0,n=this._activeBodies.length;l<n;l++){_activeBody=this._activeBodies[l];_activeBody.tryToFreeze(m);}};f.prototype.detectAllCollisions=function(m){for(var l=0,n=this._activeBodies.length;l<n;l++){_activeBody=this._activeBodies[l];_activeBody.storeState();}this.updateAllVelocities(m);this.updateAllPositions(m);for(var l=0,o=this._bodies.length;l<o;l++){_body=this._bodies[l];_body.collisions=[];}this._collisions=[];this._collisionSystem.detectAllCollisions(this._activeBodies,this._collisions);for(var l=0,n=this._activeBodies.length;l<n;l++){_activeBody=this._activeBodies[l];_activeBody.restoreState();}};f.prototype.copyAllCurrentStatesToOld=function(){for(var l=0,m=this._bodies.length;l<m;l++){_body=this._bodies[l];if(_body.isActive||_body.getVelChanged()){_body.copyCurrentStateToOld();}}};f.prototype.findAllActiveBodies=function(){this._activeBodies=[];for(var l=0,n=this._bodies.length;l<n;l++){var m=this._bodies[l];if(m.isActive){this._activeBodies.push(m);}}};f.prototype.integrate=function(m){this._doingIntegration=true;this.findAllActiveBodies();this.copyAllCurrentStatesToOld();this.getAllExternalForces(m);this.handleAllEffects();this.detectAllCollisions(m);this.handleAllConstraints(m,h.numCollisionIterations,false);this.updateAllVelocities(m);this.handleAllConstraints(m,h.numContactIterations,true);if(h.doShockStep){this.doShockStep(m);}this.dampAllActiveBodies();this.tryToFreezeAllObjects(m);this.activateAllFrozenObjectsLeftHanging();this.limitAllVelocities();this.updateAllPositions(m);this.notifyAllPostPhysics(m);this.updateAllObject3D();if(h.solverType=="ACCUMULATED"){this.updateContactCache();}for(var l=0,n=this._bodies.length;l<n;l++){_body=this._bodies[l];_body.clearForces();}this._doingIntegration=false;};d.PhysicsSystem=f;})(jigLib);(function(e){var j=e.Vector3DUtil;var a=e.JNumber3D;var b=e.JChassis;var d=e.JWheel;var f=e.PhysicsSystem;var c=Math,i=c.abs,h=c.sqrt;var g=function(k){this._chassis=new b(this,k);this._wheels=[];this._steerWheels=[];this._destSteering=this._destAccelerate=this._steering=this._accelerate=this._HBrake=0;this.setCar();};g.prototype._maxSteerAngle=null;g.prototype._steerRate=null;g.prototype._driveTorque=null;g.prototype._destSteering=null;g.prototype._destAccelerate=null;g.prototype._steering=null;g.prototype._accelerate=null;g.prototype._HBrake=null;g.prototype._chassis=null;g.prototype._wheels=null;g.prototype._steerWheels=null;g.prototype.setCar=function(m,l,k){if(m==null){m=45;}if(l==null){l=4;}if(k==null){k=500;}this._maxSteerAngle=m;this._steerRate=l;this._driveTorque=k;};g.prototype.setupWheel=function(y,o,t,w,m,D,C,p,s,z){if(t==null){t=2;}if(w==null){w=2;}if(m==null){m=3;}if(D==null){D=10;}if(C==null){C=0.5;}if(p==null){p=0.5;}if(s==null){s=1;}if(z==null){z=1;}var n=f.getInstance().get_gravity().slice(0);var v=this._chassis.get_mass();var q=0.25*v;var A=j.get_length(n);j.normalize(n);var k=a.getScaleVector(n,-1);var u=q*A/(C*m);var r=0.015*D*D*v;var l=p/2;var x=A*q;var B=new d(this);B.name=y;B.setup(o,k,u,m,r,D,t,w,l,s,z,x);this._wheels.push(B);};g.prototype.setAccelerate=function(k){this._destAccelerate=k;};g.prototype.setSteer=function(p,o){this._destSteering=o;this._steerWheels=[];var m=null;for(var n=0,k=p.length;n<k;n++){m=this.getWheel(p[n]);if(m){this._steerWheels.push(m);}}};g.prototype.findWheel=function(m){for(var n=0,k=this._wheels.length;n<k;n++){if(this._wheels[n].name==m){return true;}}return false;};g.prototype.getWheel=function(k){for(var l=0;l<this._wheels.length;l++){if(this._wheels[l].name==k){return this._wheels[l];}}return null;};g.prototype.setHBrake=function(k){this._HBrake=k;};g.prototype.addExternalForces=function(l){for(var k=0,m=this._wheels.length;k<m;k++){this._wheels[k].addForcesToCar(l);}};g.prototype.postPhysics=function(l){for(var o=0,t=this._wheels.length;o<t;o++){this._wheels[o].update(l);}var k=l;var q=l*this._steerRate;var m=this._destAccelerate-this._accelerate;if(m<-k){m=-k;}else{if(m>k){m=k;}}this._accelerate+=m;var r=this._destSteering-this._steering;if(r<-q){r=-q;}else{if(r>q){r=q;}}this._steering+=r;for(var o=0;o<this._wheels.length;o++){this._wheels[o].addTorque(this._driveTorque*this._accelerate);this._wheels[o].setLock(this._HBrake>0.5);}var n=i(this._maxSteerAngle*this._steering);var p=(this._steering>0)?1:-1;for(var o=0,s=this._steerWheels.length;o<s;o++){this._steerWheels[o].setSteerAngle(p*n);}};g.prototype.getNumWheelsOnFloor=function(m){var l=0;for(var k=0,n=this._wheels.length;k<n;k++){if(this._wheels[k].getOnFloor()){l++;}}return l;};e.JCar=g;})(jigLib);(function(b){var a=b.JBox;var c=function(e,g,f,h,d){if(f==null){f=40;}if(h==null){h=70;}if(d==null){d=30;}this.Super(g,f,h,d);this._car=e;};b.extend(c,b.JBox);c.prototype._car=null;c.prototype.addExternalForces=function(d){this.clearForces();this.addGravity();this._car.addExternalForces(d);};c.prototype.postPhysics=function(d){this._car.postPhysics(d);};b.JChassis=c;})(jigLib);(function(e){var n=e.Vector3DUtil;var g=e.JMatrix3D;var a=e.JNumber3D;var o=e.JSegment;var i=e.JConfig;var h=e.PhysicsSystem;var b=Math,f=b.PI,d=b.min,j=b.max,l=b.cos,m=b.abs,k=b.sqrt;var c=function(p){this._car=p;};c.prototype.name=null;c.prototype.noslipVel=0.2;c.prototype.slipVel=0.4;c.prototype.slipFactor=0.7;c.prototype.smallVel=3;c.prototype._car=null;c.prototype._pos=null;c.prototype._axisUp=null;c.prototype._spring=null;c.prototype._travel=null;c.prototype._inertia=null;c.prototype._radius=null;c.prototype._sideFriction=null;c.prototype._fwdFriction=null;c.prototype._damping=null;c.prototype._numRays=null;c.prototype._angVel=null;c.prototype._steerAngle=null;c.prototype._torque=null;c.prototype._driveTorque=null;c.prototype._axisAngle=null;c.prototype._displacement=null;c.prototype._upSpeed=null;c.prototype._rotDamping=null;c.prototype._normalForce=null;c.prototype._locked=null;c.prototype._lastDisplacement=null;c.prototype._lastOnFloor=null;c.prototype._angVelForGrip=null;c.prototype.worldPos=null;c.prototype.worldAxis=null;c.prototype.wheelFwd=null;c.prototype.wheelUp=null;c.prototype.wheelLeft=null;c.prototype.wheelRayEnd=null;c.prototype.wheelRay=null;c.prototype.groundUp=null;c.prototype.groundLeft=null;c.prototype.groundFwd=null;c.prototype.wheelPointVel=null;c.prototype.rimVel=null;c.prototype.worldVel=null;c.prototype.wheelCentreVel=null;c.prototype._collSystem=null;c.prototype.setup=function(x,u,z,q,v,w,r,t,s,y,A,p){if(z==null){z=0;}if(q==null){q=0;}if(v==null){v=0;}if(w==null){w=0;}if(r==null){r=0;}if(t==null){t=0;}if(s==null){s=0;}if(y==null){y=0;}if(A==null){A=0;}if(p==null){p=0;}this._pos=x;this._axisUp=u;this._spring=z;this._travel=q;this._inertia=v;this._radius=w;this._sideFriction=r;this._fwdFriction=t;this._damping=s;this._numRays=y;this._drive=A;this._normalForce=p;this._torque=0;this.reset();};c.prototype.addTorque=function(p){this._driveTorque+=p;};c.prototype.setLock=function(p){this._locked=p;};c.prototype.setSteerAngle=function(p){this._steerAngle=p;};c.prototype.getSteerAngle=function(){return this._steerAngle;};c.prototype.getPos=function(){return this._pos;};c.prototype.getLocalAxisUp=function(){return this._axisUp;};c.prototype.getActualPos=function(){return n.add(this._pos,a.getScaleVector(this._axisUp,this._displacement));};c.prototype.getRadius=function(){return this._radius;};c.prototype.getDisplacement=function(){return this._displacement;};c.prototype.getAxisAngle=function(){return this._axisAngle;};c.prototype.getRollAngle=function(){return 0.1*this._angVel*180/f;};c.prototype.setRotationDamping=function(p){this._rotDamping=p;};c.prototype.getRotationDamping=function(){return this._rotDamping;};c.prototype.getOnFloor=function(){return this._lastOnFloor;};c.prototype.addForcesToCar=function(O){var q=[0,0,0,0];this._lastDisplacement=this._displacement;this._displacement=0;var X=this._car._chassis;worldPos=this._pos.slice(0);g.multiplyVector(X.get_currentState().get_orientation(),worldPos);worldPos=n.add(X.get_currentState().position,worldPos);worldAxis=this._axisUp.slice(0);g.multiplyVector(X.get_currentState().get_orientation(),worldAxis);wheelFwd=X.get_currentState().getOrientationCols()[2].slice(0);g.multiplyVector(g.getRotationMatrix(worldAxis[0],worldAxis[1],worldAxis[2],this._steerAngle/180*2*Math.PI),wheelFwd);wheelUp=worldAxis;wheelLeft=n.crossProduct(wheelUp,wheelFwd);n.normalize(wheelLeft);var W=2*this._radius+this._travel;wheelRayEnd=n.subtract(worldPos,a.getScaleVector(worldAxis,this._radius));wheelRay=new o(n.add(wheelRayEnd,a.getScaleVector(worldAxis,W)),a.getScaleVector(worldAxis,-W));if(this._collSystem==null){this._collSystem=h.getInstance().getCollisionSystem();}var U=10;var s=d(this._numRays,U);var w=[];var S=[];var A=(2*this._radius)/(s+1);var V=A;this._lastOnFloor=false;var y;var H;var C=0;var K=0;var p=null;for(K=0;K<s;K++){w[K]={};y=(V+K*A)-this._radius;H=this._radius*(1-l(90*(y/this._radius)*f/180));p=wheelRay.clone();p.origin=n.add(p.origin,n.add(a.getScaleVector(wheelFwd,y),a.getScaleVector(wheelUp,H)));if(this._collSystem.segmentIntersect(w[K],p,X)){this._lastOnFloor=true;if(w[K].fracOut<w[C].fracOut){C=K;}}S[K]=p;}if(!this._lastOnFloor){return false;}var u=w[C].fracOut;var N=w[C].posOut;var L=w[C].bodyOut;var Q=worldAxis.slice(0);if(s>1){for(K=0;K<s;K++){var F=w[K].fracOut;if(F<=1){Q=n.add(Q,a.getScaleVector(n.subtract(worldPos,S[K].getEnd()),1-F));}}n.normalize(Q);}else{Q=w[C].normalOut;}wheelFwd=n.crossProduct(wheelLeft,Q);this._displacement=W*(1-u);if(this._displacement<0){this._displacement=0;}var P=X.get_mass();var E=P/4;var r=L.get_friction();var J=X.getVelocity(this._pos);var x=this._displacement;if(this._displacement>this._travel){this._displacement=this._travel;var v=n.dotProduct(J,Q)/O*E;v=v*2*L.get_restitution()/10;z=a.getScaleVector(Q,-v);q=n.add(q,z);}z=a.getScaleVector(this._axisUp,this._spring*this._displacement+this._upSpeed*this._damping);q=n.add(q,z);groundUp=Q;groundLeft=n.crossProduct(Q,wheelFwd);n.normalize(groundLeft);groundFwd=n.crossProduct(groundLeft,groundUp);var R=a.getScaleVector(n.crossProduct(groundLeft,n.subtract(N,worldPos)),-this._angVel);var t=a.getScaleVector(groundFwd,n.dotProduct(J,groundFwd));var B=this._fwdFriction*r;var z=a.getScaleVector(n.subtract(R,t),E/O/this._radius*B);var G=n.get_length(z);if(G>this._normalForce*B){z=a.getScaleVector(z,this._normalForce*B/G);}q=n.add(q,z);this._torque-=n.dotProduct(n.subtract(R,t),groundFwd)/this._radius*E/O;this._angVelForGrip=n.dotProduct(J,groundFwd)/this._radius;var D=n.dotProduct(J,groundLeft);var B=this._sideFriction*r;var T=a.getScaleVector(groundLeft,-D*B);var z=a.getScaleVector(T,E/O/this._radius);var G=n.get_length(z);if(G>this._normalForce*B){z=a.getScaleVector(z,this._normalForce*B/G);}q=n.add(q,z);X.addWorldForce(q,N);if(L.get_movable()){var I=500;var M=I*L.get_mass();if(n.get_lengthSquared(q)>(M*M)){q=a.getScaleVector(q,M/n.get_length(q));}L.addWorldForce(a.getScaleVector(q,-1),N);}return true;};c.prototype.update=function(q){if(q<=0){return;}var p=this._angVel;this._upSpeed=(this._displacement-this._lastDisplacement)/j(q,a.NUM_TINY);if(this._locked){this._angVel=0;this._torque=0;}else{this._angVel+=(this._torque*q/this._inertia);this._torque=0;if(((p>this._angVelForGrip)&&(this._angVel<this._angVelForGrip))||((p<this._angVelForGrip)&&(this._angVel>this._angVelForGrip))){this._angVel=this._angVelForGrip;}this._angVel+=this._driveTorque*q/this._inertia*this._drive;this._driveTorque=0;if(this._angVel<-100){this._angVel=-100;}else{if(this._angVel>100){this._angVel=100;}}this._angVel*=this._rotDamping;this._axisAngle+=(this._angVel*q*180/f);}};c.prototype.reset=function(){this._angVel=0;this._steerAngle=0;this._torque=0;this._driveTorque=0;this._axisAngle=0;this._displacement=0;this._upSpeed=0;this._locked=false;this._lastDisplacement=0;this._lastOnFloor=false;this._angVelForGrip=0;this._rotDamping=0.99;};e.JWheel=c;})(jigLib);
@@ -0,0 +1,223 @@
1
+ /**
2
+ * Container of physics systems
3
+ */
4
+ define(
5
+ function () {
6
+
7
+ // Physics systems
8
+ var items = {};
9
+
10
+ return {
11
+
12
+ /**
13
+ * Acquire a physics system for the given SceneJS scene, creating first if not existing
14
+ * @param {SceneJS.Scene} scene
15
+ * @param {String} [systemId] Optional systemId
16
+ */
17
+ getSystem:function (scene, systemId) {
18
+ systemId = systemId ? scene.getId() + "." + systemId : scene.getId();
19
+ var item = items[systemId];
20
+ if (item) {
21
+ item.useCount++;
22
+ return item.system;
23
+ }
24
+ var system = new System(systemId);
25
+ items[systemId] = {
26
+ useCount:1,
27
+ system:system,
28
+ scene:scene,
29
+ tick:scene.on("tick", // Start integrating the system on scene tick
30
+ function () {
31
+ system.integrate();
32
+ })
33
+ };
34
+ return system;
35
+ },
36
+
37
+ /**
38
+ * Release a physics system, destroying it if no more users
39
+ * @param {System} system
40
+ */
41
+ putSystem:function (system) {
42
+ var item = items[system.systemId];
43
+ if (item) {
44
+ if (item.useCount-- <= 0) {
45
+ item.system.destroy();
46
+ item.scene.off(item.tick); // Stop integrating the system
47
+ delete items[system.systemId];
48
+ }
49
+ }
50
+ }
51
+ };
52
+
53
+ /**
54
+ * A physics system
55
+ */
56
+ function System(systemId) {
57
+
58
+ this.systemId = systemId;
59
+
60
+ // Maximum number of bodies supported
61
+ var maxBodies = 10000;
62
+
63
+ var bodies = [];
64
+ var map = new Map(bodies);
65
+
66
+ // Create physics engine in worker
67
+ var workerPath = SceneJS.getConfigs().pluginPath + "/lib/physics/worker.js";
68
+ var worker = new Worker(workerPath);
69
+
70
+ var workerOutputBuf = new ArrayBuffer(maxBodies * 20);
71
+
72
+ // True while worker is busy integrating
73
+ // We don't send integration requests to it while this is true
74
+ var integrating = false;
75
+
76
+ // System is integrating only when this true
77
+ var enabled = true;
78
+
79
+ // Route updates from physics engine to bodies
80
+ worker.addEventListener('message',
81
+ function (e) {
82
+
83
+ var data = e.data;
84
+ workerOutputBuf = data.buffer; // Worker transfers ownership of buffer to us
85
+ var output = new Float32Array(workerOutputBuf);
86
+ var lenOutput = data.lenOutput;
87
+ var bodyId;
88
+ var body;
89
+
90
+ // The data buffer from the web worker contains a 20-element portion for
91
+ // each physics body, each of which contains the body ID, a new position,
92
+ // and a 16-element rotation matrix:
93
+ //
94
+ // [
95
+ // bodyId, xPos, yPos, zPos, mat0, ... mat15,
96
+ // bodyId, xPos, yPos, zPos, mat0, ... mat15,
97
+ // ...
98
+ // ]
99
+ for (var i = 0, len = lenOutput - 20; i < len; i += 20) {
100
+ bodyId = Math.round(output[i]); // First element for body ID
101
+ body = bodies[bodyId];
102
+ if (body) { // May have been deleted
103
+ body.callback(
104
+ output.subarray(i + 1, i + 4),
105
+ null);
106
+ // , // 3 elements for position
107
+ // output.subarray(i + 4, i + 20)); // 16 elements for rotation matrix
108
+ }
109
+ }
110
+
111
+ integrating = false;
112
+
113
+ }, false);
114
+
115
+ /**
116
+ * Configures this physics system
117
+ * @param params Values for configs
118
+ */
119
+ this.setConfigs = function (params) {
120
+ worker.postMessage({ cmd:"setConfigs", configs:params });
121
+ };
122
+
123
+ /**
124
+ * Enable or disable this physics system.
125
+ * To save on CPU, you would typically disable the system when its not in view.
126
+ * @param enable
127
+ */
128
+ this.setEnabled = function (enable) {
129
+ enabled = enable;
130
+ };
131
+
132
+ /**
133
+ * Creates a physics body, returns it's unique ID
134
+ * @param params Body params
135
+ * @param callback Callback fired whenever body updated
136
+ * @return Body ID
137
+ */
138
+ this.createBody = function (params, callback) {
139
+ var bodyId = map.add({
140
+ callback:callback
141
+ });
142
+ worker.postMessage({ cmd:"createBody", bodyId:bodyId, bodyCfg:params });
143
+ return bodyId;
144
+ };
145
+
146
+ /**
147
+ * Updates an existing physics body
148
+ * @param bodyId Body ID
149
+ * @param params Body params
150
+ */
151
+ this.updateBody = function (bodyId, params) {
152
+ worker.postMessage({ cmd:"updateBody", bodyId:bodyId, bodyCfg:params });
153
+ };
154
+
155
+ /**
156
+ * Removes a physics body
157
+ */
158
+ this.removeBody = function (bodyId) {
159
+ worker.postMessage({ cmd:"removeBody", bodyId:bodyId });
160
+ map.remove(bodyId);
161
+ };
162
+
163
+ /**
164
+ * Integrates this physics system
165
+ * Does nothing when system is disabled with {@link System#setEnabled}
166
+ */
167
+ this.integrate = function () {
168
+
169
+ if (!enabled) {
170
+ return;
171
+ }
172
+
173
+ if (integrating) { // Don't choke worker
174
+ return;
175
+ }
176
+
177
+ integrating = true;
178
+
179
+ // Transfer ownership of output buffer to the worker
180
+ var msg = {
181
+ cmd:"integrate",
182
+ buffer:workerOutputBuf
183
+ };
184
+ worker.postMessage(msg, [msg.buffer]);
185
+ };
186
+
187
+ /**
188
+ * Destroys system, terminating its worker
189
+ */
190
+ this.destroy = function () {
191
+ worker.terminate();
192
+ };
193
+ }
194
+
195
+ /**
196
+ * Uniquely ID'd map of items
197
+ * @param items Array that will contain the items
198
+ */
199
+ function Map(items) {
200
+ this.add = function (item) {
201
+
202
+ // Start looking from the beginning of the array
203
+ // because we don't want an infinitely-expanding
204
+ // sparse array as we remove then add nodes.
205
+
206
+ // We're trading insertion overhead for the benefit
207
+ // of a nicely packed array that's fast to traverse
208
+ // when posting updates back to the physics body nodes.
209
+
210
+ var i = 0;
211
+ while (true) {
212
+ if (!items[i]) {
213
+ items[i] = item;
214
+ return i;
215
+ }
216
+ i++;
217
+ }
218
+ };
219
+ this.remove = function (id) {
220
+ delete items[id];
221
+ };
222
+ }
223
+ });
@@ -0,0 +1,330 @@
1
+ /**
2
+ * Web worker containing a JigLibJS rigid-body physics system.
3
+ *
4
+ * This worker accepts various commands to configure the system, add or
5
+ * remove bodies, and integrate (which means run the system for one frame).
6
+ *
7
+ * After each integration, this worker posts back an array buffer containing
8
+ * an updated position and direction for each body.
9
+ *
10
+ *
11
+ * Input Commands
12
+ * --------------------------------------------------------------------------
13
+ *
14
+ * Configure the system:
15
+ * {
16
+ * cmd: "setConfigs",
17
+ * //..configs
18
+ * }
19
+ *
20
+ * Create a body:
21
+ * {
22
+ * cmd: "createBody",
23
+ * bodyId: Number,
24
+ * bodyCfg: {
25
+ * shape: "plane" | "box" | "sphere",
26
+ * movable: true | false,
27
+ * pos: [Number, Number, Number],
28
+ * mass: Number,
29
+ * restitution: Number,
30
+ * friction: Number,
31
+ * velocity: [Number, Number, Number]
32
+ * }
33
+ * }
34
+ *
35
+ * Remove a body:
36
+ * {
37
+ * cmd: "removeBody",
38
+ * bodyId: Number
39
+ * }
40
+ *
41
+ * Update a body:
42
+ * {
43
+ * cmd: "updateBody",
44
+ * bodyId: Number,
45
+ * bodyCfg: {
46
+ * movable: true | false,
47
+ * pos: [Number, Number, Number],
48
+ * mass: Number,
49
+ * restitution: Number,
50
+ * friction: Number,
51
+ * velocity: [Number, Number, Number]
52
+ * }
53
+ * }
54
+ *
55
+ * Integrate the phsycis system:
56
+ * {
57
+ * cmd: "integrate"
58
+ * }
59
+ *
60
+ *
61
+ * For efficiency, the physics system manages bodies in an array. The "bodyId"
62
+ * parameter on the "createBody" command is the index for that body in the array.
63
+ *
64
+ * The "removeBody" command will delete a body from the array, leaving a hole.
65
+ *
66
+ * The worker can handle holes in the array OK, but in order to keep the array
67
+ * from getting too sparse, it's the reponsibility of the worker client to make
68
+ * its next "createBody" command specify a "bodyId" that indexes that hole, to plug
69
+ * the gap with the next new body.
70
+ *
71
+ *
72
+ * Output Buffer
73
+ * --------------------------------------------------------------------------
74
+ *
75
+ * The output buffer contains a 20-element portion for each physics body, each of
76
+ * which contains the body ID, a new position, and a 16-element rotation matrix:
77
+ *
78
+ * [
79
+ * bodyId, xPos, yPos, zPos, mat0, ... mat15,
80
+ * bodyId, xPos, yPos, zPos, mat0, ... mat15,
81
+ * ...
82
+ * ]
83
+ *
84
+ */
85
+ importScripts(((location.protocol.length === 0) ? 'http://' : location.protocol + '//') + location.host + '/scenejs/get_scenejs_data?file=' + "/lib/physics/jiglib.all.min.js");
86
+
87
+ var bodies = [];
88
+ var numBodies = 0;
89
+
90
+ // Array in which this worker posts back
91
+ // an updated position and direction for each body
92
+ var output;
93
+
94
+ // Physics engine system
95
+ var system = jigLib.PhysicsSystem.getInstance();
96
+
97
+ // Set initial default configuration for physics system
98
+ setConfigs();
99
+
100
+ /** Configures JigLibJS
101
+ */
102
+ function setConfigs(params) {
103
+ params = params || {};
104
+ system.setGravity(params.gravity || [0, -9.8, 0, 0]); //-120
105
+ system.setSolverType(params.solver || 'ACCUMULATED'); //FAST, NORMAL, ACCUMULATED
106
+ }
107
+
108
+ // System starts immediately
109
+ var then = (new Date()).getTime();
110
+
111
+ // Handle command from worker owner
112
+ addEventListener("message",
113
+ function (e) {
114
+
115
+ var data = e.data;
116
+
117
+ switch (data.cmd) {
118
+
119
+ // Configure the physics system
120
+ case "setConfigs":
121
+ setConfigs(data.configs);
122
+ break;
123
+
124
+ // Create a physics body
125
+ case "createBody":
126
+
127
+ var bodyId = data.bodyId;
128
+ var bodyCfg = data.bodyCfg;
129
+ var shape = bodyCfg.shape;
130
+ var body;
131
+
132
+ switch (shape) {
133
+
134
+ case "plane":
135
+ body = new jigLib.JPlane(null, bodyCfg.dir || [0, 1, 0]);
136
+ break;
137
+
138
+ case "box":
139
+ body = new jigLib.JBox(null, bodyCfg.width || 1.0, bodyCfg.depth || 1.0, bodyCfg.height || 1.0);
140
+ break;
141
+
142
+ case "sphere":
143
+ body = new jigLib.JSphere(null, bodyCfg.radius || 1.0);
144
+ break;
145
+
146
+ default:
147
+ // Unsupported body type
148
+ return;
149
+ }
150
+
151
+ bodies[bodyId] = {
152
+ body:body,
153
+ spherical:shape == "sphere"
154
+ };
155
+
156
+ system.addBody(body);
157
+
158
+ if (bodyCfg.movable != undefined) {
159
+ body.set_movable(!!bodyCfg.movable);
160
+ }
161
+
162
+ if (bodyCfg.pos) {
163
+ body.moveTo(bodyCfg.pos);
164
+ }
165
+
166
+ if (bodyCfg.mass != undefined) {
167
+ body.set_mass(bodyCfg.mass);
168
+ }
169
+
170
+ if (bodyCfg.restitution != undefined) {
171
+ body.set_restitution(bodyCfg.restitution);
172
+ }
173
+
174
+ if (bodyCfg.friction != undefined) {
175
+ body.set_friction(bodyCfg.friction);
176
+ }
177
+
178
+ if (bodyCfg.velocity != undefined) {
179
+ body.setVelocity(bodyCfg.velocity);
180
+ }
181
+
182
+ numBodies++;
183
+
184
+ break;
185
+
186
+ // Update a physics body
187
+ case "updateBody":
188
+
189
+ var bodyId = data.bodyId;
190
+ var body = bodies[bodyId].body;
191
+
192
+ if (!body) {
193
+ return;
194
+ }
195
+
196
+ var bodyCfg = data.bodyCfg;
197
+
198
+ if (bodyCfg.movable != undefined) {
199
+ body.set_movable(!!bodyCfg.movable);
200
+ }
201
+
202
+ if (bodyCfg.pos) {
203
+ body.moveTo(bodyCfg.pos);
204
+ }
205
+
206
+ if (bodyCfg.mass != undefined) {
207
+ body.set_mass(bodyCfg.mass);
208
+ }
209
+
210
+ if (bodyCfg.restitution != undefined) {
211
+ body.set_restitution(bodyCfg.restitution);
212
+ }
213
+
214
+ if (bodyCfg.friction != undefined) {
215
+ body.set_friction(bodyCfg.friction);
216
+ }
217
+
218
+ if (bodyCfg.velocity != undefined) {
219
+ body.setVelocity(bodyCfg.velocity);
220
+ }
221
+
222
+ break;
223
+
224
+ // Remove a physics body
225
+ case "removeBody":
226
+ var body = bodies[data.bodyId];
227
+ if (!body) {
228
+ return;
229
+ }
230
+ bodies[data.bodyId] = null;
231
+ system.removeBody(body);
232
+ numBodies--;
233
+ break;
234
+
235
+ // Integrate the physics system and post back the body updates
236
+ case "integrate":
237
+
238
+ var output = new Float32Array(data.buffer);
239
+
240
+ var now = (new Date()).getTime();
241
+
242
+ // if (numBodies > 0) { // Only integrate and post if there are bodies
243
+
244
+ var secs = (now - then) / 1000;
245
+ var item;
246
+ var body;
247
+ var spherical;
248
+ var state;
249
+ var pos;
250
+ var dir;
251
+ var ibuf = 0;
252
+
253
+ system.integrate(secs);
254
+
255
+ for (var bodyId = 0, ibody = 0; ibody < numBodies; bodyId++) {
256
+
257
+ item = bodies[bodyId];
258
+
259
+ if (!item) { // Deleted
260
+ continue;
261
+ }
262
+
263
+ body = item.body;
264
+ spherical = item.spherical;
265
+
266
+ state = body.get_currentState();
267
+
268
+ // Body ID
269
+ output[ibuf++] = bodyId;
270
+
271
+ // New position
272
+
273
+ pos = state.position;
274
+
275
+ output[ibuf++] = pos[0];
276
+ output[ibuf++] = pos[1];
277
+ output[ibuf++] = pos[2];
278
+
279
+ if (spherical) {
280
+
281
+ // No rotation necessary for spheres
282
+ ibuf += 16;
283
+
284
+ } else {
285
+
286
+ // New rotation matrix
287
+
288
+ dir = state.get_orientation().glmatrix;
289
+
290
+ output[ibuf++] = dir[0];
291
+ output[ibuf++] = dir[1];
292
+ output[ibuf++] = dir[2];
293
+ output[ibuf++] = dir[3];
294
+ output[ibuf++] = dir[4];
295
+ output[ibuf++] = dir[5];
296
+ output[ibuf++] = dir[6];
297
+ output[ibuf++] = dir[7];
298
+ output[ibuf++] = dir[8];
299
+ output[ibuf++] = dir[9];
300
+ output[ibuf++] = dir[10];
301
+ output[ibuf++] = dir[11];
302
+ output[ibuf++] = dir[12];
303
+ output[ibuf++] = dir[13];
304
+ output[ibuf++] = dir[14];
305
+ output[ibuf++] = dir[15];
306
+ }
307
+
308
+ ibody++; // Next body;
309
+ }
310
+
311
+ // Post the output
312
+
313
+ var response = {
314
+ buffer:output.buffer,
315
+ lenOutput:ibuf - 20
316
+ };
317
+
318
+ self.postMessage(response, [response.buffer]);
319
+
320
+ then = now;
321
+
322
+ break;
323
+
324
+ default:
325
+
326
+
327
+ break;
328
+ }
329
+ }, false);
330
+