6

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?

Boldijar Paul
  • 5,405
  • 9
  • 46
  • 94

1 Answers1

7

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.

noone
  • 19,520
  • 5
  • 61
  • 76
  • 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 06 '14 at 17:05
  • 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 06 '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 06 '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 06 '14 at 18:09
  • I didn't realize myself at the beginning that the input is a float array, not just vertices and was just going to explain. Glad that it worked out :) – noone Feb 06 '14 at 18:10