目录

我的学习分享

记录精彩的程序人生

X

【LibGDX】LibGDX BOX2D change maxPolygonVertices

https://stackoverflow.com/questions/21606528/libgdx-box2d-change-maxpolygonvertices?r=SearchResults

I need to make a body with more than 8 vertices, and i get the error.

AL lib: (EE) alc_cleanup: 1 device not closed
Assertion failed!

Program: C:\Program Files\Java\jre7\bin\javaw.exe
File: /var/lib/jenkins/workspace/libgdx/gdx/jni/Box2D/Collision/Shapes/b2PolygonShape.cpp, Line 122

Expression: 3 <= count && count <= 8

How can I change that constant?

I found this file https://github.com/libgdx/libgdx/blob/master/gdx/jni/Box2D/Common/b2Settings.h

Here i saw

#define b2_maxPolygonVertices 8

How can I change it from libGDX?

1 Answer

Actually you should not change that, since it would decrease the performance.

What you would do instead is create a Body with several Fixtures. Those fixtures will have max 8 vertices and will share some of the vertices, so you will simulate a bigger piece using smaller parts, which are stuck together.

This is called polygon decomposition. Some editors for Box2D do that automatically for you, when you export your scene. Probable the best editor for Box2D out there is R.U.B.E.. There is also a libgdx loader for rube scenes here.

If you create them programmatically you would probably have to do this yourself. Maybe some LibGDX tools like the EarClippingTriangulator could help you here.

  • Ok so lets say i have a float array of vertices, that has more than 8 points, how can I use the earclippingtriangulator ? – Boldijar Paul Feb 6 '14 at 17:05

  • My code pastebin.com/L7wjqHbt . How should i use it? – Boldijar Paul Feb 6 '14 at 17:30

  • It triangulates your polygon. The array you get is an array with indices of the triangles. You would take 3 each and construct a new Fixture of it. That means array[sa.get(0)], array[sa.get(1)],array[sa.get(2)] would be the vertices you would use for one of the new trinagular fixtures. – noone Feb 6 '14 at 17:50

  • But, a triangle has 3 points , x1 y1 x2 y2 x3 y3, how can just 3 float values work? I need 6 ..i didn't gave the points by a vector2 array i did by float[] array where is like [x1 , y1, x2, y2.....xn,yn] ... I get error Expression: 3 <= count && count <= 8 – Boldijar Paul Feb 6 '14 at 17:59

  • Ops i found out that the values from the short array are the indices of the vector2 array that would be , and i also created a vector2 array from the float array and this worked, thank you! – Boldijar Paul Feb 6 '14 at 18:09

——————————————————————————————————————
简单来说,就是改不了。。。

要么就改源码,重新编译box2d组件