Add some things
This commit is contained in:
		
							
								
								
									
										39
									
								
								RotatingCube/Homogeneous3D.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								RotatingCube/Homogeneous3D.js
									
									
									
									
									
										Normal file
									
								
							| @@ -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); | ||||||
|  |    } | ||||||
|  | } | ||||||
| @@ -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,  // 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 |     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 |   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) |     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) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user