diff options
| Commit | 35fce31dd69c7a3524d1455dfe8c3244a3bbc630 (patch) | |
|---|---|---|
| Author | 2023-08-27 11:14:49 +0300 | |
| Committer | 2023-08-27 11:14:49 +0300 | |
| Files | 621ca3e49132d9a1111e0caee212c6e41f308d42 | |
| uni-projects-35fce31dd69c7a3524d1455dfe8c3244a3bbc630.tar uni-projects-35fce31dd69c7a3524d1455dfe8c3244a3bbc630.tar.gz uni-projects-35fce31dd69c7a3524d1455dfe8c3244a3bbc630.zip | ||
| Parent | 70dc2d83a54fe43050c34d6f91ba5a71fdb35d65 (diff) | |
[WGL/P] Implemented changing star location and moved the gl buffer setup in there
2 files changed, 10 insertions, 6 deletions
| -rw-r--r-- | Year 2/Computer Graphics with WebGL/Project/Project.html | 6 | ||||
| -rw-r--r-- | Year 2/Computer Graphics with WebGL/Project/star.js | 10 |
diff --git a/Year 2/Computer Graphics with WebGL/Project/Project.html b/Year 2/Computer Graphics with WebGL/Project/Project.html index ab7e618..41f4943 100644 --- a/Year 2/Computer Graphics with WebGL/Project/Project.html +++ b/Year 2/Computer Graphics with WebGL/Project/Project.html @@ -104,16 +104,13 @@ h2 { skybox = new Skybox(10000, [0,0,0], undefined);
stars = [
- new Star([1100,0,1000], 50),
+ new Star([1100,0,1000], 10),
// new Star([1000,0,900], 30),
// new Star([950,0,1100], 40),
];
// new Star([1000,0,-1000], 50)
// new Star([0,0,0], 100)
// new Star([1000, 0, -30], 20);
- for (var i = 0; i < starsBuf.length; i++) {
- gl.uniform4fv(gl.getUniformLocation(glprog, "uStars[" + i + "]"), starsBuf[i]);
- }
blackHole = new BlackHole([1000,0,900], 30);
for (var i = 0; i < blackHolesBuf.length; i++) {
@@ -139,6 +136,7 @@ h2 { lookUpdate();
gl.uniform3fv(uEye, pos);
+ stars[0].moveTo(vecSum(stars[0].sphere.center, [-0.5,0,0]));
skybox.draw();
stars.forEach((s) => s.draw());
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(); |
