WT_DECLARE_WT_MEMBER(1,JavaScriptConstructor,"WGLWidget",function(E,h){function F(){for(var c=jQuery.data(h,"obj"),d="",l=0;l<c.jsValues.length;l++){d+=l+":";for(var o=0;o<c.jsValues[l].length;o++){d+=c.jsValues[l][o];d+=o!==c.jsValues[l].length-1?",":";"}}return d}jQuery.data(h,"obj",this);var w=this,g=E.WT,q=g.glMatrix.vec3,j=g.glMatrix.mat4;this.ctx=null;this.initializeGL=function(){};this.paintGL=function(){};this.resizeGL=function(){};this.updates=[];this.initialized=false;this.preloadingBuffers=
this.preloadingTextures=0;this.jsValues=[];this.discoverContext=function(c,d){if(h.getContext){try{this.ctx=h.getContext("webgl",{antialias:d})}catch(l){}if(this.ctx===null)try{this.ctx=h.getContext("experimental-webgl",{antialias:d})}catch(o){}if(this.ctx===null){h.parentNode.insertBefore(h.firstChild,h);h.style.display="none";c()}}return this.ctx};if(h.addEventListener){h.addEventListener("webglcontextlost",function(c){c.preventDefault();w.initialized=false},false);h.addEventListener("webglcontextrestored",
function(){Wt.emit(h,"contextRestored")},false)}var e=null;this.setMouseHandler=function(c){e=c;e.setTarget&&e.setTarget(this)};this.LookAtMouseHandler=function(c,d,l,o,x){function y(a){a=Math.pow(1.2,a);j.translate(f,i);j.scale(f,[a,a,a]);q.negate(i);j.translate(f,i);q.negate(i);w.paintGL()}function z(a){var b=f[5]/q.length([f[1],f[5],f[9]]),m=f[6]/q.length([f[2],f[6],f[10]]);b=Math.atan2(m,b);m=a.x-p.x;var v=a.y-p.y,A=q.create();A[0]=f[0];A[1]=f[4];A[2]=f[8];var r=j.create();j.identity(r);j.translate(r,
i);v=v*s;if(Math.abs(b+v)>=Math.PI/2)v=(b>0?1:-1)*Math.PI/2-b;j.rotate(r,v,A);j.rotate(r,m*G,k);q.negate(i);j.translate(r,i);q.negate(i);j.multiply(f,r,f);w.paintGL();p=a}var f=c,i=d,k=l,s=o,G=x,C=null,t=null,u=null,p=null,D=this;this.mouseDown=function(a,b){g.capture(null);g.capture(h);p=g.pageCoordinates(b)};this.mouseUp=function(){if(p!==null)p=null};this.mouseDrag=function(a,b){if(p!==null){a=g.pageCoordinates(b);g.buttons===1&&z(a)}};this.mouseWheel=function(a,b){g.cancelEvent(b);a=g.wheelDelta(b);
y(a)};this.touchStart=function(a,b){t=b.touches.length===1?true:false;u=b.touches.length===2?true:false;if(t){g.capture(null);g.capture(h);p=g.pageCoordinates(b.touches[0])}else if(u){a=g.pageCoordinates(b.touches[0]);var m=g.pageCoordinates(b.touches[1]);C=Math.sqrt((a.x-m.x)*(a.x-m.x)+(a.y-m.y)*(a.y-m.y))}else return;b.preventDefault()};this.touchEnd=function(a,b){var m=b.touches.length===0?true:false;t=b.touches.length===1?true:false;u=b.touches.length===2?true:false;m&&D.mouseUp(null,null);if(t||
u)D.touchStart(a,b)};this.touchMoved=function(a,b){if(t||u){b.preventDefault();if(t){if(p===null)return;a=g.pageCoordinates(b);z(a)}if(u){a=g.pageCoordinates(b.touches[0]);b=g.pageCoordinates(b.touches[1]);b=Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));a=b/C;if(!(Math.abs(a-1)<0.05)){a=a>1?1:-1;C=b;y(a)}}}}};this.WalkMouseHandler=function(c,d,l){function o(i){var k=i.x-f.x;i=i.y-f.y;var s=j.create();j.identity(s);j.rotateY(s,k*z);k=q.create();k[0]=0;k[1]=0;k[2]=-y*i;j.translate(s,k);j.multiply(s,
x,x);w.paintGL();f=g.pageCoordinates(event)}var x=c,y=d,z=l,f=null;this.mouseDown=function(i,k){g.capture(null);g.capture(h);f=g.pageCoordinates(k)};this.mouseUp=function(){if(f!==null)f=null};this.mouseDrag=function(i,k){if(f!==null){i=g.pageCoordinates(k);o(i)}}};this.mouseDrag=function(c,d){if((this.initialized||!this.ctx)&&e&&e.mouseDrag)e.mouseDrag(c,d)};this.mouseMove=function(c,d){if((this.initialized||!this.ctx)&&e&&e.mouseMove)e.mouseMove(c,d)};this.mouseDown=function(c,d){if((this.initialized||
!this.ctx)&&e&&e.mouseDown)e.mouseDown(c,d)};this.mouseUp=function(c,d){if((this.initialized||!this.ctx)&&e&&e.mouseUp)e.mouseUp(c,d)};this.mouseWheel=function(c,d){if((this.initialized||!this.ctx)&&e&&e.mouseWheel)e.mouseWheel(c,d)};this.touchStart=function(c,d){if((this.initialized||!this.ctx)&&e&&e.touchStart)e.touchStart(c,d)};this.touchEnd=function(c,d){if((this.initialized||!this.ctx)&&e&&e.touchEnd)e.touchEnd(c,d)};this.touchMoved=function(c,d){if((this.initialized||!this.ctx)&&e&&e.touchMoved)e.touchMoved(c,
d)};this.handlePreload=function(){if(this.preloadingTextures===0&&this.preloadingBuffers===0){if(this.initialized){var c;for(c in this.updates)this.updates[c]();this.updates=[]}else this.initializeGL();this.resizeGL();this.paintGL()}};h.wtEncodeValue=F;var B=null,n=new Image;n.busy=false;n.onload=function(){h.src=n.src;if(B!=null)n.src=B;else n.busy=false;B=null};n.onerror=n.onload;this.loadImage=function(c){if(n.busy)B=c;else{n.src=c;n.busy=true}}});
