From 87e9c9fa25b21bec3a658dcebc6c765a511d838e Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 27 Aug 2023 11:44:43 +0300 Subject: [WGL/P] Slight code reorganisation, moved buffer logic for black holes in BlackHole and exported count limits as global variables --- Year 2/Computer Graphics with WebGL/Project/blackhole.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'Year 2/Computer Graphics with WebGL/Project/blackhole.js') 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" -- cgit v1.3.1-26-gb76a