Skip to content

setanarut/coll

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc

coll - 2d collision library for Go

Features

  • Collisions only - no gravity, rigid body handling, or complex solvers
  • Is data-oriented and functional

Conventions

"Sweep" tests indicate at least 1 of the objects is moving. The number indicates how many objects are moving. e.g., box-box-sweep2 means we are comparing 2 aabbs, both of which are moving. "Overlap" tests don't take movement into account, and this is a static check to see if the 2 entities overlap. plural forms imply a collection. e.g., BoxSegmentsSweep1Indexed() checks one box segment against a set of line segments. If there is more than one collision, the closest collision is set in the hitInfo argument.

Available collision checks

Box-Box overlap

Box-Box-overlap

BoxBoxOverlap(boxA, boxB *AABB, hitInfo *HitInfo) bool

Box-Box contain

// BoxBoxContain returns true if a fully contains b. BoxBoxContain(a, b *AABB) bool

Box-Box sweep 1

Box-Box sweep 1

BoxBoxSweep1(staticBoxA, boxB *AABB, boxBVel v.Vec, hitInfo *HitInfo) bool 

Box-Box sweep 2

Box-Box sweep 2

BoxBoxSweep2(boxA, boxB *AABB, boxAVel, boxBVel v.Vec, hitInfo *HitInfo) bool

Circle-Circle sweep 2

CircleCircleSweep2(c1, c2 *Circle, c1Vel, c2Vel v.Vec) bool

Box-OrientedBox overlap

abb-obb-overlap

BoxOrientedBoxOverlap(a *AABB, b *OBB) bool

Box-OrientedBox sweep 2

BoxOrientedBoxSweep2(a *AABB, b *OBB, va v.Vec, vb v.Vec) bool

Box-Segment sweep 1

Box-Segment sweep 1

BoxSegmentSweep1(line *Segment, box *AABB, delta v.Vec, hitInfo *HitInfo) bool

Box-Segments sweep 1 indexed

Box-Segments sweep 1

BoxSegmentsSweep1Indexed(lines []*Segment, aabb *AABB, delta v.Vec, hitInfo *HitInfo) (index int)

Box-Point overlap

Box-Point overlap

BoxPointOverlap(box *AABB, point v.Vec, hitInfo *HitInfo) bool

Box-Segment overlap

Box-Segment overlap

BoxSegmentOverlap(box *AABB, start, delta, padding v.Vec, hitInfo *HitInfo) bool

Line-Circle overlap

alt text

LineCircleOverlap(raySeg *Segment, circ *Circle, overlapSeg *Segment) bool

Segment-Circle overlap

alt text

SegmentCircleOverlap(seg *Segment, c *Circle) []v.Vec

Box-Circle sweep 2

BoxCircleSweep2(box *AABB, circle *Circle, boxVel, circleVel v.Vec) bool

Box-Tilemap sweep

(c *TileCollider) Collide(box AABB, delta v.Vec, onCollide TileCollisionCallback) v.Vec

Ray-Tilemap DDA

RayTilemapDDA(pos, dir v.Vec, length float64, tm [][]uint8, cellSize float64, h *HitInfo) (bool, image.Point) 

Examples (Ebitengine)

  1. Clone this repository
  2. In the terminal, change to the examples directory cd examples
  3. Run a folder with go run ./foldername. Example: go run ./box_box_sweep1

Credits

Most of these collision checks were adapted from existing open source repos: