How to increase number of vertices of polygon (BOX2D)

Discuss issues specific the Java port of Box2D
Khubaib
Posts: 13
Joined: Sat Jul 12, 2014 12:44 pm

How to increase number of vertices of polygon (BOX2D)

Postby Khubaib » Sun Dec 28, 2014 3:31 am

Does anyone know how to increase maximum number of vertices for a polygon. Currently default value is 8 but I want at least 30 vertices for a polygon shape. Any help is appreciated :geek:

isaacburns
Posts: 4
Joined: Tue Nov 19, 2013 8:10 am

Re: How to increase number of vertices of polygon (BOX2D)

Postby isaacburns » Sun Dec 28, 2014 7:29 am

It should be as easy as changing the constant in the source.

https://github.com/jbox2d/jbox2d/blob/m ... s.java#L91

Although, expect a memory/performance hit if you're increasing it to 30.

Another option is to use a physics editor to generate multiple polygon shapes from the 30 vertices. The R.U.B.E. Box2D editor has a feature for this.

https://www.iforce2d.net/rube/

Physics Editor is another.

https://www.codeandweb.com/physicseditor/

Khubaib
Posts: 13
Joined: Sat Jul 12, 2014 12:44 pm

Re: How to increase number of vertices of polygon (BOX2D)

Postby Khubaib » Mon Dec 29, 2014 10:38 pm

thanks for your reply isaacburns!
I am using Physics Editor by codeandweb but most number of vertices for most of the shapes it generates are greater than 8 (normally in the range of 12-20). Thats why i was looking to increase the number of vertices of the polygon in box2d

isaacburns
Posts: 4
Joined: Tue Nov 19, 2013 8:10 am

Re: How to increase number of vertices of polygon (BOX2D)

Postby isaacburns » Wed Dec 31, 2014 7:54 am

Perhaps you are using the hull polygon from the data exported from Physics Editor.

Instead, use the list of convex sub-polygons. These are limited to the default maximum number of vertices (8) in Box2D.

Create a b2PolygonShape from each of these and attach them to the same b2Body.

Khubaib
Posts: 13
Joined: Sat Jul 12, 2014 12:44 pm

Re: How to increase number of vertices of polygon (BOX2D)

Postby Khubaib » Thu Jan 01, 2015 12:02 pm

ok thanks a lot buddy :)


Return to “Java”



Who is online

Users browsing this forum: No registered users and 2 guests