<p>This implementation represents the water as a regular height field grid. The function parameters <code>m</code> and <code>n</code> are the dimensions of the grid, <code>dx</code> is the regular distance between the water vertices, <code>dt</code> is the time step, <code>speed</code> is the speed of the movement and <code>damping</code> is a constant to ease disturbance as the water flows from the disturbance center.</p>

CC BY-SA 3.0
2017-04-11T20:07:54.760Z
2017-04-12T11:28:55.877Z
2017-04-12T11:28:55.877Z
dsilva.vinicius
<p>I'm confused by the <code>Waves</code> class <a href="https://github.com/utilForever/DirectX/blob/master/DirectX%2011/Frank%20D.%20Luna/Common/Waves.cpp#L55" rel="nofollow noreferrer">implementation</a> in the source code of the book <em>Introduction to 3D Game Programming with DirecX11</em>:</p>

<pre><code>float d = damping*dt+2.0f;
float e = (speed*speed)*(dt*dt)/(dx*dx);
mK1     = (damping*dt-2.0f)/ d;
mK2     = (4.0f-8.0f*e) / d;
mK3     = (2.0f*e) / d;
</code></pre>

<p>What do the parameters mean? How are the waves generated? I've tried searching waves implementation and found <a href="https://stackoverflow.com/questions/6716887/how-to-render-ocean-wave-using-opengl-in-3d">https://stackoverflow.com/questions/6716887/how-to-render-ocean-wave-using-opengl-in-3d</a> , I looked up the links mentioned by the answer but I couldn't understand the complicated equations and it seems that the equations have no relation with the code above. I also tried searching "spatially damped wave", and then I found <a href="https://physics.stackexchange.com/questions/223366/wave-equation-with-spatial-damping">https://physics.stackexchange.com/questions/223366/wave-equation-with-spatial-damping</a>, that didn't help me, neither...</p>

CC BY-SA 3.0
2017-04-07T19:12:53.157Z
Could you be a little more specific as to what you don't really understand? Is it how the waves are generated and the parameters? I'm sure many people here could help you.
Arjan Singh
CC BY-SA 3.0
2017-04-08T02:49:27.947Z
@ArjanSingh Yes! I updated the question.
Cu2S
<3d>
How does the Waves class in the book Introduction to 3D Game Programming with DirecX11 work?
Cu2S
# How does the Waves class in the book Introduction to 3D Game Programming with DirecX11 work?

(Asked by: username_0 on 2017-04-07)

I'm confused by the `Waves` class [implementation](https://github.com/utilForever/DirectX/blob/master/DirectX%2011/Frank%20D.%20Luna/Common/Waves.cpp#L55) in the source code of the book *Introduction to 3D Game Programming with DirecX11*:

```
float d = damping*dt+2.0f;
float e = (speed*speed)*(dt*dt)/(dx*dx);
mK1     = (damping*dt-2.0f)/ d;
mK2     = (4.0f-8.0f*e) / d;
mK3     = (2.0f*e) / d;

```

What do the parameters mean? How are the waves generated? I've tried searching waves implementation and found <https://stackoverflow.com/questions/6716887/how-to-render-ocean-wave-using-opengl-in-3d> , I looked up the links mentioned by the answer but I couldn't understand the complicated equations and it seems that the equations have no relation with the code above. I also tried searching "spatially damped wave", and then I found <https://physics.stackexchange.com/questions/223366/wave-equation-with-spatial-damping>, that didn't help me, neither...

**Tags:** 3d

> **Comments:**
> **username_1**: Could you be a little more specific as to what you don't really understand? Is it how the waves are generated and the parameters? I'm sure many people here could help you.  
> **username_0**: @username_1 Yes! I updated the question.  

---

## 1 answers

### Answer by username_2 on 2017-04-11. Score: 2 | Accepted answer

This implementation represents the water as a regular height field grid. The function parameters `m` and `n` are the dimensions of the grid, `dx` is the regular distance between the water vertices, `dt` is the time step, `speed` is the speed of the movement and `damping` is a constant to ease disturbance as the water flows from the disturbance center.


---

