The realization method of water wave simulation

Source: Internet
Author: User

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;
        }
    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.