在我的 libgdx android 应用程序中,我使用以下代码创建箭头
@Override
public void onAxonConnected(Pos one, Pos two) {
Model lineModel = build.createArrow(one.x, one.y, one.z, two.x, two.y, two.z, 0.15 f, 0.05 f, 5, GL20.GL_TRIANGLES, new Material(), VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
ModelInstance line = new ModelInstance(lineModel);
this.addArrowModelInstanceToRender(line);
}
如何防止较长的箭头变得比较短的连接箭头“更粗”?
我假设某处发生了一些乘法,但我宁愿让它们全部以相同的宽度和箭头大小渲染。通过 createArrow 可以实现这一点吗?还是我必须为此推出自己的模型?
最佳答案
一种解决方案是计算代表箭头起点和终点的两个 vector 之间的距离,然后将该值传递给 capLength 和 StemThickness 乘以或除以一个常数(或两个)。
Vector3 start = new Vector3(one.x, one.y, one.z);
Vector3 end = new Vector3(two.x, two.y, two.z);
float distance = start.dst(end);
Model lineModel = build.createArrow(one.x, one.y, one.z, two.x, two.y, two.z, CAP_LENGTH_CONSTANT / distance, STEM_THICKNESS_CONSTANT / distance, 5, GL20.GL_TRIANGLES, new Material(), VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
您可能需要稍微测试一下数字才能找到正确的常量
关于java - 防止使用 ModelBuilder.createArrow 创建时箭头较长时为 "fatter",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55047175/