A library for 2d shapes and collisions

In java, we have Shape interface which defines a bunch of shapes and handles collisions. But I dont think these are strong enough. The collision methods dont take the rotation of the shape into consideration, for exmaple.

So I am looking for something more powerful. Something that at least support the following shapes:

  • Rectangles
  • Circles
  • Polygons

Use box2D. If you need 3D use bullet. These are the libraries that are the most widely used and supported.
Box2D: http://www.jbox2d.org/
Bullet: http://jbullet.advel.cz/

Hi!

I am working with 2d. However, Box2D is a physics engine and way to much for what I need.

You will have to make you own for something lighter.

Put some time into it you and you will end up with something less bloated. Plus, it will be a great learning experience.

If you need torquing and shapes, you are in the realm of a physics engine. Use box2D. This will give you the most consistent outputs and will be something actually usable.

If you just want shaped collisions, look into Separating Axis Theorem.

There is no simple in between that I know of, because anyone who puts that much work into their collisions will just opt for the library that handles what they need already and is well established.

For specific suggestions, some more info would be helpful, such as:

  • Exactly what shapes you want to support (e.g. oriented rectangles or axis-aligned rectangles only).
  • Whether you need continuous collision detection, or discrete only.
  • Whether you need collision response, or collision detection only.

And anything else you think might be relevant. That should help narrow things down as to whether an existing solution like Box2D would be suitable, or whether a more lightweight custom solution would be a practical option.

If you want to create your own physic library you may want to look a these tutorials.
It will show you how to create some physic from scratch.