From 43923a54d4117c953f4b763040bf1688cf0aa2a6 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Wed, 25 Jun 2025 18:54:57 +0900 Subject: [PATCH] example: more precisely calculate frame numbers fixed a missing case of the last frame. --- examples/Example.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/Example.h b/examples/Example.h index a7c866e0..583ffc9f 100644 --- a/examples/Example.h +++ b/examples/Example.h @@ -496,10 +496,10 @@ struct WgWindow : Window float progress(uint32_t elapsed, float durationInSec, bool rewind = false) { auto duration = uint32_t(durationInSec * 1000.0f); //sec -> millisec. - if (duration == 0) return 0.0f; + if (elapsed == 0 || duration == 0) return 0.0f; auto forward = ((elapsed / duration) % 2 == 0) ? true : false; - auto wrapped = elapsed % duration; - auto progress = ((float)wrapped / (float)duration); + if (elapsed % duration == 0) return 1.0f; + auto progress = (float(elapsed % duration) / (float)duration); if (rewind) return forward ? progress : (1 - progress); return progress; }