GithubHelp home page GithubHelp logo

snowkit / differ Goto Github PK

View Code? Open in Web Editor NEW
165.0 20.0 28.0 2.24 MB

A separation axis theorem collision library for Haxe.

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

License: MIT License

Haxe 100.00%

differ's Introduction

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

 

differ's People

Contributors

beeblerox avatar dvergar avatar francoisvn avatar keymaster- avatar lunabunn avatar player-03 avatar ruby0x1 avatar samnm avatar ubald 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

differ's Issues

testShapeWithShapes preallocated results

The best implementation we discussed was a simple custom container that keeps a set of preallocated results.

You'd create one with a fixed size to start, then upon use, it resets each as it populates them. It keeps track of how many are set in the length property, then it can be iterated normally and the length property will correctly reflect the number of valid results, as well as correctly respond to [ ] operator.

This is the last place needing an into argument, which the type of would be this container.

Implement inactivity

There's no reason to test a collision if the source (shape1) is not moving.
One way would be to set a boolean whenever there's a change to x/y/rotation. Not sure if there are other accessors for the user. Will check.

Unexpected behaviour when using Shape.scaleX and Shape.scaleY properties.

When using the scaleX and scaleY properties, polygons seems to be incorrectly transformed. When examining transformed vertices of a polygon, it appears that scale transformation is applied for both X and Y, even when only one of the scaleX/Y properties are used.
So, when using myPolygon.scaleX = 0.5; scale is set to {0.5, 1}.
When using myPolygon.scaleY = 0.5; scale is actually set to {0.5, 0.5} but applied to the transformation matrix twice.

License

Hi. What is the license for this library?

Allow arbitrary points in Polygon

Polygon.create([a1, b1, a2, b2...]) and another name for perfect polygon types by number of sides would make more sense.

Triangle.create() could be nice too.

Extreme performance difference between JS and C++ export.

I've used differ very naively in my project, with every tilemap tile having it's own box collider, and with every collision check checking all of these tiles. It's bad - and I'll fix it with a quad tree or something - but the JS export of my project has been working fine, not lagging at all. However, when I export for windows (I'm using Kha) the app can't run, and after just seconds will freeze and close. I think this performance difference is due to differ, as when running the windows build through visual studio, the performance tools reported that 81.53% of my builds CPU time was spent on a differ method.

perf plz

Feel free to close this if this is outside's of differs control. I totally get that this sort of performance should be expected with what I am doing. I'm just almost curious about why JS does work well, when I expected C++ performance to be higher.

Compile Error: Custom property accessor is no longer supported

Haxe version: 4.0.5

/Users/dkuffner/games/haxe/celest-hl/.haxelib/differ/1,3,0/differ/shapes/Circle.hx:12: characters 24-34 : radius: Custom property accessor is no longer supported, please use `get`
/Users/dkuffner/games/haxe/celest-hl/.haxelib/differ/1,3,0/differ/shapes/Circle.hx:14: characters 35-56 : transformedRadius: Custom property accessor is no longer supported, please use `get`

Ray v. Circle issue

When a circle shape is positioned at the start of a non-infinite ray, there is no collision detected by testRayVsCircle function. I believe this is non-intentional?

Issues with colliders being side-by-side

Here's an example of the Luxe platformer having its gravity reverted (gravity.set_xyz(0, -800, 0); in Simulation.hx).

The rectangles of the two colliders have exactly the same y-coordinates but appears to block the players movement along the x-axis.
This might be caused by the gravity being applied causing the calculations of the player to be performed in this position -- where he actually would be blocked by the other collider.

Any fix or workaround?

Raycaster hitting shapes in opposite direction

I'm using a raycast with infinite turned off, but the raycast is hitting shapes behind me.

For example, I have a square in the middle of the room. If I'm on the right hand side of the square and face left, I hit the outside of the square the the raycast works. If I face right, the raycast now comes in from (what seems like) infinite distance away from the left and hits the square from the left side.

Facing towards the square:
https://dl.dropboxusercontent.com/u/20830426/differ_facingtoward.png
Facing away from the square:
https://dl.dropboxusercontent.com/u/20830426/differ_facingaway.png

It seems like you can replicate this in the github demo by moving the mouse past the raycaster on the left hand side:
https://dl.dropboxusercontent.com/u/20830426/differ_demobug.png

Is this a bug or a settings issue?

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.