*** ParallelLightCubes2.html Tue Jul 1 18:30:52 2014
--- ParallelLightObjects.html Tue Jul 1 18:31:08 2014
***************
*** 42,64 ****
var canvas = app.canvas;
var gl = app.gl;
! var vertices = tsuda.cube.vertices;
! var indices = tsuda.cube.indices;
! var colorList = [];
! colorList[0] = tsuda.get3Float32Array(1.0, 0.0, 0.0, vertices.length);
! colorList[1] = tsuda.get3Float32Array(0.0, 1.0, 0.0, vertices.length);
! colorList[2] = tsuda.get3Float32Array(0.0, 0.0, 1.0, vertices.length);
! colorList[3] = tsuda.get3Float32Array(1.0, 1.0, 0.0, vertices.length);
! colorList[4] = tsuda.get3Float32Array(1.0, 0.0, 1.0, vertices.length);
! colorList[5] = tsuda.get3Float32Array(0.0, 1.0, 1.0, vertices.length);
! colorList[6] = tsuda.get3Float32Array(1.0, 1.0, 1.0, vertices.length);
! var normals = tsuda.indexNormals(vertices,indices);
!
! if (! tsuda.initArrayBuffer('a_Position',vertices,3,gl.FLOAT)) return;
! if (! tsuda.initArrayBuffer('a_Color',colorList[0],3,gl.FLOAT)) return;
! if (! tsuda.initArrayBuffer('a_Normal',normals,3,gl.FLOAT)) return;
!
! if (! tsuda.setElementArrayBuffer(indices)) return;
var u_MvpMatrix = gl.getUniformLocation(gl.program,'u_MvpMatrix');
var u_NormalMatrix = gl.getUniformLocation(gl.program,'u_NormalMatrix');
--- 42,60 ----
var canvas = app.canvas;
var gl = app.gl;
! var obj = [ tsuda.cube, tsuda.pyramid ];
! var i,j;
! for (i=0; i<obj.length; i++) {
! obj[i].colorList = [];
! obj[i].colorList[0] = tsuda.get3Float32Array(1.0, 0.0, 0.0, obj[i].vertices.length);
! obj[i].colorList[1] = tsuda.get3Float32Array(0.0, 1.0, 0.0, obj[i].vertices.length);
! obj[i].colorList[2] = tsuda.get3Float32Array(0.0, 0.0, 1.0, obj[i].vertices.length);
! obj[i].colorList[3] = tsuda.get3Float32Array(1.0, 1.0, 0.0, obj[i].vertices.length);
! obj[i].colorList[4] = tsuda.get3Float32Array(1.0, 0.0, 1.0, obj[i].vertices.length);
! obj[i].colorList[5] = tsuda.get3Float32Array(0.0, 1.0, 1.0, obj[i].vertices.length);
! obj[i].colorList[6] = tsuda.get3Float32Array(1.0, 1.0, 1.0, obj[i].vertices.length);
! obj[i].normals = tsuda.indexNormals(obj[i].vertices,obj[i].indices);
! }
var u_MvpMatrix = gl.getUniformLocation(gl.program,'u_MvpMatrix');
var u_NormalMatrix = gl.getUniformLocation(gl.program,'u_NormalMatrix');
***************
*** 92,112 ****
viewMatrix.setLookAt(-30.0, 50.0, 50.0, 0, 0, 0, 0, 1, 0);
projMatrix.setPerspective(30, canvas.width/canvas.height, 1, 100);
! var i;
! for (i=0; i<30; i++) {
! var colorIndex = Math.floor(Math.random()*colorList.length);
! if (! tsuda.initArrayBuffer('a_Color',colorList[colorIndex],3,gl.FLOAT)) return;
! modelMatrix.setTranslate(tsuda.tr(20),tsuda.tr(20),tsuda.tr(20));
! modelMatrix.rotate(Math.random()*90, 1, 0, 0);
! modelMatrix.rotate(Math.random()*90, 0, 1, 0);
! modelMatrix.rotate(Math.random()*90, 0, 0, 1);
! mvpMatrix.set(projMatrix).multiply(viewMatrix).multiply(modelMatrix);
! gl.uniformMatrix4fv(u_MvpMatrix,false,mvpMatrix.elements);
! normalMatrix.setInverseOf(modelMatrix);
! normalMatrix.transpose();
! gl.uniformMatrix4fv(u_NormalMatrix,false,normalMatrix.elements);
!
! gl.drawElements(gl.TRIANGLES, indices.length,gl.UNSIGNED_BYTE,0);
}
}
--- 88,121 ----
viewMatrix.setLookAt(-30.0, 50.0, 50.0, 0, 0, 0, 0, 1, 0);
projMatrix.setPerspective(30, canvas.width/canvas.height, 1, 100);
! var oidx;
! for (oidx = 0; oidx < obj.length; oidx ++) {
! var vertices = obj[oidx].vertices;
! var indices = obj[oidx].indices;
! var normals = obj[oidx].normals;
! var colorList = obj[oidx].colorList;
!
! if (! tsuda.initArrayBuffer('a_Position',vertices,3,gl.FLOAT)) return;
! if (! tsuda.initArrayBuffer('a_Color',colorList[0],3,gl.FLOAT)) return;
! if (! tsuda.initArrayBuffer('a_Normal',normals,3,gl.FLOAT)) return;
!
! if (! tsuda.setElementArrayBuffer(indices)) return;
!
! for (i=0; i<30; i++) {
! var colorIndex = Math.floor(Math.random()*colorList.length);
! if (! tsuda.initArrayBuffer('a_Color',colorList[colorIndex],3,gl.FLOAT)) return;
! modelMatrix.setTranslate(tsuda.tr(20),tsuda.tr(20),tsuda.tr(20));
! modelMatrix.rotate(Math.random()*90, 1, 0, 0);
! modelMatrix.rotate(Math.random()*90, 0, 1, 0);
! modelMatrix.rotate(Math.random()*90, 0, 0, 1);
! mvpMatrix.set(projMatrix).multiply(viewMatrix).multiply(modelMatrix);
! gl.uniformMatrix4fv(u_MvpMatrix,false,mvpMatrix.elements);
! normalMatrix.setInverseOf(modelMatrix);
! normalMatrix.transpose();
! gl.uniformMatrix4fv(u_NormalMatrix,false,normalMatrix.elements);
!
! gl.drawElements(gl.TRIANGLES, indices.length,gl.UNSIGNED_BYTE,0);
! }
}
}
|