Coder Social home page Coder Social logo

headbutt's Introduction

headbutt

GitHub license Build Status Docs

A GJK and EPA collision engine made with pure Haxe.

Usage

Create either 2D shapes or 3D shapes by implementing the appropriate interface: headbutt.twod.Shape / headbutt.threed.Shape. Or use one of the pre-defined shapes given in headbutt.twod.shapes / headbutt.threed.shapes:

  • 2D
    • Circle
    • Line
    • Rectangle
    • Polygon
  • 3D
    • Sphere
    • Line
    • Box
    • Polyhedron

Apply generic transformations to shapes:

var box = new Box(new Vec3(0.5, 0.5, 0.5));
box.transform = GLM.transform(
  new Vec3(5, -1, 3), // translation
  Quat.fromEuler(Math.PI / 4, 0, Math.PI / 3, new Quat()), // rotation
  new Vec3(2, 1, 4) // scale
);

Then, check shapes for intersections:

if(headbutt.twod.Headbutt.test(shapeA, shapeB)) { /*...*/ }
if(headbutt.threed.Headbutt.test(objectA, objectB)) { /*...*/ }

Alternatively, calculate intersections (note: intersection calculations haven't been implemented in 3D yet!):

var testResult = headbutt.twod.Headbutt.test(shapeA, shapeB);
var intersection = headbutt.twod.Headbutt.intersect(testResult);
// or:
var intersection = headbutt.twod.Headbutt.testAndIntersect(shapeA, shapeB);

API

API documentation is available.

Benchmarks

Benchmarks were run for the Node / Javascript target using haxe bench.hxml. The benchmarks were collected on an Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz with 16 GB of DDR4 RAM, running Linux Manjaro 19.0.0.

Benchmark Mean Time / Iteration
2D test line/line intersect 162.654 [ns] ± 2.982 [ns]
2D test line/line no intersect 126.105 [ns] ± 2.486 [ns]
2D test circle/circle intersect 246.520 [ns] ± 5.394 [ns]
2D test circle/circle no intersect 78.339 [ns] ± 1.650 [ns]
2D test pentagon/pentagon intersect 392.746 [ns] ± 2.768 [ns]
2D test pentagon/pentagon no intersect 126.104 [ns] ± 1.947 [ns]
2D intersect line/line 337.045 [ns] ± 2.785 [ns]
2D intersect circle/circle 11.901 [μs] ± 86.617 [ns]
2D intersect pentagon/pentagon 1.916 [μs] ± 8.471 [ns]
3D test sphere/sphere intersect 201.095 [ns] ± 2.095 [ns]
3D test sphere/sphere no intersect 69.234 [ns] ± 1.347 [ns]
3D test box/box intersect 194.634 [ns] ± 1.847 [ns]
3D test box/box no intersect 983.447 [ns] ± 7.303 [ns]

headbutt's People

Contributors

hamaluik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

headbutt's Issues

[QUESTION] plans for optimized collision detection

Hi,
I am wondering if there are any plans to implement any "smarter" way to check multiple collisions other than current way of testing everything against everything. As far I can tell some libs use quad/octo trees to narrow down possible candidates to test against. Is this something that's on the roadmap?

Thanks

MIT

Would like the core under MIT licence? Could you consider splitting examples tests into other repositories?

circle is different to your actual examples

just learning a bit on GJK & the such. but looking at the code & even trying to run it. it just errors with the Circle, due to it not having 2 values needed, but the examples show 2

thanks

how could you rotate objects?

as the title says. how could you go about rotating the objects as well, keeping the shape & making sure its actually rotating?

thanks again for this library. very lovely

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.