libgdx绘制圆弧曲线 [英] libgdx drawing arc curve

查看:145
本文介绍了libgdx绘制圆弧曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

libgdx的弧函数而不是绘制弧会绘制扇形段(即,有2条线连接到弧的原点)

The arc function of libgdx instead of drawing a arc draws a pie segment (ie. has 2 lines connecting to the arc's origin)

shapeRenderer.begin(ShapeType.Line);
shapeRenderer.arc(x, y, radius, 30, 120);
shapeRenderer.end();

是否有解决此问题的方法,以便libgdx可以绘制类似于html5 canvas arc函数的弧形曲线?

Is there a solution to this problem so that libgdx can draw an arc curve similar to the html5 canvas arc function?

推荐答案

阅读源代码,这似乎是内置行为:

Reading the source code, this seems built-in behavior:

/** Draws an arc using {@link ShapeType#Line} or {@link ShapeType#Filled}. */
public void arc (float x, float y, float radius, float start, float degrees, int segments) {
    if (segments <= 0) throw new IllegalArgumentException("segments must be > 0.");
    float colorBits = color.toFloatBits();
    float theta = (2 * MathUtils.PI * (degrees / 360.0f)) / segments;
    float cos = MathUtils.cos(theta);
    float sin = MathUtils.sin(theta);
    float cx = radius * MathUtils.cos(start * MathUtils.degreesToRadians);
    float cy = radius * MathUtils.sin(start * MathUtils.degreesToRadians);

    if (shapeType == ShapeType.Line) {
        check(ShapeType.Line, ShapeType.Filled, segments * 2 + 2);

        renderer.color(colorBits);
        renderer.vertex(x, y, 0);           <--- CENTER
        renderer.color(colorBits);
        renderer.vertex(x + cx, y + cy, 0); <--- LINE TO START POINT
        for (int i = 0; i < segments; i++) {
            renderer.color(colorBits);
            renderer.vertex(x + cx, y + cy, 0);
            float temp = cx;
            cx = cos * cx - sin * cy;
            cy = sin * temp + cos * cy;
            renderer.color(colorBits);
            renderer.vertex(x + cx, y + cy, 0);
        }
        renderer.color(colorBits);
        renderer.vertex(x + cx, y + cy, 0); <-- LINE TO END POINT
...

最简单的方法可能是复制整个函数,并至少抛出我标记的两行: CENTER LINE TO END POINT ,以及随附的renderer.color(..每行上方.

Easiest is probably to copy the entire function and at least throw out two of the lines I marked: CENTER and LINE TO END POINT, along with the accompanying renderer.color(.. line above each.

(您还可以删除 LINE TO START POINT –它出现 来设置曲线的起点,但实际上也是在循环内完成的,因此是多余的)

(You can also delete the LINE TO START POINT – it appears to set the starting point for the curve, but that's actually also done inside the loop, so it's redundant.)

该函数的第二部分是填充的弧"(我同意,应该正确地将其命名为"pie"或"wedge"),但是您在这里不需要它,因为它的作用完全相同.

The function has a second part for a filled "arc" (I agree, it should have properly been named "pie" or "wedge"), but you don't need that here because it would do exactly the same.

如果您可以使用它,可以将其建议给libgdx的维护者,例如在 libgdx的贡献论坛.

If you get it to work, you could propose it to libgdx's maintainers, for example on libgdx's Contributions Forum.

这篇关于libgdx绘制圆弧曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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