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:
dolcel committed 2026-10-20 23:59:02 +00:00
commit c09ce40be0
4048 files changed
+603256

No files matched your search

+100
View File
@@ -0,0 +1,100 @@
"use strict";
// draws wire frame teapot data
// by evaluating Bezier polynomials
// for each patch
var canvas, gl;
// number of evaluations along each curve
var numDivisions = 10;
var index = 0;
var points = [];
var bezier = function(u) {
var b = [];
var a = 1-u;
b.push(u*u*u);
b.push(3*a*u*u);
b.push(3*a*a*u);
b.push(a*a*a);
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);
}
}
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;
}
}
var 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 );
render();
}
var render = function(){
gl.clear( gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
for(var i=0; i<index; i+=3) gl.drawArrays( gl.LINE_LOOP, i, 3 );
requestAnimationFrame(render);
}