From f9f168c66ae0c2dd19e66c0cc35149f87ae76dc3 Mon Sep 17 00:00:00 2001 From: diegomatos Date: Sun, 14 Jul 2024 11:58:15 -0300 Subject: [PATCH] =?UTF-8?q?Adicionando=20bot=C3=A3o=20de=20play=20e=20paus?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirTrack.html | 22 +++++++++++++------ .../AirTrackScene.js | 17 ++++++++++---- .../BolasBilhar.html | 18 ++++++++++----- .../BolasBilharScene.js | 12 ++++++++-- .../BouncingBall.html | 14 +++++++++--- .../BouncingBallScene.js | 12 ++++++++-- .../ObliqueWallCollision.html | 14 +++++++++--- .../ObliqueWallCollision.js | 12 ++++++++-- 8 files changed, 93 insertions(+), 28 deletions(-) diff --git a/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/AirTrack.html b/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/AirTrack.html index 055f32d..a54dfaf 100644 --- a/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/AirTrack.html +++ b/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/AirTrack.html @@ -31,7 +31,7 @@ + + \ No newline at end of file diff --git a/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/AirTrackScene.js b/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/AirTrackScene.js index 72800cf..a29294b 100644 --- a/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/AirTrackScene.js +++ b/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/AirTrackScene.js @@ -43,16 +43,18 @@ export default class AirTrackScene { }, vtkActorRef: null } + fullScreenRenderer = null previousTimestamp = 0 + isPlaying = false constructor() { } Start() { this.vtkSetup() this.vtkPipeline() - - window.requestAnimationFrame(this.Anim) + + this.Anim() } vtkSetup() { @@ -119,15 +121,22 @@ export default class AirTrackScene { } Anim = (timeStamp) => { + // Por algum motivo na primeira iteração o argumento vem nulo/undefined if (timeStamp === undefined) { timeStamp = 0 } + const dt = (timeStamp - this.previousTimestamp) / 1000 // Proximo passo da animação em segundos this.previousTimestamp = timeStamp - this.Update(dt) - this.Render() + // Quando pausar eu só não atualizo a fisica, mas renderizo o último + // estado na tela + + if (this.isPlaying) { + this.Update(dt) + } + this.Render() window.requestAnimationFrame(this.Anim) } diff --git a/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/BolasBilhar.html b/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/BolasBilhar.html index e42aeb0..4590927 100644 --- a/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/BolasBilhar.html +++ b/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/BolasBilhar.html @@ -30,7 +30,7 @@ + + @@ -90,7 +97,8 @@

Colisão oblíqua entre duas bolas de bilhar Scene.Start()) + window.addEventListener("toggleAnimation", (e) => Scene.isPlaying = e.detail.isPlaying) \ No newline at end of file diff --git a/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/BolasBilharScene.js b/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/BolasBilharScene.js index dc9acc0..50d73a4 100644 --- a/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/BolasBilharScene.js +++ b/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/BolasBilharScene.js @@ -45,6 +45,7 @@ export default class BolasBilharScene { } fullScreenRenderer = null previousTimestamp = 0 + isPlaying = false constructor() { } @@ -115,15 +116,22 @@ export default class BolasBilharScene { } Anim = (timeStamp) => { + // Por algum motivo na primeira iteração o argumento vem nulo/undefined if (timeStamp === undefined) { timeStamp = 0 } + const dt = (timeStamp - this.previousTimestamp) / 1000 // Proximo passo da animação em segundos this.previousTimestamp = timeStamp - this.Update(dt) - this.Render() + // Quando pausar eu só não atualizo a fisica, mas renderizo o último + // estado na tela + if (this.isPlaying) { + this.Update(dt) + } + + this.Render() window.requestAnimationFrame(this.Anim) } diff --git a/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/BouncingBall.html b/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/BouncingBall.html index 36c2496..271e050 100644 --- a/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/BouncingBall.html +++ b/modelagem-matematica-computacional-2024-01/elastic-collision-implementation/BouncingBall.html @@ -55,7 +55,7 @@ class="fixed top-0 left-0 w-screen h-screen z-10" >