diff options
[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.js | 52 |
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", |
