Skip to content
A GJK and EPA collision engine made with pure Haxe.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
samples
src/headbutt
test
.gitignore
.travis.yml
LICENSE
README.md
completion.hxml
haxelib.json
test.interp.hxml

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

Then, instantiate an instance of the appropriate Headbutt:

var hb2 = new headbutt.twod.Headbutt();
var hb3 = new headbutt.threed.Headbutt();

Next, check shapes for intersections:

if(hb2.test(shapeA, shapeB)) { /*...*/ }
if(hb3.test(objectA, objectB)) { /*...*/ }

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

var penetration: Null<Vec2> = hb2.intersect(shapeA, shapeB);

API

2D

// headbutt.twod.Shape
interface Shape {
    public var origin(get, set): Vec2;
    public function support(direction: Vec2): Vec2;
}
// headbutt.twod.Headbutt
class Headbutt {
    /**
       The maximum number of simplex evolution iterations before we accept the
       given simplex. For non-curvy shapes, this can be low. Curvy shapes potentially
       require higher numbers, but this can introduce significant slow-downs at
       the gain of not much accuracy.
    */
    public var maxIterations:Int = 20;

    /**
       Create a new Headbutt instance. Headbutt needs to be instantiated because
       internally it stores state. This may change in the future.
    */
    public function new();

    /**
       Given two convex shapes, test whether they overlap or not
    */
    public function test(a: Shape, b: Shape): Bool;

    /**
       Given two shapes, test whether they overlap or not. If they don't, returns
       `null`. If they do, calculates the penetration vector and returns it.
    */
    public function intersect(a: Shape, b: Shape): Null<Vec2>;
}

3D

// headbutt.threed.Shape
interface Shape {
    public var origin(get, set): Vec2;
    public function support(direction: Vec2): Vec2;
}
// headbutt.threed.Headbutt
class Headbutt {
    /**
       The maximum number of simplex evolution iterations before we accept the
       given simplex. For non-curvy shapes, this can be low. Curvy shapes potentially
       require higher numbers, but this can introduce significant slow-downs at
       the gain of not much accuracy.
    */
    public var maxIterations:Int = 20;

    /**
       Create a new Headbutt instance. Headbutt needs to be instantiated because
       internally it stores state. This may change in the future.
    */
    public function new();

    /**
       Given two convex shapes, test whether they overlap or not
    */
    public function test(a: Shape, b: Shape): Bool;
}
You can’t perform that action at this time.