All Projects → tangrams → isect2d

tangrams / isect2d

Licence: MIT license
2D Geometry Intersection Library

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

isect2d

00

Collision detection algorithms, using basic tile grid for broad-phase and separating axes theorem (SAT) for narrow-phase.

Example

// Provide your own vector 2d implementation
#ifdef USE_GLM
using Vec2 = glm::vec2;
#else
using Vec2 = isect2d::Vec2;
#endif

std::vector<isect2d::OBB> obbs;
std::vector<isect2d::AABB> aabbs;

// Init the set of OBBs from the AABBs set
for (auto& obb : obbs) {
    auto aabb = obb.getExtent();
    aabbs.push_back(aabb);
}

Using the Isect2D context

isect2d::ISect2D<Vec2> context({16, 16}, {800, 600});

context.clear();

// Broadphase
context.intersect(aabbs);

// Narrow-phase
for (auto& pair : context.pairs) {
    if (intersect(obbs[pair.first], obbs[pair.second])) {
        // Both oriented bounding boxes collide
    }
}

Using the naive grid based implementation

// Broadphase
auto pairs = intersect(
    aabbs, 
    {4, 4},     // split resolution  
    {800, 600}, // screen resolution
);

// Narrow-phase
for (auto& pair : pairs) {
    if (intersect(obbs[pair.first], obbs[pair.second])) {
        // Both oriented bounding boxes collide
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].