Commit Graph

96 Commits

Author SHA1 Message Date
Matthias Richter
6bb4ba0e24 Rename intersectionsRay. Less redundancy.
* intersectionsRay() -> intersectionsWithRay()
* intersectsRay() uses results from intersectionsWithRay()
  (Exception: PointShape does it the other way around)
2014-01-24 09:47:13 +01:00
vrld
afc917253c Merge pull request #31 from Ragzouken/intersectionsRay
method to return all intersections, not just the first
2014-01-24 00:33:16 -08:00
Matthias Richter
b362ae8c5f Undo bf35186904: use own triangulation again.
Replaced call to love.math.triangulate() with pure Lua implementation of
Kong's algofirthm.
2014-01-24 09:31:06 +01:00
Mark Wonnacott
b101121d51 new method for shapes :intersectionsRay returns an unordered table of ray intersection t values 2014-01-14 10:33:12 +00:00
Matthias Richter
2d169413dd Assert that Polygon is not intersecting itself 2014-01-13 22:49:45 +01:00
Matthias Richter
bf35186904 Use love.math.triangulate instead of own implementation 2014-01-13 22:49:38 +01:00
vrld
cabee18c81 Merge pull request #29 from italomaia/patch-1
Merge #29: remove redundant variable in shapes.lua
2013-12-30 10:50:31 -08:00
Italo Maia
db1b1bdb38 Update shapes.lua
mode in ConvexPolygonShape is already defined in the method signature
2013-12-29 02:09:27 -02:00
Matthias Richter
9d432517b7 Hackish fix for 97ae2d89 and parent.
A clean solution needs more investigation, but this will work for now.
2013-09-04 10:20:19 +02:00
Matthias Richter
97ae2d8928 Fix commit adfe9a9a breaking EPA. 2013-09-03 17:13:27 +02:00
Matthias Richter
adfe9a9a5d Issue #25 (2): Collision detection sometimes hangs.
Sometimes the expanding polytype algorithm takes a long time to
terminate, e.g. in situations like this:

 .-.
: +-:-+
 '-'  |
  |   |
  +---+

The issue here is that the EPA adds vertices very close to each other,
which makes the separation distance change very slowly. If this is the
case, consider the current separation distance as approximately correct
and continue.
2013-08-13 15:34:58 +02:00
Matthias Richter
0dc1e6c719 Issue #25: Division by 0 in CircleShape:support().
support(A,B, 1,0) returns 0,0 when A and B are touching in a vertex of
both A and B AND this vertex is on the right of A's center (in direction
(1,0)), e.g. this situation:

    .---.
 .-.| B |
: A x---'
 '-'

Then: support(A,B, 1,0) = A:support(1,0) - B:support(-1,0) = x - x = 0

Since CircleShape:support(dx,dy) normalizes dx,dy this will result in a
division by 0 error in the subsequent execution of the GJK algorithm.

An early out with result 'not colliding' (in accordance to the other
edge cases) prevents this error.
2013-08-13 15:13:25 +02:00
Matthias Richter
5d100c703f Adhere to new class commons specs. 2013-07-21 12:51:35 +02:00
Matthias Richter
6c7c17ed9e [Fix #23] polygon:getBBox should be polygon:bbox 2013-02-09 22:07:31 +01:00
Matthias Richter
df3e163f9a [Fix] HC:remove(shape) does not remove from groups 2013-02-09 22:04:28 +01:00
Matthias Richter
ec2cc20a6b Better check if cell is empty in Hash:draw() 2013-02-09 22:04:18 +01:00
Matthias Richter
8283c13cfb Add shape:inGroup() 2012-12-15 16:01:21 +01:00
Matthias Richter
788c735ef7 Merge branch 'master' of github.com:vrld/HardonCollider 2012-10-12 18:53:01 +02:00
Matthias Richter
6931ca823a More robust way of handling collisons with concave shapes 2012-10-12 18:52:41 +02:00
Matthias Richter
28e80aeb6f Fix #21: CircleShape:collidesWith() incorrect. 2012-10-12 18:17:34 +02:00
Matthias Richter
8b30af1385 Refactor: Remove shape ids in main module. 2012-10-09 00:50:46 +02:00
Matthias Richter
ed495d3306 Report collisions immediately instead of collecting first.
Collecting collisions and then reporting leads to confusing behavior
when a previous collision callback resolved the collision, e.g.
platforms in jump in runs pushing the player upwards when standing on
two platforms at the same time.
2012-10-08 13:48:30 +02:00
Matthias Richter
68de65f22e Fix #19: outcircle not changed when scaling polygon. 2012-07-30 19:27:55 +02:00
Matthias Richter
1d5196cd70 Fix #18: Invalid check for class-commons. 2012-07-22 12:13:10 +02:00
Matthias Richter
de82e88ddf Add HC:shapesInRange(x1,y1, x2,y2)
Returns a set of shapes that are enclosed in the rectangle
(x1,y1)-(x2,y2).
2012-07-10 16:35:27 +02:00
Matthias Richter
317cce31c6 Add HC:addShape(shape).
Shape must have at least two functions:
- shape:bbox()
  must return an axis aligned bounding box of the shape

- shape:collidesWith(other)
  must return false, ... if the two shapes do not collide
  must return true, sx, sy if the two shapes collide, where sx,sy is the
                           separation vector from from shape to other.

Convex shapes can use the supplied GJK algorithm. In that case the shape
must implement shape:support(dx,dy) which returns the point of the shape
that lies furthest in the direction of dx,dy.
2012-07-10 16:29:59 +02:00
Matthias Richter
ebaabd22b7 Code refactoring 2012-07-10 16:29:34 +02:00
Matthias Richter
f1ad856da9 Remove Spatialhash:getNeighbors() in favor of :inRange() 2012-07-10 16:21:33 +02:00
Matthias Richter
1280b0a2d4 Use hash:rangeIter() in HC:update() 2012-07-10 16:19:27 +02:00
Matthias Richter
9badb23125 Add Spatialhash:inRange() and Spatialhash:rangeIter() 2012-07-10 16:18:53 +02:00
Matthias Richter
5125f35e71 Quick exit on shape:collidesWith(shape) 2012-07-10 16:18:20 +02:00
Matthias Richter
b20fc496eb Add shape:scale(s). 2012-07-05 17:30:13 +02:00
Matthias Richter
694cc05024 Fix polygon merging. Add polygon:scale(s, cx, cy).
Polygon merging failed due to invalid computation of shared edge.

polygon:scale(s,cx,cy) scales polygon by factor s wrt point cx,cy.
2012-07-05 17:27:33 +02:00
Matthias Richter
6b23a5c4c4 More numerically stable point-in-triangle test 2012-06-29 12:21:47 +02:00
Matthias Richter
ea49f9df8b Issue #14: Remove usage of collision ID. 2012-06-10 14:24:30 +02:00
Matthias Richter
e03ea9b0a2 Spatial hash to use number instead of table arguments 2012-05-30 15:27:09 +02:00
Matthias Richter
ce4b8011da Collision detection using GJK/EPA instead of SAT.
The Gilbert–Johnson–Keerthi collision detection algorithm is
significantly faster than collision detection using the separating axis
theorem. GJK can only determine whether two shapes collide, but not the
penetration vector. The expanding polytype algorithm can use information
from GJK to quickly find the required vector.
2012-05-20 16:50:35 +02:00
Matthias Richter
490b8775a2 Remove unpackHelper from polygon.lua 2012-05-19 17:31:19 +02:00
Matthias Richter
c3011ad841 Faster Polygon:unpack() 2012-05-19 12:41:25 +02:00
Matthias Richter
bf95f1e5fc Remove debug print in hash:update() 2012-04-26 20:29:33 +02:00
Matthias Richter
7d09bd30e2 Fix issue #10. Fix spatialhash drawing.
Shapes were not inserted into the spatial hash when not moved. Shapes
set to passive directly after creation would not be in the hash,
resulting in no collision reports.

Spatialhash drawing updated to the new cell indexing method.
2012-04-22 01:10:28 +02:00
Matthias Richter
9ac3d870ff Remove output on console 2012-04-22 01:10:11 +02:00
Matthias Richter
5b12e72aae Switch to light vector module 2012-04-12 16:07:50 +02:00
Matthias Richter
8a182a902f Rename HC:testPoint to HC:shapesAt. More efficient implementation. 2012-03-05 10:37:36 +01:00
Matthias Richter
1fd4dff37e Merge remote-tracking branch 'technocat/master' 2012-03-05 10:32:51 +01:00
Matthias Richter
a7c65630ef Iterators for active and neighboring shapes. 2012-03-05 10:26:14 +01:00
Danny "TechnoCat" Fritz
b58631465c Added HC:testPoint(x, y) -- Test point for collisions with active objects. 2012-03-03 20:06:39 -06:00
Matthias Richter
87f964cb43 Fix shape:intersectsRay(). 2012-02-20 13:13:49 +01:00
Matthias Richter
ac27eee778 Fix HC:remove(shape, ...) to accept varargs. 2012-02-20 10:54:07 +01:00
Matthias Richter
940266e0dc Add shape:bbox(). Simplify hash aware functions 2012-02-11 19:38:09 +01:00