diff options
2 files changed, 7 insertions, 4 deletions
| -rw-r--r-- | Year 2/Computer Graphics with WebGL/Project/Project.html | 5 | ||||
| -rw-r--r-- | Year 2/Computer Graphics with WebGL/Project/level.js | 6 |
diff --git a/Year 2/Computer Graphics with WebGL/Project/Project.html b/Year 2/Computer Graphics with WebGL/Project/Project.html index 202b01c..c4d090c 100644 --- a/Year 2/Computer Graphics with WebGL/Project/Project.html +++ b/Year 2/Computer Graphics with WebGL/Project/Project.html @@ -124,15 +124,18 @@ h2 { window.onresize = resizeglcanvas;
var pauseAnimations = false;
+ var startT = -1;
function drawFrame()
{
+ if (startT == -1) startT = Date.now();
+ var t = Math.floor(Date.now() - startT) / 10; // tenths of a second
gl.clear(gl.COLOR_BUFFER_BIT+gl.DEPTH_BUFFER_BIT);
updateCamera();
gl.uniform3fv(uEye, pos);
skybox.draw();
- if (!pauseAnimations) animations.forEach((a) => a());
+ if (!pauseAnimations) animations.forEach((a) => a(t));
stars.forEach((s) => s.draw());
requestAnimationFrame(drawFrame);
diff --git a/Year 2/Computer Graphics with WebGL/Project/level.js b/Year 2/Computer Graphics with WebGL/Project/level.js index 68eed7a..7f4120a 100644 --- a/Year 2/Computer Graphics with WebGL/Project/level.js +++ b/Year 2/Computer Graphics with WebGL/Project/level.js @@ -16,12 +16,12 @@ Level = function(name, description, cameraCoords) { Level.prototype.addStar = function(center, size, animation) { var star = new Star(center, size); this.stars.push(star); - if (animation) this.animations.push(() => star.moveTo(animation(star))); + if (animation) this.animations.push((t) => star.moveTo(animation(t, star))); } Level.prototype.addBlackHole = function(center, size, animation) { var bh = new BlackHole(center, size); this.blackHoles.push(bh); - if (animation) this.animations.push(() => bh.moveTo(animation(bh))); + if (animation) this.animations.push((t) => bh.moveTo(animation(t, bh))); } Level.prototype.load = function() { stars = this.stars; @@ -35,6 +35,6 @@ function createLevels() { "Star passing behind black hole", "You can see how the black hole (correctly) warps the light of the star behind it when it passes", [1000,0,650]); - l1.addStar([1100,0,1000], 10, (star) => (vecSum(star.sphere.center, [-0.5,0,0]))); + l1.addStar([1100,0,1000], 10, (t, star) => [1100 -100 * (1 + Math.sin(t/300 + 1.5 * Math.PI)),0,1000]); l1.addBlackHole([1000,0,900], 30, undefined); } |
