text: function main(){var e=document.getElementById("webgl"),r=getWebGLContext(e);if(!r)return void console.log("Failed to get the rendering context for WebGL");var t=$("#vsh_tmpl").html(),a=$("#fsh_tmpl").html();if(!initShaders(r,t,a))return void console.log("Failed to intialize shaders.");var n=initVertexBuffers(r);if(0>n)return void console.log("Failed to set the vertex information");r.clearColor(0,0,0,1),r.enable(r.DEPTH_TEST);var o=r.getUniformLocation(r.program,"u_MvpMatrix"),i=r.getUniformLocation(r.program,"u_NormalMatrix");if(!o||!i)return void console.log("Failed to get the storage location");var l=new Matrix4;l.setPerspective(50,e.width/e.height,1,100),l.lookAt(20,10,30,0,0,0,0,1,0),document.onkeydown=function(e){keydown(e,r,n,l,o,i)},draw(r,n,l,o,i)}function keydown(e,r,t,a,n,o){switch(e.keyCode){case 38:135>g_joint1Angle&&(g_joint1Angle+=ANGLE_STEP);break;case 40:g_joint1Angle>-135&&(g_joint1Angle-=ANGLE_STEP);break;case 39:g_arm1Angle=(g_arm1Angle+ANGLE_STEP)%360;break;case 37:g_arm1Angle=(g_arm1Angle-ANGLE_STEP)%360;break;default:return}draw(r,t,a,n,o)}function initVertexBuffers(e){var r=new Float32Array([1.5,10,1.5,-1.5,10,1.5,-1.5,0,1.5,1.5,0,1.5,1.5,10,1.5,1.5,0,1.5,1.5,0,-1.5,1.5,10,-1.5,1.5,10,1.5,1.5,10,-1.5,-1.5,10,-1.5,-1.5,10,1.5,-1.5,10,1.5,-1.5,10,-1.5,-1.5,0,-1.5,-1.5,0,1.5,-1.5,0,-1.5,1.5,0,-1.5,1.5,0,1.5,-1.5,0,1.5,1.5,0,-1.5,-1.5,0,-1.5,-1.5,10,-1.5,1.5,10,-1.5]),t=new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1]),a=new Uint8Array([0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]);if(!initArrayBuffer(e,"a_Position",r,e.FLOAT,3))return-1;if(!initArrayBuffer(e,"a_Normal",t,e.FLOAT,3))return-1;e.bindBuffer(e.ARRAY_BUFFER,null);var n=e.createBuffer();return n?(e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,n),e.bufferData(e.ELEMENT_ARRAY_BUFFER,a,e.STATIC_DRAW),a.length):(console.log("Failed to create the buffer object"),-1)}function initArrayBuffer(e,r,t,a,n){var o=e.createBuffer();if(!o)return console.log("Failed to create the buffer object"),!1;e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,t,e.STATIC_DRAW);var i=e.getAttribLocation(e.program,r);return 0>i?(console.log("Failed to get the storage location of "+r),!1):(e.vertexAttribPointer(i,n,a,!1,0,0),e.enableVertexAttribArray(i),!0)}function draw(e,r,t,a,n){e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT);var o=10;g_modelMatrix.setTranslate(0,-12,0),g_modelMatrix.rotate(g_arm1Angle,0,1,0),drawBox(e,r,t,a,n),g_modelMatrix.translate(0,o,0),g_modelMatrix.rotate(g_joint1Angle,0,0,1),g_modelMatrix.scale(1.3,1,1.3),drawBox(e,r,t,a,n)}function drawBox(e,r,t,a,n){g_mvpMatrix.set(t),g_mvpMatrix.multiply(g_modelMatrix),e.uniformMatrix4fv(a,!1,g_mvpMatrix.elements),g_normalMatrix.setInverseOf(g_modelMatrix),g_normalMatrix.transpose(),e.uniformMatrix4fv(n,!1,g_normalMatrix.elements),e.drawElements(e.TRIANGLES,r,e.UNSIGNED_BYTE,0)}var ANGLE_STEP=3,g_arm1Angle=-90,g_joint1Angle=0,g_modelMatrix=new Matrix4,g_mvpMatrix=new Matrix4,g_normalMatrix=new Matrix4;$(function(){main()});