Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics with WebGL / Project / level.js
diff options
context:
space:
mode:
Commit53c352887fdb3e0345e97c2760d8f7985a1bfc48 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-08-28 13:01:49 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-08-28 13:01:49 +0300
Files4ca4700916a35a216a96ac7c347a5ad1b33a4ef2 /Year 2/Computer Graphics with WebGL/Project/level.js
uni-projects-53c352887fdb3e0345e97c2760d8f7985a1bfc48.tar
uni-projects-53c352887fdb3e0345e97c2760d8f7985a1bfc48.tar.gz
uni-projects-53c352887fdb3e0345e97c2760d8f7985a1bfc48.zip
Parent8861a3e72f28f1757954c7f20ebeb469980f573a (diff)
[WGL/P] Added a lot of comments and reworked formatting of certain code
1 files changed, 52 insertions, 0 deletions
-rw-r--r--Year 2/Computer Graphics with WebGL/Project/level.js52
diff --git a/Year 2/Computer Graphics with WebGL/Project/level.js b/Year 2/Computer Graphics with WebGL/Project/level.js
index 5a5a22a..2a525d2 100644
--- a/Year 2/Computer Graphics with WebGL/Project/level.js
+++ b/Year 2/Computer Graphics with WebGL/Project/level.js
@@ -1,3 +1,7 @@
+/* Logic for levels, where each level contains all the objects that a scene needs */
+
+/* Global variables */
+
stars = [];
blackHoles = [];
animations = [];
@@ -7,6 +11,52 @@ blackHolesBuf = [];
levels = [];
var startT = -1;
+/* Star "class" */
+
+Star = function(center, size, starsBuf) {
+ if (starsBuf.length == STAR_MAX_COUNT)
+ throw 'Error: cannot add more stars, limit of ' + STAR_MAX_COUNT + ' reached!'
+
+ this.sphere = new Sphere(center, size);
+ this.sphere.color = STAR_COLOR;
+ this.index = starsBuf.push([]) - 1;
+ this.center = center;
+
+ this.sphere.center = center;
+ starsBuf[this.index] = center.concat(this.sphere.size);
+}
+Star.prototype.moveTo = function(newCenter, starsBuf) {
+ this.sphere.center = newCenter;
+ starsBuf[this.index] = newCenter.concat(this.sphere.size);
+ gl.uniform4fv(gl.getUniformLocation(glprog, 'uStars[' + this.index + ']'), starsBuf[this.index]);
+}
+Star.prototype.draw = function() {
+ this.sphere.draw();
+}
+
+/* BlackHole "class" */
+
+BlackHole = function(center, size, blackHolesBuf) {
+ if (blackHolesBuf.length == BLACKHOLE_MAX_COUNT)
+ throw 'Error: cannot add more black holes, limit of ' + BLACKHOLE_MAX_COUNT + ' reached!'
+
+ this.rs = size / 3;
+ this.index = blackHolesBuf.push([]) - 1;
+ this.center = center;
+
+ blackHolesBuf[this.index] = center.concat(this.rs);
+}
+BlackHole.prototype.moveTo = function(newCenter, blackHolesBuf) {
+ blackHolesBuf[this.index] = newCenter.concat(this.rs);
+ gl.uniform4fv(gl.getUniformLocation(glprog, 'uBH[' + this.index + ']'), blackHolesBuf[this.index]);
+}
+BlackHole.prototype.draw = function() {
+ // Black holes are not "drawn"
+ // But I'm keeping that function in case I put blackHole.draw() by accident
+}
+
+/* Level "class" */
+
Level = function(name, description, cameraCoords) {
this.name = name;
this.description = description;
@@ -47,6 +97,8 @@ Level.prototype.load = function() {
startT = -1;
}
+/* Our levels, this is ran in init() */
+
function createLevels() {
var l1 = new Level(
"Star passing behind black hole",