简体   繁体   English

libgdx 中的多边形顶点

[英]Polygon vertices in libgdx

How can I make the vertices of a polygon in libgdx?如何在 libgdx 中制作多边形的顶点? I am trying to make a pentagon for collision detection and I am kind of confused about how the vertices part is done, until now I used rectangle to achieve this我正在尝试制作一个用于碰撞检测的五边形,我对如何完成顶点部分感到困惑,直到现在我使用矩形来实现这一点

You should make several polygons since a pentagon is a convex shape and not easy to compute if a point is within the shape.您应该制作几个多边形,因为五边形是凸形,如果一个点在该形状内,则不容易计算。

To create a shape with the Polygon class you specify the vertices with a float array.要使用Polygon class 创建形状,您可以使用浮点数组指定顶点。 In sequence, you specify the x and y positions.依次指定 x 和 y 位置。 Since Polygon is a 2D shape in Libgdx the Z axis is not needed.由于Polygon在 Libgdx 中是二维形状,因此不需要 Z 轴。

Below is a polygon for a triangle shape, create your pentagon like this from multiple polygons and use Intersector to test the polygon vs various other geometry like lines and points.下面是三角形的多边形,从多个多边形创建这样的五边形,并使用Intersector测试多边形与其他各种几何形状(如线和点)。 Note, Intersector does contain method overlapConvexPolygon but I am pretty sure that gives true for something in between the points of your pentagon.请注意, Intersector确实包含方法overlapConvexPolygon ,但我很确定这对于五边形点之间的某些东西是正确的。

new Polygon(new Array[
0, 0,
10, 0,
5, 10
]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM