2013-11-20 91 views
1

如何獲取libgdx中特定多邊形體的頂點列表?獲取多邊形形狀體的頂點列表

像這樣:

public Array<Vector2> getVerts(Body body){ 
    Array<Vector2>verts = null; 

    // can't find how to look them up properly anywhere 

    return verts; 
} 

謝謝!

回答

1

基於@詹姆斯韋伯斯特代碼:

Array<Vector2> verts = new Array<Vector2>(); 
Fixture f = body.getFixtureList().get(0); 
PolygonShape s = f.shape; 

// this is needed to temporarily keep the vertex, getVertex is a void method 
Vector2 tmp = new Vector2(); 
for (int i = 0; i < s.getVertexCount(); i++) { 
    // fill tmp with the vertex 
    s.getVertex(i, tmp)); 
    verts.add(new Vector2(tmp)); 
} 
+0

的偉大工程,謝謝! – user2989675

+0

downvoted這個人可以解釋downvote嗎? – noone

3

我還沒有LibGDX工作,但我已經有Box2D的工作,看API,我建議:

//Assuming only 1 fixture per body and a polygon shape 


Array<Vector2>verts = new Array<Vector2>(); 
Fixture f = body.getFixtureList().get(0); 
PolygonShape s = f.shape; 
for (int i = 0; i < s.getVertexCount(); i++) 
{ 
    verts.add(s.getVertex(i, /*I couldn't figure out what this param is supposed to be*/)); 
} 

這沒有一個IDE被鍵入,注意明顯的錯誤!我也很久沒有做Java了。