Water wave demonstration:
Screenshot
This water wave simulation process is not only the same as other common algorithms. This is the use of the Tiger Chemical to approximate the water wave fluctuations. The specific algorithm is as follows.
We know that when the water is calm, it is time. That is to say, the water surface is in a balanced position. The force of any point on the water is balanced. However, there is any disturbance, and it will be a bit deviated from the balanced position. The force will be unbalanced, which will generate acceleration. Since these points are complied with the Tiger theorem, if you know the state of the water surface, in theory, we can accurately calculate the surface state (external interference is 0).
Of course, in our program, the calculation is not necessary. Otherwise we have to build a complex differential equation ... We do the following assumptions here: 1) The point on the water is discrete. 2) One point is the same in the time of DT. 3) A point force is only related to 8 points around. With this three assumptions, we can build our physical approximation model.
First, let's calculate a point of force and the relationship between the positions of them. Set the displacement of the S point to S, speed is VS
Spoint force FS = K * B * [(B1 B2 B3 B4) - 4 * S] K * A * [(A1 A2 A3 A4) -4 * S]. K is the tiger coefficient. A, B is the weight coefficient of the two distance points, respectively. (Different distances, the effect is of course different.)
Therefore, at this moment, the acceleration of the s point is A = fs * DM (DM is the quality of water.). The speed of the S point at the next time is VS2 = VS - A * DT (DT is time interval). The only time at the next time is S2 = S VS2 * DT (DT is time interval).
Everything is ready. It is time to implement the program now. The displacement of the point on the water can be saved by an array. We need two arrays to save the displacement, a saving current displacement, one for calculating the displacement of the next moment (current displacement when calculating). Also have an array to save the current speed. In the program, when we calculate the acceleration, you can assume DT to 1. This improves speed. At the same time, you can use the DM * K as a number. Note that if these constants are not good, they don't get the results you want. In my program, DM * k = 1. B = 1. a = 3. DT = 1. Second, we have to attenuate the water wave, otherwise your water waves can't stop :-). The code of the diffusion of the water wave is as follows:
Void ripplespread () {for (int y = 1; y