rem: str += '\n'; } return str; } 
add:  return { length_x:x, length_y:y, length_z:z,  size_x: options.size_x, size_y: options.size_y, size_z: options.size_z,  buffers: { position: position, indices: indices }, buffers_info : null }; }  function grid4(x,y,z,w, options) {  if(!options) options = {}; if(!options.size_w) options.size_w = (!options.size)?100.0:options.size; if(!options.size_z) options.size_z = (!options.size)?100.0:options.size; if(!options.size_y) options.size_y = (!options.size)?100.0:options.size; if(!options.size_x) options.size_x = (!options.size)?100.0:options.size;  var position = new GLMAT_ARRAY_TYPE(w*z*y*x*4), color = new GLCOLOR_ARRAY_TYPE(w*z*y*x*4), indices, step_x = 4, step_y = x*step_x, step_z = y*step_y, step_w = z*step_z, step_length_w = options.size_w/(w-1), step_length_z = options.size_z/(z-1), step_length_y = options.size_y/(y-1), step_length_x = options.size_x/(x-1), i_w, i_z, i_y, i_x, i_dir, min=1, max = -1;   for(i_w = w; i_w--;) for(i_z = z; i_z--;) for(i_y = y; i_y--;) for(i_x = x; i_x--;) { i_dir = i_w*step_w + i_z*step_z + i_y*step_y + i_x*step_x;  position[ i_dir ] =  ((x-1)/2-i_x)*step_length_x; position[i_dir+1] =  ((y-1)/2-i_y)*step_length_y; position[i_dir+2] =  ((z-1)/2-i_z)*step_length_z; position[i_dir+3] =  ((w-1)/2-i_w)*step_length_w;  color[i_dir] = 105; color[i_dir+1] = 105; color[i_dir+2] = 105; color[i_dir+3] = 255;  if( position[i_dir+0] < 0 ) color[i_dir] += 150;  if( position[i_dir+2] < 0 ) color[i_dir+1] += 150;  if( position[i_dir+3] < 0 ) color[i_dir+2] += 150;  if( position[i_dir+1] < 0 ) color[i_dir+1] -= 45; }   if(!options.linestrip) { indices = new GLINDEX_ARRAY_TYPE(2*( w*z*y*(x-1) + w*z*(y-1)*x + w*(z-1)*y*x + (w-1)*z*y*x ));       function createLinesOnAxis(offset, axis_a_step, axis_b_step, axis_c_step, axis_d_step) { var i_dir2;  var step_x = 1, step_y = y*step_x, step_z = z*step_y, step_w = w*step_z;  for(i_w = w; i_w--;) for(i_z = z; i_z--;) for(i_y = y; i_y--;) for(i_x = x-1; i_x--;) {  i_dir = offset + i_w*step_w + i_z*step_z + i_y*step_y + i_x*step_x; i_dir2 =  i_w*axis_a_step + i_z*axis_b_step + i_y*axis_c_step + i_x*axis_d_step;  indices[i_dir] = i_dir2/4; indices[i_dir+1] = (i_dir2 + axis_d_step)/4; } }      createLinesOnAxis(0, step_w, step_z, step_y, step_x); createLinesOnAxis( 2*w*z*y*(x-1), step_w, step_z, step_x, step_y);  createLinesOnAxis( 2*w*z*(y*(x-1) + (y-1)*x), step_w, step_y, step_x, step_z);  createLinesOnAxis( 2*w*(z*(y*(x-1) + (y-1)*x) + (z-1)*y*x),step_z, step_y, step_x, step_w); }  return { length_x:x, length_y:y, length_z:z, length_w:w,  size_x: options.size_x, size_y: options.size_y, size_z: options.size_z, size_w: options.size_w,  buffers: { position: {numComponents: 4, data: position, type: Float32Array}, indices: {numComponents: 2, data: indices, type: Float32Array}, color: {numComponents: 4, data: color, type: Uint8Array} } }; }  return { grid4: grid4, grid3: grid3 }; })();      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(); }  return { objAdd: objAdd, objRm: objRm, init: init, resize: resize, render: render, obj_list: obj_list, camera: camera, camera3: camera3, math: math, config: config }; })();  
context:   global.mat = (function() {    function str(m, l) {      var str = '\n',        l = (!l)? Math.floor(Math.sqrt(m.length+1)+0.05) : l,        x,y,        number_width = 1,        width;      for(x=l*l; x--;) {        width = String(m[x]).length;        if(width > number_width)          number_width = width;      }      for(y=-1; ++y < l; ) {        for(x=-1; ++x < l; ) {          width = String(m[(x*l) + y]).length;          str += m[(x*l) + y] + Array(number_width-width+2).join(' ');        }        str += '\n';      }      return str;    }    return {      str: str    };  })();
meta: 5665	/local1/tlutelli/issta_data/temp/all_js/javascript/2007_temp/2007/5665/0f8ba5d109269d49d72be1d776721a5a867dd729/NEngine.js/clean/lib/NEngine.js