项目作者: hamaluik

项目描述 :
A GJK and EPA collision engine made with pure Haxe.
高级语言: Haxe
项目地址: git://github.com/hamaluik/headbutt.git
创建时间: 2017-04-20T22:57:58Z
项目社区:https://github.com/hamaluik/headbutt

开源协议:Apache License 2.0

下载


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:

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

Then, check shapes for intersections:

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

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

  1. var testResult = headbutt.twod.Headbutt.test(shapeA, shapeB);
  2. var intersection = headbutt.twod.Headbutt.intersect(testResult);
  3. // or:
  4. 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]