Giter Club home page Giter Club logo

abby's Introduction

abby Build status Build Status version Language License

A header-only implementation of an AABB tree.

Purpose

Collision detection is common in many applications, especially games. Subsequently, collision detection often require checking for potential collision between many different game objects, and as such it is important that the collision detection is efficient. A naive implementation will end up with quadratic complexity, which isn't very scalable. By using an AABB tree, bounding hitboxes are stored in a tree according to their position and size, which in turn enables logarithmic complexity for collision detection.

Example

  #include <abby.hpp>
  #include <iterator> // back_inserter
  #include <vector>   // vector
  #include <iostream> // clog

  void foo()
  {
    // Constructs an AABB tree that uses integers as identifiers and AABBs with double precision
    abby::tree<int, double> tree;

    // Inserts a few AABBs, takes a lower and upper bound
    tree.insert(1, {150.0, 165.0}, {50.0, 50.0});
    tree.insert(2, {88.0, 63.0}, {150.0, 343.0});
    tree.insert(3, {412.0, 132.0}, {566.0, 291.0});

    // Could also use a stack buffer
    std::vector<int> candidates;  

    // Find collision candidates
    tree.query(1, std::back_inserter(candidates));  
    for (const auto candidate : candidates) {
      // Obtains an AABB
      const auto& aabb = tree.get_aabb(candidate);
    }
  
    // Prints the tree using a stream
    tree.print(std::clog);

    // Updates an existing AABB
    tree.update(2, {33.0, 76.0}, {123.0, 155.0});

    // Sets the position of an AABB
    tree.relocate(2, {12.0, 34.0});

    // Removes an AABB from the tree
    tree.erase(2);

    // Rebuild as optimal tree
    tree.rebuild();

    // Clear the tree of all entries
    tree.clear();
  }

Acknowledgements

This library is an adapted and improved version of the AABBCC library. Furthermore, the AABB tree in the Simple Voxel Engine project also influenced the design of this library.

abby's People

Contributors

albin-johansson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

abby's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.