2012-07-06 190 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中得到這個修復。