Hello there,

I'm trying to implement the water effect using the gamedev article about Hooke springs (http://gamedev.tutsplus.com/tutorials/implementation/make-a-splash-with-2d-water-effects/), but I wanted to add a sine wave generator to keep the waves moving. So I started writing a test code for generating a progressive sine wave:

Water::Water(uint32 uiPoints) { m_points.resize(uiPoints); for (size_t i = 0; i < uiPoints; ++i) { m_points[i].p[0] = (i+1.f) / uiPoints * WIDTH; m_points[i].p[1] = 0.f; m_points[i].speed[1] = 0.f; } TimerSystem::getInstance().addTickable(this); } void Water::tick(uint32 dt) { m_uiDt += dt; // T = 2PI/w = 2PI*f uint32 T = static_cast<uint32>(Math::TWO_PI/w_constant*1000.f); // (in ms) if (m_uiDt >= T) m_uiDt -= T; // Y(x, t) = A*sin(k*x - w*t) float t = m_uiDt / 1000.f; for (size_t i = 0; i < m_points.size(); ++i) m_points[i].p[1] = amplitude * std::sinf(k_constant*m_points[i].p[0] - w_constant*t); } void Water::render() { // translate Math::Vector2f pos(0.f, Y_OFFSET); for (size_t i = 0; i < m_points.size(); ++i) Graphics::Renderer::getInstance().drawFillCircle(pos+m_points[i].p, 2.f, Math::Colorf::RED); }

As far as I remember the formula is this one (long time I do not open a math book) but I started to render the points and I noticed that it's like generating 2 different waves:

I made the springs and the particles without any problem but I can't get the sine wave working (the easiest thing I know, so funny), what's wrong?

Thanks in advice.