• Stars
    star
    166
  • Rank 227,748 (Top 5 %)
  • Language Haxe
  • License
    MIT License
  • Created about 12 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A separation axis theorem collision library for Haxe.

Logo


What is differ?

A Separating Axis Theorem collision library for haxe

haxe


Facts

  • Implements Separating Axis Theorem, for collision detection.
  • Supports convex polygons, circles, and rays.
  • 2D only (for now).
  • Includes a simple drawing interface for debugging shapes
  • COLLISION ONLY. No physics/response - this is by design.
  • Contributions welcome

Quick look

A simple collision example

    var circle = new Circle( 300, 200, 50 );
    var box = Polygon.rectangle( 0, 0, 50, 150 );

    box.rotation = 45;

    var collideInfo = Collision.shapeWithShape( circle, box );

    if(collideInfo != null) {
        //use collideInfo.separationX
        //    collideInfo.separationY
        //    collideInfo.normalAxisX
        //    collideInfo.normalAxisY
        //    collideInfo.overlap
    }

See tests/ for usage examples and tests

Other notes

API documentation

https://snowkit.github.io/differ/

Demos

Main Contributors

view all contributors


History

1.4.0 (Latest release, haxelib)

  • Fixes for newer haxe versions
  • Fix Polygon.testRay ignoring 'into' parameter

1.3.0

The goal of this release is as follows :

  • Reduce the usage of Vector internally, simplifying the code to primitives
  • Remove allocations, myriads of them the old code had that carried over
  • Add ways to reuse allocated results for efficiency when querying
  • Add more test/example cases
  • Expose the alternative polygon vs shape overlaps to make better choices based on movement
  • Move the code more forward to be internally consistent and maintainable
  • Fix the bugs with the rays and add more useful infinite flags

All of this was achieved, with the following changes.

  • Refactor continued clean up
    • remove all allocations in SAT2D, except for results if not provided
    • refactor away internal uses of Vector
    • remove superfluous use of Vector in the API
      • ShapeDrawer: drawLine,drawPoint
      • Collision.pointInPoly
  • Added Ray infinite mode instead of boolean
    • Not infinite
    • Infinite from start position
    • Infinite in both directions
  • Added Rays test in usage0
  • Added ShapeCollision/RayCollision/RayIntersection
    • added clone(), copy_from(other), reset()
  • Added differ.math.Util
    • removes internal SAT2D use of the Vector class
  • Added into argument for all internal and external calls
    • this reuses the existing instance for the result
    • all calls will always reset the collision result
    • all direct calls still return null as "no result"
    • added Results<T> results cache helper
    • all plural calls return Results<T>
  • Fixed Bug in testCircleVsPolygon
    • When testing polygon vs circle values were flipped/wrong
  • Fixed Bug in rayVsRay with a negative overlap
  • Removed Common util class, it's internal to SAT2D and simplified now
  • Removed drawVector in ShapeDrawer, wasn't used (use drawLine if needed)

1.2.0

The biggest change for sure, renamed hxcollision to differ Now that the library is getting more use its better to have a consistent name and to have a more explicit path. Think of "differ" as a diff tool for shapes/rays, it tells you how shapes differ (i.e the separation).

  • Added ray collision information, rather than just true/false
  • Added ray vs ray intersection with info on overlap
  • Added more granular tests, that will expand further
    • New test case uses luxe https://luxeengine.com/
    • hxcollision/differ was born for luxe.collision, separate for any framework
  • Refactor continued separating code for future 3D vs 2D
    • moved all internal 2D code into differ.sat.SAT2D
    • moved all internal common code into differ.sat.Common
  • Renamed Collision.test to Collision.shapeWithShape
  • Renamed Collision.testShapes to Collision.shapeWithShapes
  • Renamed Collision.rayShape to Collision.rayWithShape
  • Renamed Collision.rayShapes to Collision.rayWithShapes
  • Renamed Collision.rayRay to Collision.rayWithRay
  • Renamed Collision.rayRays to Collision.rayWithRays
  • Renamed Collision.rayRays to Collision.rayWithRays
  • Renamed data.CollisionData to data.ShapeCollision
  • Renamed data.RayCollisionData to data.RayCollision
  • Renamed data.RayIntersectionData to data.RayIntersection
  • Removed OpenFLDrawer, will replace with gist or test later

1.1.0

  • Added documentation and clean up of code
  • Renamed Vector2D to Vector and cleaned up code to ONLY what is needed. This class is meant to be as small and easy to integrate as possible.
  • Refactor for easier maintaining in embedded libraries
  • Renamed BaseShape to Shape, continued refactoring
  • Renamed Collision.testShapes to Collision.test
  • Renamed Collision.testShapeList to Collision.testShapes
  • Renamed Collision.rayCollision to Collision.ray
  • Fixed various bugs in collisions
  • Fixed separation/unitVector behaviour (signs bugs)
  • Fixed bug with Polygon/Polygon collisions not returning best vectors
  • Fixed bug where you couldn't beginFill using OpenFLDrawer
  • Fixed collisionData in CheckCircles, shape2 wasn't assigned.
  • Fixed separation/unitVector is now bound to shape1 as it should be
  • Added 2 samples (usage2 & usage3)
  • Added drawVector in OpenFLDrawer showing vector direction
  • Added drawShape in ShapeDrawer, will cast proper types and call appropriate drawing functions.

1.0.4

  • Renamed Polygon.normalPolygon to Polygon.create
  • Added testShapeList for testing one shape with many
  • Added changes to the test to display the unitVector response (soon to be renamed also)
  • Refactor to more integration friendly api, and more logical order of arguments for shapes.
  • Fixed rotation on the base shapes absolute (submitted by @grapefrukt).
  • Added name and data flag to BaseShape

1.0.3

  • Fixed bug in circle vs polygon, when polygon was rotated.
  • Added line raycast with collision shapes
  • Added a custom ShapeDrawer class, for drawing the shapes in a non specific way.
  • Update to latest haxelib revisions
  • Removed dependency on OpenFL, now completely standalone

1.0.2

  • uncommitted internal fixes

1.0.1

  • Added an option for Polygon.rectangle() to be non-centered

1.0.0

  • Initial project pull and compile/port, functional

 

More Repositories

1

snow

A low level cross platform framework for Haxe. Mac, Windows, Linux, Android, iOS, WebGL.
Haxe
133
star
2

hxcpp-guide

A guide for the Haxe CPP target build systems, CFFI and APIs
80
star
3

mint

A framework/renderer agnostic Minimal UI interface library for Haxe.
Haxe
65
star
4

flow

flow
JavaScript
63
star
5

atom-haxe

atom.io haxe plugin, includes completion, error checking and more.
JavaScript
43
star
6

gif

Haxe GIF encoder, implementing the NeuQuant and LZW encoding algorithms
Haxe
40
star
7

linc_sdl

http://snowkit.github.io/linc/ Haxe/hxcpp @:native bindings for SDL
Haxe
31
star
8

tides

Haxe tools for IDE support
Haxe
26
star
9

linc

A collection of Haxe native libraries for hxcpp. SDL, OpenGL, OpenAL and more.
CSS
23
star
10

linc_dialogs

http://snowkit.github.io/linc/ Haxe @:native bindings for Open, Folder, and Save dialogs
C++
19
star
11

linc_enet

http://snowkit.github.io/linc/ Haxe/hxcpp @:native bindings for Enet networking
Haxe
14
star
12

gifcapture

A threaded Haxe GIF capture recording helper
Haxe
13
star
13

linc_nanovg

http://snowkit.github.io/linc/ Haxe/hxcpp @:native bindings for nanovg
C
13
star
14

linc_openal

http://snowkit.github.io/linc/ Haxe/hxcpp @:native bindings for OpenAL
C
12
star
15

linc_ogg

http://snowkit.github.io/linc/ Haxe/hxcpp @:native bindings for Ogg vorbis decoding
Haxe
9
star
16

linc_stb

http://snowkit.github.io/linc/ Haxe/hxcpp @:native bindings for stb libraries
C
9
star
17

linc_empty

http://snowkit.github.io/linc/ An empty linc library
Haxe
8
star
18

linc_opengl

http://snowkit.github.io/linc/ Haxe/hxcpp @:native bindings for OpenGL
C
8
star
19

sublime_haxe

WIP refactoring of Sublime Text support for Haxe (see readme)
Python
7
star
20

ktx-format

https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/
Haxe
6
star
21

atom-flow

atom.io support for haxe flow build tool
JavaScript
6
star
22

linc_filewatch

http://snowkit.github.io/linc/ Haxe/hxcpp @:native bindings for OS file change notifications
C++
5
star
23

sublime_flow

Sublime Text support for Haxe flow build tool
Python
5
star
24

iqm

Haxe importer for IQM mesh format | https://github.com/lsalzman/iqm
Haxe
5
star
25

linc_timestamp

http://snowkit.github.io/linc/ Haxe/hxcpp @:native bindings for high precision timestamp
C++
5
star
26

linc_glew

http://snowkit.github.io/linc/ Haxe/hxcpp @:native bindings for GLEW
C
4
star
27

linc_icloud

http://snowkit.github.io/linc/ Haxe/hxcpp @:native bindings for iCloud
Haxe
3
star
28

support

A place to ask questions, give feedback, and discuss the snowkit collective and it's initiatives
3
star