In a wavelength range, the displacement of any point disp=sin (Dist) *force+disp_center;
The wave is set here as a sine wave, and the amplitude is force,disp_center as the displacement in the vibration.
Extended to any point, Disp=sin (dist%wave_length) *force+disp_center;
Here wave_length is the wavelength. It can be seen that in the discrete data, the displacement of any point is a finite set. We first construct this set, in the process of operation, from the set to select a displacement value on the line, rather than real-time calculation of the displacement of each point.
The design is as follows: Take the wavelength of 12, the displacement of any point by an array of 12 elements.
int disp[12];
Set up a number of storage points to the distance in the vibration
int dist[600][800];
A wave is generated below
inline void Build_disp_matrix ()
{for
(int i = 0; i < ++i)
Disp = static_cast<int> (sin (double) i* 30*dxpi/360) *precision);
void create_ripple (int center_x, int center_y, int force, int damp, int wave_length)
{for
(int i = 0; I < wave _length; ++i)
{
disp = force * disp/precision;
}
int dist_x, dist_y;
for (i = 0; i < screen_height. ++i)
{for
(int j = 0; j< screen_width; ++j)
{
dist_y = I-center_ y;
dist_x = j-center_x;
DIST[J] = static_cast<int> (sqrt (dist_x*dist_x + dist_y*dist_y) + 0.5)% Wave_length;
}
}