libgdx drawing arc curve(libgdx 绘制圆弧曲线)
问题描述
libgdx 的 arc 函数不是画圆弧而是画一个饼段(即有 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.)
该函数有一个填充弧"的第二部分(我同意,它应该被正确命名为饼"或楔"),但你不需要在这里,因为它会完全一样.
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 绘制圆弧曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:libgdx 绘制圆弧曲线
基础教程推荐
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01