0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-25 13:39:06 -05:00

added compound support to Query.ray

This commit is contained in:
liabru 2015-02-01 23:59:14 +00:00
parent eb29367459
commit 10e5d0fcd2
2 changed files with 16 additions and 6 deletions

View file

@ -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() {

View file

@ -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;
}
}
}
}
}