LibGDX Guide - 2D Sprite Tracing - Infinite Random Bezier Curve

I was able to apply smooth animation to my sprite and control it with an accelerometer. My sprite is fixed to move left and right along x-aixs.

From here I need to figure out how to create a vertical infinite wavy line for the sprite to try to trace. the goal of my game is to allow the user to control the left / right movement with the accelerometer, trying to trace the infinite wavy line as much as possible, while the sprite and camera move in the vertical direction to simulate "moving" along the line. " It would be ideal if the string were randomly generated.

I explored splines, planes, Bezier curves, etc., but I can't find anything similar that seems to be pretty close to what I'm trying to achieve.

I'm just looking for some recommendations as to which methods I could use to achieve this. Any ideas?

+3
source share
1 answer

You can use a sum of 4 to 5 sine waves (each with a different amplitude, wavelength and phase difference). All 3 of these parameters may be random.

The resulting curve will be very smooth (since it is mostly sinusoidal), but it will look random (its time period will be the LCM of all 4-5 random wavelengths, which is a huge number).

, , ​​. , , FPS.

. enter image description here

. ( .. -)

, . .: D

( - , , , )


Edit:

, , .

public class SineTerm {

    private float amplitude;
    private float waveLength;
    private float phaseDifference;

    public SineTerm(float amplitude, float waveLength, float phaseDifference) {
        this.amplitude = amplitude;
        this.waveLength = waveLength;
        this.phaseDifference = phaseDifference;
    }

    public float evaluate(float x) {
        return amplitude * (float) Math.sin(2 * Math.PI * x / waveLength + phaseDifference);
    }

}

SineTerm , evaluate(x) ( ). . .

.

.

+2

All Articles