Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics with WebGL / Project / blackhole.js
diff options
context:
space:
mode:
Commit87e9c9fa25b21bec3a658dcebc6c765a511d838e (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-08-27 11:44:43 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-08-27 11:44:43 +0300
Files5727bac04d65259a23267300dd9ff9a20a45554b /Year 2/Computer Graphics with WebGL/Project/blackhole.js
uni-projects-87e9c9fa25b21bec3a658dcebc6c765a511d838e.tar
uni-projects-87e9c9fa25b21bec3a658dcebc6c765a511d838e.tar.gz
uni-projects-87e9c9fa25b21bec3a658dcebc6c765a511d838e.zip
Parent35fce31dd69c7a3524d1455dfe8c3244a3bbc630 (diff)
[WGL/P] Slight code reorganisation, moved buffer logic for black holes in BlackHole and exported count limits as global variables
1 files changed, 9 insertions, 1 deletions
-rw-r--r--Year 2/Computer Graphics with WebGL/Project/blackhole.js10
diff --git a/Year 2/Computer Graphics with WebGL/Project/blackhole.js b/Year 2/Computer Graphics with WebGL/Project/blackhole.js
index 261a541..674093b 100644
--- a/Year 2/Computer Graphics with WebGL/Project/blackhole.js
+++ b/Year 2/Computer Graphics with WebGL/Project/blackhole.js
@@ -1,8 +1,16 @@
blackHolesBuf = [];
BlackHole = function(center, size) {
+ if (blackHolesBuf.length == BLACKHOLE_MAX_COUNT)
+ throw "Error: cannot add more black holes, limit of " + BLACKHOLE_MAX_COUNT + " reached!"
+
this.rs = size / 3;
- blackHolesBuf.push([center[0], center[1], center[2], this.rs]);
+ this.index = blackHolesBuf.push([]) - 1;
+ this.moveTo(center);
+}
+BlackHole.prototype.moveTo = function(newCenter) {
+ 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"