diff options
[WGL] Added unfinished homeworks
1 files changed, 12 insertions, 6 deletions
| -rw-r--r-- | Year 2/Computer Graphics with WebGL/Homework 06 - The knot/Homework.html | 18 |
diff --git a/Year 2/Computer Graphics with WebGL/Homework 06 - The knot/Homework.html b/Year 2/Computer Graphics with WebGL/Homework 06 - The knot/Homework.html index bbf9808..348947b 100644 --- a/Year 2/Computer Graphics with WebGL/Homework 06 - The knot/Homework.html +++ b/Year 2/Computer Graphics with WebGL/Homework 06 - The knot/Homework.html @@ -115,6 +115,12 @@ for (var point = 0; point < TREFOIL_SIDES; point++) {
sectionCircle.push([Math.sin(2 * Math.PI * point / TREFOIL_SIDES), 0, Math.cos(2 * Math.PI * point / TREFOIL_SIDES)]);
}
+ function alternateInsertEnd(points) {
+ for (var i = 0, j = data.length - points.length * 3 + 3; i < points.length; i++, j += 6) {
+ data.splice(j, 0, ...points[i]);
+ }
+ }
+
function section(ver, vp) {
var out = sectionCircle.slice(0);
@@ -122,7 +128,6 @@ var xAng = Math.acos(dotProduct(unitVector([vp[0], 0, vp[2]]), [1,0,0]));
var zRot = zRotateMatrix(yAng / Math.PI * 180);
var yRot = yRotateMatrix(xAng / Math.PI * 180);
- console.log(zRot);
out = out.map((point) => {
point = matVecMult(zRot, point);
point = matVecMult(yRot, point);
@@ -139,10 +144,11 @@ for (var t = 0; t < Math.PI * 2; t += stepSize) {
var ver = vertex(t);
// var hue = t;
- var vec = vectorPoints(vertex(t + stepSize), ver);
- section(ver, vec).forEach((point) => {
- data.push(...point);
- });
+ var vec = vectorPoints(ver, vertex(t + stepSize));
+ alternateInsertEnd(section(ver, vec));
+ // section(ver, vec).forEach((point) => {
+ // data.push(...point);
+ // });
// data.push(...ver);
}
@@ -169,7 +175,7 @@ // върхове
gl.enableVertexAttribArray(aXYZ);
gl.vertexAttribPointer(aXYZ, 3, gl.FLOAT, false, 3 * FLOATS,0);
- gl.drawArrays(gl.TRIANGLES, 0, this.TREFOIL_POINTS * this.TREFOIL_SIDES);
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, this.TREFOIL_POINTS * this.TREFOIL_SIDES);
popMatrix();
}
|
