diff --git a/RotatingCube/Homogeneous3D.js b/RotatingCube/Homogeneous3D.js new file mode 100644 index 0000000..7b808a5 --- /dev/null +++ b/RotatingCube/Homogeneous3D.js @@ -0,0 +1,39 @@ +// Homogeneous3D.js +// John Breaux 2022-07-12 +// 3D Homogeneous coordinate library + +"use strict"; + +// +// Classes +// + +// Homogeneous3D: Stores a 3D vector or point in homogeneous coords +class Homogeneous3D { + constructor({ x = 0, y = 0, z = 0, w = 0 } = { x: 0, y: 0, z: 0, w: 0 }) { + this.x = x; + this.y = y; + this.z = z; + this.w = w; + } + // Add with modify + add_m(rhs) { + if (rhs) { + this.x += rhs.x; + this.y += rhs.y; + this.z += rhs.z; + this.w += rhs.w; + return this; + } + else return null; + } + // calculate the magnitude (lol what are points) + magnitude() { + var magnitude = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); + } + + // copy + copy() { + return new Homogeneous3D(this.x, this.y, this.z, this.w); + } +} \ No newline at end of file diff --git a/RotatingCube/RotatingCube.js b/RotatingCube/RotatingCube.js index 96d5b0b..430210a 100644 --- a/RotatingCube/RotatingCube.js +++ b/RotatingCube/RotatingCube.js @@ -107,6 +107,14 @@ function initVertexBuffers(gl) { -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, -1.0, -1.0, 1.0, // v7-v4-v3-v2 down 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0 // v4-v7-v6-v5 back ]); + var colors2 = new Float32Array([ // Vertex coordinates + 1.0, 1.0, 1.0, 0, 1.0, 1.0, 0, 0, 1.0, 1.0, 0, 1.0, // v0-v1-v2-v3 front + 1.0, 1.0, 1.0, 1.0, 0, 1.0, 1.0, 0, 0, 1.0, 1.0, 0, // v0-v3-v4-v5 right + 1.0, 1.0, 1.0, 1.0, 1.0, 0, 0, 1.0, 0, 0, 1.0, 1.0, // v0-v5-v6-v1 up + 0, 1.0, 1.0, 0, 1.0, 0, 0, 0, 0, 0, 0, 1.0, // v1-v6-v7-v2 left + 0, 0, 0, 1.0, 0, 0, 1.0, 0, 1.0, 0, 0, 1.0, // v7-v4-v3-v2 down + 1.0, 0, 0, 0, 0, 0, 0, 1.0, 0, 1.0, 1.0, 0 // v4-v7-v6-v5 back + ]); var colors = new Float32Array([ // Colors 0.4, 0.4, 1.0, 0.4, 0.4, 1.0, 0.4, 0.4, 1.0, 0.4, 0.4, 1.0, // v0-v1-v2-v3 front(blue)