2012-07-06 197 views
2

我得到一个意外的ArrayIndexOutOfBoundsException此代码;谁能帮忙?多边形到多边形碰撞libgdx

我创建两个多边形是这样的:

float[]vertice={.1f, 2.7f, .4f, 4.3f, 3.4f, 5.3f, 5.6f, 3.3f, 3.3f, .1f}; 
Polygon oPolygon1=new Polygon(vertice); 

float[]vertice2={.2f,1.3f,1.9f,4.5f,4.1f,1.3f}; 
Polygon oPolygon2=new Polygon(vertice2); 

并与更新他们的立场:

oPolygon1.setPosition(x1,y1); 
oPolygon2.setPosition(x2,y2); 

但是,当我尝试使用Intersector,看看他们是否重叠?

if(Intersector.overlapConvexPolygons(oPolygon1, oPolygon2)){ 
    //do something 
} 

...我得到以下错误:

Exception in thread "LWJGL Application" java.lang.ArrayIndexOutOfBoundsException:

在这个代码块内的Intersector

// projection axis is perpendicular to potential separation axis edge i->j 
float projX = verts1[j + 1] - verts1[i + 1]; 
float projY = verts1[i] - verts1[j]; 
+0

你有多边形的截图吗?我只是猜测一个人可能不是凸面的。 – 2012-07-06 19:57:19

+0

他们是凸的,这是一个错误,现在它的固定=) – Tiarsoft 2012-10-22 01:12:13

+1

请标记下面的答案为“接受”,如果它回答你的问题:http://stackoverflow.com/faq#howtoask谢谢! – 2012-10-22 03:08:29

回答

4

这似乎是在LibGDX的错误。在行设置projX中,它应该包装索引

float projX = verts1[(j + 1) % length1] - verts1[i + 1]; 

我会在SVN中得到这个修复。