Bézier曲线,用于在单一游戏上进行平滑素描

时间:2014-02-20 08:10:15

标签: windows-phone monogame bezier sketching

我是一名MonoGame开发者,我想在手机屏幕上绘制一条曲线但是,曲线不是规则而是生涩,由几行组成。

我使用了这样的代码:

第一种方法绘制精灵间隔开的精灵,如下所示:

 // increment is how far apart each sprite is drawn
private void DrawEvenlySpacedSprites(Texture2D texture, Vector2 point1, Vector2 point2, float     increment)
{
    var distance = Vector2.Distance(point1, point2);    // the distance between two points
    var iterations = (int)(distance / increment);       // how many sprites with be drawn
    var normalizedIncrement = 1.0f / iterations;        // the Lerp method needs values between 0.0 and 1.0
    var amount = 0.0f;

    if(iterations == 0)
        iterations = 1;

    for (int i = 0; i < iterations; i++)
    {
        var drawPoint = Vector2.Lerp(point1, point2, amount);
        _spriteBatch.Draw(texture, drawPoint, Color.White);
        amount += normalizedIncrement;
    }
}

更新方法:

private Vector2? _previousPoint;
protected override void Update(GameTime gameTime)
{
    TouchCollection touches = TouchPanel.GetState();

    foreach (TouchLocation touch in touches)
    {
        if (touch.State == TouchLocationState.Moved)
        {
            GraphicsDevice.SetRenderTarget(renderTarget);
            _spriteBatch.Begin();

            if (_previousPoint.HasValue)
                DrawEvenlySpacedSprites(texture, _previousPoint.Value, touch.Position, 0.5f);

            _spriteBatch.End();
            GraphicsDevice.SetRenderTarget(null);
        }
    }

    if (touches.Any())
        _previousPoint = touches.Last().Position;
    else
        _previousPoint = null;

    base.Update(gameTime);
}

我有这个结果:

enter image description here

为了解决这个问题,我试图使用贝塞尔曲线,但我无法实现这个解决方案。

拜托,能帮帮我吗。

等待您的宝贵意见和建议。

0 个答案:

没有答案