diff options
| Commit | 52ca40b96baa6bd0f4bce48a69b9bb34582386f3 (patch) | |
|---|---|---|
| Author | 2023-08-27 15:14:52 +0300 | |
| Committer | 2023-08-27 15:14:52 +0300 | |
| Files | e104b2909afceafbc4beb77044e5f303abf1e1ef | |
| uni-projects-52ca40b96baa6bd0f4bce48a69b9bb34582386f3.tar uni-projects-52ca40b96baa6bd0f4bce48a69b9bb34582386f3.tar.gz uni-projects-52ca40b96baa6bd0f4bce48a69b9bb34582386f3.zip | ||
| Parent | 8608f2c0e0d02e58df9280eab03a6b7a96acd5f1 (diff) | |
[WGL/P] Added movement pausing
3 files changed, 23 insertions, 8 deletions
| -rw-r--r-- | Year 2/Computer Graphics with WebGL/Project/Project.html | 4 | ||||
| -rw-r--r-- | Year 2/Computer Graphics with WebGL/Project/level.js | 20 | ||||
| -rw-r--r-- | Year 2/Computer Graphics with WebGL/Project/menu.js | 7 |
diff --git a/Year 2/Computer Graphics with WebGL/Project/Project.html b/Year 2/Computer Graphics with WebGL/Project/Project.html index 1dc3ffe..202b01c 100644 --- a/Year 2/Computer Graphics with WebGL/Project/Project.html +++ b/Year 2/Computer Graphics with WebGL/Project/Project.html @@ -123,6 +123,7 @@ h2 { }
window.onresize = resizeglcanvas;
+ var pauseAnimations = false;
function drawFrame()
{
gl.clear(gl.COLOR_BUFFER_BIT+gl.DEPTH_BUFFER_BIT);
@@ -130,9 +131,8 @@ h2 { updateCamera();
gl.uniform3fv(uEye, pos);
- // stars[0].moveTo(vecSum(stars[0].sphere.center, [-0.5,0,0]));
-
skybox.draw();
+ if (!pauseAnimations) animations.forEach((a) => a());
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 65c3cc6..68eed7a 100644 --- a/Year 2/Computer Graphics with WebGL/Project/level.js +++ b/Year 2/Computer Graphics with WebGL/Project/level.js @@ -1,5 +1,7 @@ stars = []; blackHoles = []; +animations = []; + levels = []; Level = function(name, description, cameraCoords) { @@ -8,17 +10,23 @@ Level = function(name, description, cameraCoords) { this.cameraCoords = cameraCoords; this.stars = []; this.blackHoles = []; + this.animations = []; levels.push(this); } -Level.prototype.addStar = function(center, size) { - this.stars.push(new Star(center, size)); +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))); } -Level.prototype.addBlackHole = function(center, size) { - this.blackHoles.push(new BlackHole(center, size)); +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))); } Level.prototype.load = function() { stars = this.stars; blackHoles = this.blackHoles; + animations = this.animations; pos = this.cameraCoords; } @@ -27,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); - l1.addBlackHole([1000,0,900], 30); + l1.addStar([1100,0,1000], 10, (star) => (vecSum(star.sphere.center, [-0.5,0,0]))); + l1.addBlackHole([1000,0,900], 30, undefined); } diff --git a/Year 2/Computer Graphics with WebGL/Project/menu.js b/Year 2/Computer Graphics with WebGL/Project/menu.js index 83a8e3c..1a9555f 100644 --- a/Year 2/Computer Graphics with WebGL/Project/menu.js +++ b/Year 2/Computer Graphics with WebGL/Project/menu.js @@ -50,3 +50,10 @@ function levelChange() { levels[this.value].load(); } levelSelect.addEventListener('change', levelChange); + +const animPause = document.getElementById('pause-movement'); +function pauseMovement() { + pauseAnimations = this.checked; +} +pauseMovement.call(animPause); +animPause.addEventListener('change', pauseMovement); |
