headbutt

GJK and EPA based collision detection and intersection calculation
https://github.com/hamaluik/headbutt

To install, run:

haxelib install headbutt 0.6.0 

See using Haxelib in Haxelib documentation for more information.

README.md

headbutt

GitHub license Build Status

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 each target using the results from haxe bench.hxml. The benchmarks were collected on a Ryzen 3600 CPU with 32 GB of DDR4 3200 MHz ram.

TestIntersectCpp (μs/iter)Hashlink (μs/iter)Node/Javascript (μs/iter)Python (μs/iter)Interp (μs/iter)
line/line0.5 ± 0.14.4 ± 0.10.3 ± 1.118.6 ± 0.110.8 ± 0.1
line/line0.3 ± 02.5 ± 0.10.2 ± 0.612 ± 0.16.8 ± 0
circ/circ0.5 ± 0.15.5 ± 0.10.3 ± 0.923.8 ± 0.112.8 ± 0.1
circ/circ0.2 ± 00.9 ± 00.1 ± 0.34.5 ± 0.12.6 ± 0
pent/pent0.6 ± 0.17.5 ± 0.10.4 ± 1.155.4 ± 0.224.5 ± 0.1
pent/pent0.2 ± 01.9 ± 00.1 ± 0.315.1 ± 0.36.7 ± 0
Contributors
FuzzyWuzzie
hamaluik
Version
0.6.0
Published
5 years ago
Dependencies
License
Apache

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub