Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Computer Graphics with WebGL / Project / star.js
diff options
context:
space:
mode:
1 files changed, 8 insertions, 2 deletions
-rw-r--r--Year 2/Computer Graphics with WebGL/Project/star.js10
diff --git a/Year 2/Computer Graphics with WebGL/Project/star.js b/Year 2/Computer Graphics with WebGL/Project/star.js
index 7aebc6c..a98c3cf 100644
--- a/Year 2/Computer Graphics with WebGL/Project/star.js
+++ b/Year 2/Computer Graphics with WebGL/Project/star.js
@@ -2,8 +2,14 @@ starsBuf = [];
Star = function(center, size) {
this.sphere = new Sphere(center, size);
- this.sphere.color = [0.956,0.5,0.215];
- starsBuf.push([center[0], center[1], center[2], size]);
+ this.sphere.color = [0.956,0.5,0.215];
+ this.index = starsBuf.push([]) - 1;
+ this.moveTo(center);
+}
+Star.prototype.moveTo = function(newCenter) {
+ 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();