LibGDX指导-精灵跟踪2D无限随机贝塞尔曲线 [英] LibGDX guidance - sprite tracing 2D infinite random bezier curve

查看:135
本文介绍了LibGDX指导-精灵跟踪2D无限随机贝塞尔曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经能够将平滑的动画应用于我的精灵,并使用加速度计对其进行控制.我的精灵已固定为沿着x-aix左右移动.

I've been able to apply a smooth animation to my sprite and control it using the accelerometer. My sprite is fixed to move left and right along the x-aixs.

从这里开始,我需要弄清楚如何为精灵创建垂直无限的波浪线以尝试跟踪.我的游戏的目的是让用户使用加速度计控制精灵的左右移动,以尽其所能追踪永无止境的波浪线,而精灵和相机都沿垂直方向移动以模拟移动"沿线."如果该行是随机生成的,那将是理想的选择.

From here, I need to figure out how to create a vertical infinite wavy line for the sprite to attempt to trace. the aim of my game is for the user to control the sprite's left/right movement with the accelerometer in an attempt to trace the never ending wavy line as best they can, whilst the sprite and camera both move in a vertical direction to simulate "moving along the line." It would be ideal if the line was randomly generated.

我已经研究了样条曲线,平面,贝塞尔曲线等,但是找不到与我要达到的目标足够接近的东西.

I've researched about splines, planes, bezier curves etc, but I can't find anything that seems to relate close enough to what I'm trying to achieve.

我只是在寻求有关可以使用哪些方法实现此目标的指导.有什么想法吗?

I'm just seeking some guidance as to what methods I could possibly use to achieve this. Any ideas?

推荐答案

您可以使用4至5个正弦波的总和(每个正弦波具有不同的幅度,波长和相位差).这些参数中的所有3个都可以是随机的.

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

最终的曲线将非常平滑(因为它主要是正弦曲线的),但看起来却是随机的(时间段将是所有4至5个随机波长的LCM,这是一个很大的数目).

The resulting curve would be very smooth (since it is primarily sinusoidal) yet it'll look random (it's time period would be LCM of all 4 to 5 random wavelengths which is a huge number).

因此曲线不会重复很长时间,但不会很难记忆.关于计算复杂性,您始终可以通过使用FPS更改正弦项的数量来对其进行调整.

So the curve won't repeat for a long time, yet it will not be hard on memory. Concerning computational complexity, you can always tune it by changing number of sine terms with FPS.

它应该看起来像这样.

It should look like this.

这也很容易实现. (即使我可以生成上面的图像..哈哈)

It's really easy to implement too. (even I could generate above image.. haha)

希望这会有所帮助.数学岩石. :D

Hope this helps. Maths rocks. :D

(这里的基本思想是一个有限的傅里叶级数,我认为它应该是理想的您的用例)

(The basic idea here is a finite Fourier series which I think should be ideal for your use case)

您可以像这样创建每个术语,并为所有术语分配随机值.

You can create each term like this and assign random values to all terms.

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)返回的所有值(使用一个精灵的坐标作为输入).将输出用作子画面的其他坐标.你应该很好走.

Now create an array of SineTerms and add all values returned by evaluate(x) (use one coordinate of sprite as input). Use the output as other coordinate of sprite. You should be good to go.

真正的诀窍是调整那些随机数.

The real trick would be in tuning those random numbers.

祝你好运.

这篇关于LibGDX指导-精灵跟踪2D无限随机贝塞尔曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆