program.js
// Re-generates the faces of the superquadric.
Re-generates the faces of the superquadric.
Re - generates the faces of the superquadric .
function updateFaces(superquadric, constants, subdivU, subdivV) {
    points = [];
	var normals = [];
	var texCoords = [];
	var texture;
	var texCoord = [
		vec2(0, 0),
		vec2(0, 1),
		vec2(1, 1),
		vec2(1, 0)
	];
    var du = (superquadric.uMax - superquadric.uMin) / subdivU;
    var dv = (superquadric.vMax - superquadric.vMin) / subdivV;
    wireframePointCount = 0;
    for (var i = 0; i < subdivU; i++) {
        for (var j = 0; j < subdivV; j++) {
            var u = superquadric.uMin + i * du;
            var v = superquadric.vMin + j * dv;
            var p = vec4(superquadric.evaluate(constants, u, v), 1.0);
            var pu = vec4(superquadric.evaluate(constants, u + du, v), 1.0);
            var pv = vec4(superquadric.evaluate(constants, u, v + dv), 1.0);
			var puv = vec4(superquadric.evaluate(constants, u + du, v + dv), 1.0);
			var t1;
			var t2;
			var normal;
			if (isFinite(p[0]) && isFinite(p[1]) && isFinite(p[2]) &&
					isFinite(pu[0]) && isFinite(pu[1]) && isFinite(pu[2]) &&
					isFinite(pv[0]) && isFinite(pv[1]) && isFinite(pv[2])) {
				t1 = subtract(pu, p);
				t2 = subtract(pv, p);
				normal = normalize(cross(t2, t1));
				normal = vec4(normal);
				normal[3]  = 0.0;
				normals.push(normal);
				normals.push(normal);
				normals.push(normal);
				points.push(p);
				points.push(pu);
				points.push(pv);
				texCoords.push(texCoord[0]);
				texCoords.push(texCoord[1]);
				texCoords.push(texCoord[2]);
				wireframePointCount += 3;
			}
			if (isFinite(puv[0]) && isFinite(puv[1]) && isFinite(puv[2]) &&
					isFinite(pu[0]) && isFinite(pu[1]) && isFinite(pu[2]) &&
					isFinite(pv[0]) && isFinite(pv[1]) && isFinite(pv[2])) {
				t1 = subtract(puv, pu);
				t2 = subtract(pv, pu);
				normal = normalize(cross(t2, t1));
				normal = vec4(normal);
				normal[3]  = 0.0;
				normals.push(normal);
				normals.push(normal);
				normals.push(normal);
				points.push(puv);
				points.push(pv);
				points.push(pu);
				texCoords.push(texCoord[3]);
				texCoords.push(texCoord[2]);
				texCoords.push(texCoord[1]);
				wireframePointCount += 3;
			}
            v += dv;
        }
        v = superquadric.vMax;
        u += du;
    }
    u = superquadric.uMax;
	gl.bindBuffer(gl.ARRAY_BUFFER, normalsBufferId );
	gl.bufferData(gl.ARRAY_BUFFER, flatten(normals), gl.DYNAMIC_DRAW);
    gl.bindBuffer(gl.ARRAY_BUFFER, wireframeBufferId );
    gl.bufferData(gl.ARRAY_BUFFER, flatten(points), gl.DYNAMIC_DRAW);
	gl.bindBuffer( gl.ARRAY_BUFFER, textureBufferId );
    gl.bufferData( gl.ARRAY_BUFFER, flatten(texCoords), gl.STATIC_DRAW );
}
function updateFaces ( superquadric , constants , subdivU , subdivV ) { points = [ ] ; var normals = [ ] ; var texCoords = [ ] ; var texture ; var texCoord = [ vec2 ( 0 , 0 ) , vec2 ( 0 , 1 ) , vec2 ( 1 , 1 ) , vec2 ( 1 , 0 ) ] ; var du = ( superquadric . uMax - superquadric . uMin ) / subdivU ; var dv = ( superquadric . vMax - superquadric . vMin ) / subdivV ; wireframePointCount = 0 ; for ( var i = 0 ; i < subdivU ; i ++ ) { for ( var j = 0 ; j < subdivV ; j ++ ) { var u = superquadric . uMin + i * du ; var v = superquadric . vMin + j * dv ; var p = vec4 ( superquadric . evaluate ( constants , u , v ) , 1.0 ) ; var pu = vec4 ( superquadric . evaluate ( constants , u + du , v ) , 1.0 ) ; var pv = vec4 ( superquadric . evaluate ( constants , u , v + dv ) , 1.0 ) ; var puv = vec4 ( superquadric . evaluate ( constants , u + du , v + dv ) , 1.0 ) ; var t1 ; var t2 ; var normal ; if ( isFinite ( p [ 0 ] ) && isFinite ( p [ 1 ] ) && isFinite ( p [ 2 ] ) && isFinite ( pu [ 0 ] ) && isFinite ( pu [ 1 ] ) && isFinite ( pu [ 2 ] ) && isFinite ( pv [ 0 ] ) && isFinite ( pv [ 1 ] ) && isFinite ( pv [ 2 ] ) ) { t1 = subtract ( pu , p ) ; t2 = subtract ( pv , p ) ; normal = normalize ( cross ( t2 , t1 ) ) ; normal = vec4 ( normal ) ; normal [ 3 ] = 0.0 ; normals . push ( normal ) ; normals . push ( normal ) ; normals . push ( normal ) ; points . push ( p ) ; points . push ( pu ) ; points . push ( pv ) ; texCoords . push ( texCoord [ 0 ] ) ; texCoords . push ( texCoord [ 1 ] ) ; texCoords . push ( texCoord [ 2 ] ) ; wireframePointCount += 3 ; } if ( isFinite ( puv [ 0 ] ) && isFinite ( puv [ 1 ] ) && isFinite ( puv [ 2 ] ) && isFinite ( pu [ 0 ] ) && isFinite ( pu [ 1 ] ) && isFinite ( pu [ 2 ] ) && isFinite ( pv [ 0 ] ) && isFinite ( pv [ 1 ] ) && isFinite ( pv [ 2 ] ) ) { t1 = subtract ( puv , pu ) ; t2 = subtract ( pv , pu ) ; normal = normalize ( cross ( t2 , t1 ) ) ; normal = vec4 ( normal ) ; normal [ 3 ] = 0.0 ; normals . push ( normal ) ; normals . push ( normal ) ; normals . push ( normal ) ; points . push ( puv ) ; points . push ( pv ) ; points . push ( pu ) ; texCoords . push ( texCoord [ 3 ] ) ; texCoords . push ( texCoord [ 2 ] ) ; texCoords . push ( texCoord [ 1 ] ) ; wireframePointCount += 3 ; } v += dv ; } v = superquadric . vMax ; u += du ; } u = superquadric . uMax ; gl . bindBuffer ( gl . ARRAY_BUFFER , normalsBufferId ) ; gl . bufferData ( gl . ARRAY_BUFFER , flatten ( normals ) , gl . DYNAMIC_DRAW ) ; gl . bindBuffer ( gl . ARRAY_BUFFER , wireframeBufferId ) ; gl . bufferData ( gl . ARRAY_BUFFER , flatten ( points ) , gl . DYNAMIC_DRAW ) ; gl . bindBuffer ( gl . ARRAY_BUFFER , textureBufferId ) ; gl . bufferData ( gl . ARRAY_BUFFER , flatten ( texCoords ) , gl . STATIC_DRAW ) ; }
Re-generates the faces of the superquadric.
Re - generates the faces of the superquadric .
// Initialize an empty array of points // Determine how much u and v change with each segment // Reset the vertex count to 0 // Loop over u and v, generating all the required line segments // Determine u and v // p is the "current" point at surface coordinates (u,v) // pu is the point at surface coordinates (u+du, v) // pv is the point at surface coordinates (u, v+dv) // puv is the point at surface coordinates (u+du, v+dv) // Verify that all the points actually used are not infinite or NaN // (Could be an issue for hyperboloids) // Pass the new set of vertices to the graphics card