rem: math = (function() {     function rotateNormalized(va, vb, theta) { var tmp = vec4.clone(va); vec4.scaleAndAdd(va, va, va, Math.cos(theta)-1); vec4.scaleAndAdd(va, va, vb, -Math.sin(theta));  vec4.scaleAndAdd(vb, vb, vb, Math.cos(theta)-1); vec4.scaleAndAdd(vb, vb, tmp, Math.sin(theta)); }   function projection(out,va,vb) { vec4.scale(out, vb, vec4.dot(va,vb)/vec4.length(va)); }   function repair(vx, vy, vz, vw) { var length, projection = new vec4.create();   projection(projection, vx, vy); vec4.sub(vx,vx, projection); projection(projection, vx, vz); vec4.sub(vx,vx, projection); projection(projection, vx, vw); vec4.sub(vx,vx, projection);  vec4.normalize(vx, vx);  projection(projection, vy, vz); vec4.sub(vy,vy, projection); projection(projection, vy, vw); vec4.sub(vy,vy, projection);  vec4.normalize(vy,vy);  projection(projection, vz, vw); vec4.sub(vz,vz, projection);  vec4.normalize(vz,vz); vec4.normalize(vw,vw); 
add: renderer = (function() { var obj_list = [], options_init, context = null, canvas = null, shader_info = null, vertexShader, fragmentShader, attrib_vertex, attrib_color, uniforms = {}, config = { dimensions : null, color_clear : [0.0, 0.0, 0.0, 1.0], view_3d : 'stereo', view_3d_camera_disposition: 'hexagon', view_3d_stereo_angle : Math.PI/60, view_3d_stereo_separator : [-2.616,0,0,0], view_3d_projection: 'perspective', view_3d_projection_ortogonal_length : 100, view_3d_projection_ortogonal_aspect_x : 1, view_3d_projection_ortogonal_aspect_y : 1 }, math = { mat : null, mat_cartesian : null, vec : null, vec_homogenous : null, vec_base : null },  PMVMatrix = mat5.create(), PMVMatrix3 = mat4.create(), PMatrix = mat5.create(), PMatrix3 = mat4.create(),  uPMVMatrix1 = mat4.create(), uPMVMatrix2 = mat4.create(), uPMVMatrix3D = PMVMatrix3,  matrix_tmp = mat5.create(), tmp_matrix5_1 = mat5.create(), tmp_matrix5_2 = mat5.create(), tmp_matrix5_3 = mat5.create(), tmp_matrix4 = mat4.create(), tmp_matrix4_1 = mat4.create(), tmp_matrix4_2 = mat4.create(), tmp_matrix4_3 = mat4.create(), tmp_vec1 = vec4.create(), tmp_vec2 = vec4.create(), tmp_vec3 = vec4.create(), tmp_vec4 = vec4.create(), tmp_vec5 = vec4.create(), m_cameraRotation = mat5.create(), m_cameraRotation3 = mat4.create(), m_objectRotation = mat5.create(), v_totalTraslation = vec4.create(), v_totalTraslation3 = vec4.create(), obj_list_i, obj_list_obj, camera = new Obj(), camera3 = new Obj();  global.tmp_debug = true;  uPMVMatrix2[0] = 0; uPMVMatrix2[5] = 0; uPMVMatrix2[10] = 0; uPMVMatrix2[15] = 0;  function init(options) { var options_default = { dim : 4 }, field; for(field in options_default) if(options[field] === undefined) options[field] = options_default[field];   if(!options) options = {}; if(!options.container) options.container = document.body; if(!options.projection_near) options.projection_near = 1.0; if(!options.projection_far) options.projection_far = 100.0; if(!options.projection_angle) options.projection_angle = Math.PI/2;  if(!options.projection_3d_near) options.projection_3d_near = 1.0; if(!options.projection_3d_far) options.projection_3d_far = 100.0; if(!options.projection_3d_angle) options.projection_3d_angle = Math.PI/2;  options_init = options;  if(options.view_3d_projection) config.view_3d_projection = options.view_3d_projection; if(options.view_3d_camera_disposition) config.view_3d_camera_disposition = options.view_3d_camera_disposition; if(options.view_3d_projection_ortogonal_length) config.view_3d_projection_ortogonal_length = options.view_3d_projection_ortogonal_length;  if(config.view_3d_camera_disposition === 'hexagon') { if(config.view_3d_projection === 'perspective')  { vec3.rotateNormalizedRelative(camera3, camera3.rz, camera3.rx, -Math.PI/4); vec3.rotateNormalizedRelative(camera3, camera3.rz, camera3.ry, Math.PI/5); camera3.p[0] = +100; camera3.p[1] = -100; } else if(config.view_3d_projection === 'ortogonal') { vec3.rotateNormalizedRelative(camera3, camera3.rz, camera3.rx, -Math.PI/4); vec3.rotateNormalizedRelative(camera3, camera3.rz, camera3.ry, Math.PI/5); camera3.p[0] =100; camera3.p[1] =-100; } }  config.dim = options.dim; math.mat = global['mat'+(config.dim+1)]; math.mat_cartesian = global['mat'+config.dim];  math.vec = global['vec'+config.dim]; math.vec_homogenous = global['vec'+(config.dim+1)];  if(options.container === document.body) { options.container = document.createElement('canvas', {alpha: false, premultipliedAlpha: false}); options.container.className = 'NEngine_canvas'; document.body.appendChild(options.container); } context = twgl.getWebGLContext(options.container);   twgl.setAttributePrefix('a_'); shader_info = twgl.createProgramInfo(context, ["vs", "fs"]); context.useProgram(shader_info.program);   uniforms.uPMVMatrix1 = uPMVMatrix1; uniforms.uPMVMatrix2 = uPMVMatrix2; uniforms.uPMVMatrix3D = uPMVMatrix3D;   canvas = context.canvas;  global.addEventListener('resize', resize, false); resize(); } function set(options) { var field; foreach(field in options) config[field] = options[field]; } function resize() { var const_vert = 1, const_hor = 1;  twgl.resizeCanvasToDisplaySize( canvas );  mat5.projectionLen(PMatrix, options_init.projection_angle, options_init.projection_angle, options_init.projection_angle, options_init.projection_near, options_init.projection_far);   switch(config.view_3d) { case 'stereo': const_vert = canvas.height/canvas.width; const_hor = 1/2; break; case 'flat': default: const_vert = canvas.height/canvas.width; const_hor = 1; return; } if(config.view_3d_projection === 'perspective') mat4.projectionLen(PMatrix3, options_init.projection_3d_angle*const_hor, options_init.projection_3d_angle*const_vert, options_init.projection_3d_near, options_init.projection_3d_far); else if(config.view_3d_projection === 'ortogonal') mat4.ortogonalLen(PMatrix3, config.view_3d_projection_ortogonal_length, config.view_3d_projection_ortogonal_aspect_x, config.view_3d_projection_ortogonal_aspect_y) }  function render() {  if(obj_list.length) { context.clearColor(config.color_clear[0],config.color_clear[1],config.color_clear[2],config.color_clear[3]); context.clear(context.COLOR_BUFFER_BIT);   mat5.rotationVecs(m_cameraRotation, camera.rx, camera.ry, camera.rz, camera.rw ); for(obj_list_i=obj_list.length; obj_list_i--;) {  obj_list_obj = obj_list[obj_list_i]   mat5.rotationVecs(m_objectRotation, obj_list_obj.rx, obj_list_obj.ry, obj_list_obj.rz, obj_list_obj.rw );  mat5.copy(matrix_tmp, m_objectRotation); vec4.sub(v_totalTraslation, obj_list_obj.p, camera.p); mat5.translate(m_objectRotation, v_totalTraslation);   mat5.multiply(matrix_tmp, m_cameraRotation, m_objectRotation); mat5.multiply(PMVMatrix, PMatrix, matrix_tmp);   mat5.inferiorProjection(uPMVMatrix1, uPMVMatrix2, PMVMatrix);   context.useProgram(shader_info.program); twgl.setBuffersAndAttributes(context, shader_info, obj_list_obj.geom.buffers_info);  if(config.view_3d === 'stereo') {     mat5.identity(tmp_matrix5_1); mat5.rotateZX(tmp_matrix5_1, config.view_3d_stereo_angle); mat.createFrom(tmp_matrix4_1, tmp_matrix5_1);  mat4.translate(tmp_matrix4_1, tmp_matrix4_1, config.view_3d_stereo_separator);   mat4.rotationVecs(tmp_matrix4_2, camera3.rx, camera3.ry, camera3.rz); mat4.translate(tmp_matrix4_2, tmp_matrix4_2, camera3.p);   mat4.multiply(tmp_matrix4_3, tmp_matrix4_2, tmp_matrix4_1);   mat4.multiply(PMVMatrix3, PMatrix3, tmp_matrix4_3);  twgl.setUniforms(shader_info, uniforms); context.viewport(0,0, canvas.width/2, canvas.height); twgl.drawBufferInfo(context, context.LINES, obj_list_obj.geom.buffers_info);      mat5.identity(tmp_matrix5_1); mat5.rotateZX(tmp_matrix5_1, -config.view_3d_stereo_angle); mat.createFrom(tmp_matrix4_1, tmp_matrix5_1);  vec4.scale(tmp_vec1, config.view_3d_stereo_separator, -1 ); mat4.translate(tmp_matrix4_1, tmp_matrix4_1, tmp_vec1);   mat4.rotationVecs(tmp_matrix4_2, camera3.rx, camera3.ry, camera3.rz); mat4.translate(tmp_matrix4_2, tmp_matrix4_2, camera3.p);   mat4.multiply(tmp_matrix4_3, tmp_matrix4_2, tmp_matrix4_1);   mat4.multiply(PMVMatrix3, PMatrix3, tmp_matrix4_3);  twgl.setUniforms(shader_info, uniforms); context.viewport(canvas.width/2,0, canvas.width/2, canvas.height); twgl.drawBufferInfo(context, context.LINES, obj_list_obj.geom.buffers_info); } else if(config.view_3d === 'flat' || !config.view_3d) {  mat4.rotationVecs(m_cameraRotation3, camera3.rx, camera.ry, camera.rz);   vec4.copy(tmp_vec1, camera3.p); vec4.scale(tmp_vec1, tmp_vec1, -1); mat4.translate(tmp_matrix4, m_cameraRotation3, camera3.p);   mat4.multiply(PMVMatrix3, PMatrix3, tmp_matrix4);  twgl.setUniforms(shader_info, uniforms); context.viewport(0,0, canvas.width, canvas.height); twgl.drawBufferInfo(context, context.LINES, obj_list_obj.geom.buffers_info); }  if(global.tmp_debug) { global.tmp_debug = false; console.log(mat.str(PMatrix3)); console.log(mat.str(PMatrix)); console.log(mat.str(PMVMatrix));  var i = 0, data = obj_list_obj.geom.buffers.position.data; for(; i < data.length; i+=4) { var v = vec.createFrom(5, data, i, 4), v_tmp = vec5.create(); v[4] = 1.0, h = 0, v4=null, v4_tmp=vec4.create(), depth = null;   mat5.multiplyVec(v_tmp, PMVMatrix,v); h = v_tmp[4]; vec5.scaleI(v_tmp, 1/h); v_tmp[3] *= h;    v4 = vec.createFrom(4, v_tmp); v4[2] += 1.0; vec4.scale(v4, v4, 50); v4[3] = 1.0;   mat4.multiplyVec(v4_tmp, PMVMatrix3, v4); h = v4_tmp[3]; vec4.scale(v4_tmp, v4_tmp, 1/h); v4_tmp[2] = v_tmp[3];  /* console.log(vec.str(v_tmp, 8)); console.log(vec.str(v4, 8)); console.log(vec.str(v4_tmp, 8)); console.log(''); */  } global.tmp_debug = false; } } } } function objAdd(obj) { if(obj.geom && obj.geom.buffers_info !== null) { obj.geom.buffers_info = twgl.createBufferInfoFromArrays(context, obj.geom.buffers ); } obj_list.push(obj); }  function objRm(obj) { if(obj_list[obj_list.length-1] === obj) { obj_list.pop(); return; } obj_list[ obj_list.indexOf(obj) ] = obj_list.pop(); 
context:     math = (function() {      //front-vector : va      //rotation-vector: vb      //all ortogonal      function rotateNormalized(va, vb, theta) {        var tmp = vec4.clone(va);        vec4.scaleAndAdd(va, va, va, Math.cos(theta)-1);        vec4.scaleAndAdd(va, va, vb, -Math.sin(theta));        vec4.scaleAndAdd(vb, vb, vb, Math.cos(theta)-1);        vec4.scaleAndAdd(vb, vb, tmp, Math.sin(theta));      }      //gets projection of va over vb      function projection(out,va,vb) {        vec4.scale(out, vb, vec4.dot(va,vb)/vec4.length(va));      }      //will reorthogonalize vectors      function repair(vx, vy, vz, vw) {        var length,          projection = new vec4.create();        //repair vx        projection(projection, vx, vy);        vec4.sub(vx,vx, projection);        projection(projection, vx, vz);        vec4.sub(vx,vx, projection);        projection(projection, vx, vw);        vec4.sub(vx,vx, projection);        vec4.normalize(vx, vx);        projection(projection, vy, vz);        vec4.sub(vy,vy, projection);        projection(projection, vy, vw);        vec4.sub(vy,vy, projection);        vec4.normalize(vy,vy);        projection(projection, vz, vw);        vec4.sub(vz,vz, projection);        vec4.normalize(vz,vz);        vec4.normalize(vw,vw);      }      return {        rotateNormalized: rotateNormalized,        projection: projection,        repair: repair      };    })();
meta: 5665	/local1/tlutelli/issta_data/temp/all_js/javascript/2007_temp/2007/5665/0f8ba5d109269d49d72be1d776721a5a867dd729/NEngine.js/clean/lib/NEngine.js