Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics with WebGL / Project / blackhole.js
diff options
context:
space:
mode:
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"