Skip to content

Commit

Permalink
added compound support to Query.ray
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Feb 1, 2015
1 parent eb29367 commit 10e5d0f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 4 additions & 1 deletion demo/js/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1285,8 +1285,11 @@
return Bodies.polygon(x, y, sides, Common.random(20, 50));
}
});

var vertices = Matter.Vertices.fromPath('164 171,232 233,213 302,273 241,342 305,316 231,364 170,309 188,281 117,240 182'),
concave = Bodies.fromVertices(200, 200, vertices);

World.add(_world, stack);
World.add(_world, [stack, concave]);

_sceneEvents.push(
Events.on(_engine, 'afterRender', function() {
Expand Down
17 changes: 12 additions & 5 deletions src/collision/Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,19 @@ var Query = {};

for (var i = 0; i < bodies.length; i++) {
var bodyA = bodies[i];

if (Bounds.overlaps(bodyA.bounds, ray.bounds)) {
var collision = SAT.collides(bodyA, ray);
if (collision.collided) {
collision.body = collision.bodyA = collision.bodyB = bodyA;
collisions.push(collision);
for (var j = bodyA.parts.length === 1 ? 0 : 1; j < bodyA.parts.length; j++) {
var part = bodyA.parts[j];

if (Bounds.overlaps(part.bounds, ray.bounds)) {
var collision = SAT.collides(part, ray);
if (collision.collided) {
collision.body = collision.bodyA = collision.bodyB = bodyA;
collisions.push(collision);
break;
}
}
}
}
}
Expand Down

0 comments on commit 10e5d0f

Please sign in to comment.