Initial transfer of larger repo from git. IF full history and branches are needed must go to github at https://github.com/DulcisL/CCUCoding.git
This commit is contained in:
commit
c09ce40be0
4048 files changed
+603256
No files matched your search
@@ -0,0 +1,126 @@
|
||||
"use strict";
|
||||
|
||||
var numDivisions = 5;
|
||||
|
||||
var index = 0;
|
||||
|
||||
var points = [];
|
||||
|
||||
var modelViewMatrix, projectionMatrix;
|
||||
|
||||
var axis =0;
|
||||
|
||||
var xAxis = 0;
|
||||
var yAxis = 1;
|
||||
var zAxis = 2;
|
||||
var theta = vec3(0, 0, 0);
|
||||
|
||||
var render, canvas, gl;
|
||||
var program;
|
||||
|
||||
var flag = true;
|
||||
|
||||
var bezier = function(u) {
|
||||
var b =new Array(4);
|
||||
var a = 1-u;
|
||||
b[3] = a*a*a;
|
||||
b[2] = 3*a*a*u;
|
||||
b[1] = 3*a*u*u;
|
||||
b[0] = u*u*u;
|
||||
return b;
|
||||
}
|
||||
|
||||
onload = function init() {
|
||||
|
||||
canvas = document.getElementById( "gl-canvas" );
|
||||
|
||||
gl = canvas.getContext('webgl2');
|
||||
if (!gl) { alert( "WebGL 2.0 isn't available" ); }
|
||||
gl.viewport( 0, 0, canvas.width, canvas.height );
|
||||
|
||||
gl.clearColor( 1.0, 1.0, 1.0, 1.0 );
|
||||
|
||||
var h = 1.0/numDivisions;
|
||||
|
||||
var patch = new Array(numTeapotPatches);
|
||||
for(var i=0; i<numTeapotPatches; i++) patch[i] = new Array(16);
|
||||
for(var i=0; i<numTeapotPatches; i++)
|
||||
for(j=0; j<16; j++) {
|
||||
patch[i][j] = vec4([vertices[indices[i][j]][0],
|
||||
vertices[indices[i][j]][2],
|
||||
vertices[indices[i][j]][1], 1.0]);
|
||||
}
|
||||
|
||||
|
||||
for ( var n = 0; n < numTeapotPatches; n++ ) {
|
||||
|
||||
var data = new Array(numDivisions+1);
|
||||
for(var j = 0; j<= numDivisions; j++) data[j] = new Array(numDivisions+1);
|
||||
for(var i=0; i<=numDivisions; i++) for(var j=0; j<= numDivisions; j++) {
|
||||
data[i][j] = vec4(0,0,0,1);
|
||||
var u = i*h;
|
||||
var v = j*h;
|
||||
var t = new Array(4);
|
||||
for(var ii=0; ii<4; ii++) t[ii]=new Array(4);
|
||||
for(var ii=0; ii<4; ii++) for(var jj=0; jj<4; jj++)
|
||||
t[ii][jj] = bezier(u)[ii]*bezier(v)[jj];
|
||||
|
||||
|
||||
for(var ii=0; ii<4; ii++) for(var jj=0; jj<4; jj++) {
|
||||
var temp = vec4(patch[n][4*ii+jj]);
|
||||
temp = mult( t[ii][jj], temp);
|
||||
data[i][j] = add(data[i][j], temp);
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById("ButtonX").onclick = function(){axis = xAxis;};
|
||||
document.getElementById("ButtonY").onclick = function(){axis = yAxis;};
|
||||
document.getElementById("ButtonZ").onclick = function(){axis = zAxis;};
|
||||
document.getElementById("ButtonT").onclick = function(){flag = !flag;};
|
||||
|
||||
for(var i=0; i<numDivisions; i++) for(var j =0; j<numDivisions; j++) {
|
||||
points.push(data[i][j]);
|
||||
points.push(data[i+1][j]);
|
||||
points.push(data[i+1][j+1]);
|
||||
points.push(data[i][j]);
|
||||
points.push(data[i+1][j+1]);
|
||||
points.push(data[i][j+1]);
|
||||
index += 6;
|
||||
}
|
||||
}
|
||||
|
||||
program = initShaders( gl, "vertex-shader", "fragment-shader" );
|
||||
gl.useProgram( program );
|
||||
|
||||
var vBufferId = gl.createBuffer();
|
||||
gl.bindBuffer( gl.ARRAY_BUFFER, vBufferId );
|
||||
gl.bufferData( gl.ARRAY_BUFFER, flatten(points), gl.STATIC_DRAW );
|
||||
|
||||
var positionLoc = gl.getAttribLocation( program, "aPosition" );
|
||||
gl.vertexAttribPointer( positionLoc, 4, gl.FLOAT, false, 0, 0 );
|
||||
gl.enableVertexAttribArray( positionLoc );
|
||||
|
||||
|
||||
projectionMatrix = ortho(-2, 2, -2, 2, -20, 20);
|
||||
gl.uniformMatrix4fv( gl.getUniformLocation(program, "projectionMatrix"), false, flatten(projectionMatrix));
|
||||
|
||||
render();
|
||||
}
|
||||
|
||||
render = function(){
|
||||
gl.clear( gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||
|
||||
if(flag) theta[axis] += 0.5;
|
||||
|
||||
modelViewMatrix = mat4();
|
||||
|
||||
modelViewMatrix = mult(modelViewMatrix, rotate(theta[xAxis], vec3(1, 0, 0)));
|
||||
modelViewMatrix = mult(modelViewMatrix, rotate(theta[yAxis], vec3(0, 1, 0)));
|
||||
modelViewMatrix = mult(modelViewMatrix, rotate(theta[zAxis], vec3(0, 0, 1)));
|
||||
|
||||
|
||||
gl.uniformMatrix4fv( gl.getUniformLocation(program, "modelViewMatrix"), false, flatten(modelViewMatrix) );
|
||||
|
||||
for(var i=0; i<index; i+=3) gl.drawArrays( gl.LINE_LOOP, i, 3 );
|
||||
requestAnimationFrame(render);
|
||||
}
|
||||
Reference in new issue
Block a user