From af5d17e6af1acf45b26f49040cb4e0e1708a577d Mon Sep 17 00:00:00 2001 From: ohlidalp Date: Mon, 27 Jan 2025 01:12:28 +0100 Subject: [PATCH] :ocean: Fixed waves on water not respecting sim time (pause/slomo/t.lapse). --- source/main/gfx/Water.cpp | 5 ++--- source/main/gfx/Water.h | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/main/gfx/Water.cpp b/source/main/gfx/Water.cpp index 4d78b985fb..8ff0cdc946 100644 --- a/source/main/gfx/Water.cpp +++ b/source/main/gfx/Water.cpp @@ -511,8 +511,6 @@ float Water::CalcWavesHeight(Vector3 pos) return m_water_height; } - const float time_sec = (float)(App::GetAppContext()->GetOgreRoot()->getTimer()->getMilliseconds() * 0.001); - // uh, some upper limit?! if (pos.y > m_water_height + m_max_ampl) return m_water_height; @@ -528,7 +526,7 @@ float Water::CalcWavesHeight(Vector3 pos) float amp = std::min(m_wavetrain_defs[i].amplitude * waveheight, m_wavetrain_defs[i].maxheight); // now the main thing: // calculate the sinus with the values of the config file and add it to the result - result += amp * sin(Math::TWO_PI * ((time_sec * m_wavetrain_defs[i].wavespeed + m_wavetrain_defs[i].dir_sin * pos.x + m_wavetrain_defs[i].dir_cos * pos.z) / m_wavetrain_defs[i].wavelength)); + result += amp * sin(Math::TWO_PI * ((m_sim_time_counter * m_wavetrain_defs[i].wavespeed + m_wavetrain_defs[i].dir_sin * pos.x + m_wavetrain_defs[i].dir_cos * pos.z) / m_wavetrain_defs[i].wavelength)); } // return the summed up waves return result; @@ -613,6 +611,7 @@ void Water::FrameStepWater(float dt) // Update even if game paused to account for camera movement (important for reflections). // -------------------------------------------------------------------------------------- this->UpdateWater(); + m_sim_time_counter += dt; } void Water::SetForcedCameraTransform(Ogre::Radian fovy, Ogre::Vector3 pos, Ogre::Quaternion rot) diff --git a/source/main/gfx/Water.h b/source/main/gfx/Water.h index c7197d1ee5..b9b0d14cf6 100644 --- a/source/main/gfx/Water.h +++ b/source/main/gfx/Water.h @@ -108,6 +108,7 @@ class Water : public IWater float m_max_ampl = 0.f; float m_waterplane_mesh_scale = 1.f; int m_frame_counter = 0; + float m_sim_time_counter = 0.f; //!< Elapsed simulation time in seconds. Ogre::Vector3 m_map_size = Ogre::Vector3::ZERO; Ogre::Plane m_water_plane; Ogre::MeshPtr m_waterplane_mesh;