Performance questions about box2D

Hi guys,

first of all thanks for this amazing library! It was not easy to get into box2d but I just love it now 🙂 I downloaded it 4 days ago and integrated into a game I'm working on. It's a boat racing game, so there is no gravity in my world, I'm using box2d to do the collisions in-between the boats and some other dynamical objects and then a lot of static "edges" that describe the track. I'm using 2.1.2 version of box2d.

I already have few questions considering the performance and hope you would help me. I'm real noob when it comes to physics so some of my questions may be very easy for you 🙂

Which shape is better to be used for simple dynamic objects, box or sphere? I assume it's a sphere as the collision calculation would be faster on that, am I right? Can you estimate how much more it takes to collide 10 dynamic objects of a box and then of a circle shape? I'm asking as it would be nice to use box shape, as then I have a nice rotation of the box after the collision as well, which is not the case with sphere shape.

As I mentioned the track is described with "edges", using the SetAsEdge method of b2PolygonShape. Is this the best solution or would it be worth describing the surrounding of the track using convex polygons? I'm not sure if providing the information in this form can help box2d solve the collisions faster or easier?

Thanks a lot for your time and I'll post some video later 😉
Circles are faster than boxes. But I wouldn't worry about it unless it is affecting your frame rate.

Edge shapes are the way to go for environment boundaries. I'll be working to improve these in the near future.
Thanks for you quick answer Erin!

The game is for iPhone and I'm already hitting the limits of the device, so every little speedup is more than welcome in my case 🙂 I'll use circles for the small floating objects then, and maybe fake the rotation by spinning the circles after collision or something like that. Does not matter much if the rotation orientation is physically correct, it just looks better when they rotate 🙂

Other question I have is that the way I move the boats now is that I'm applying a force to them using ApplyForce() method. I was wondering if this is the fastest option - again speaking of calculations box2d needs to do - or if it's worth using SetLinearVelocity() to move the boats. It won't be hard to change, I just don't know which one may be faster, any ideas?

Also for the rotation I apply force to the tip of the boat and it turns - should I rather use ApplyAngularImpulse() to do that?

The promised video is uploading right now.. I'll post the link once it's finished.

Thanks a lot for your help and looking forward to your ideas!
Here is the video 😉

http://vimeo.com/11236701
Looks fun! I would try to use boxes if you can because they will collide better with each other. ApplyForce has negligible cost.

Original thread: https://box2d.org/forum/viewtopic.php?t=4870