diff options
1 files changed, 6 insertions, 5 deletions
| -rw-r--r-- | Year 2/Computer Graphics with WebGL/Project/star.js | 11 |
diff --git a/Year 2/Computer Graphics with WebGL/Project/star.js b/Year 2/Computer Graphics with WebGL/Project/star.js index de1e9e9..8aad803 100644 --- a/Year 2/Computer Graphics with WebGL/Project/star.js +++ b/Year 2/Computer Graphics with WebGL/Project/star.js @@ -1,15 +1,16 @@ -starsBuf = []; - -Star = function(center, size) { +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 = [0.956,0.5,0.215]; this.index = starsBuf.push([]) - 1; - this.moveTo(center); + this.center = center; + + this.sphere.center = center; + starsBuf[this.index] = center.concat(this.sphere.size); } -Star.prototype.moveTo = function(newCenter) { +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]); |
