Skip to content

Commit

Permalink
🌊 Fixed waves on water not respecting sim time (pause/slomo/t.lapse).
Browse files Browse the repository at this point in the history
  • Loading branch information
ohlidalp committed Jan 27, 2025
1 parent fbe64fe commit af5d17e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
5 changes: 2 additions & 3 deletions source/main/gfx/Water.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions source/main/gfx/Water.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit af5d17e

Please sign in to comment.