我是 Libgdx 和 box2d 的新手。我需要画弧线。我搜索了一个功能,最后我想出了如下
public void drawarc (float centerx, float centery,float radius, float anglefrom, float anglediff, int steps)
{
EdgeShape ps = new EdgeShape();
FixtureDef psfd = new FixtureDef();
psfd.shape = ps;
BodyDef psbd = new BodyDef();
psbd.allowSleep = true;
psbd.awake = true;
psbd.position.set(centerx, centery);
psbd.gravityScale = 0;
Vector2[] vertices = new Vector2[steps];
for (int i = 0; i < steps; i++) {
double angle=Math.toRadians(anglefrom+anglediff/steps*i);
Vector2 sc = new Vector2((float)(radius * Math.cos(angle)),
(float)(radius * Math.sin(angle)));
vertices[i] = sc;
}
Body psd = world.createBody(psbd);
for (int i = 1; i < steps; i++) {
ps.set(vertices[i-1], vertices[i]);
psd.createFixture(psfd);
}
}
它工作正常,但我不确定它是否正确。请您检查并告诉我它是否有效/正确的方式?
谢谢