Collider2D is a simple, object-oriented library for 2D collision detection.
Visual C++ ( 32-bit | 64-bit )
In the project's properties, add:
- The path to the Collider2D headers (collider2d-install-path/include) to C/C++ > General > Additional Include Directories
- The path to the Collider2D libraries (collider2d-install-path/lib) to Linker > General > Additional Library Directories
These paths are the same in both Debug and Release configuration.
Library must be added in the project's properties, in Linker > Input > Additional Dependencies.
- For Debug -
Collider2D-d.lib
- For Release -
Collider2D.lib
The library uses the cd::
namespace.
#include <vector>
#include <CollisionDetection.hpp>
int main()
{
// create array of vertices
std::vector<cd::Vector2<float>> vertices(5);
// initialize it
vertices[0] = cd::Vector2<float>(100.f, 80.f);
// ...
// create a convex shape from array of vertices
cd::ConvexCollision convex(&vertices[0], vertices.size());
// create another circle collision from its position and radius
cd::CircleCollision circle(cd::Vector2<float>(100.f, 100.f), 50.f);
// check if collisions overlap
if (convex.intersects(circle))
{
// do something
}
// you can change the collisions
convex[2].x = 20.f;
convex[4] = cd::Vector2<float>(50.f, 50.f);
circle.setRadius(150.f);
// create a point
cd::Vector2<float> point(80.f, 80.f);
// check if collisions contain the point;
if (convex.contains(point))
{
// do something
}
if (circle.contains(point))
{
// do something
}
return 0;
}
- AABB
- Circle
- Convex
- Compound
For CompoundCollision there are the following PrimitiveTypes:
- Triangles
- TriangleFan
- TriangleStrip
The Collider2D libraries and source code are under MIT license.
The example uses SFML which is under zlib/png license.