mirror of
https://github.com/liabru/matter-js.git
synced 2024-12-26 13:49:01 -05:00
added compound support to Query.ray
This commit is contained in:
parent
eb29367459
commit
10e5d0fcd2
2 changed files with 16 additions and 6 deletions
|
@ -1286,7 +1286,10 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
World.add(_world, stack);
|
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, concave]);
|
||||||
|
|
||||||
_sceneEvents.push(
|
_sceneEvents.push(
|
||||||
Events.on(_engine, 'afterRender', function() {
|
Events.on(_engine, 'afterRender', function() {
|
||||||
|
|
|
@ -31,10 +31,17 @@ var Query = {};
|
||||||
var bodyA = bodies[i];
|
var bodyA = bodies[i];
|
||||||
|
|
||||||
if (Bounds.overlaps(bodyA.bounds, ray.bounds)) {
|
if (Bounds.overlaps(bodyA.bounds, ray.bounds)) {
|
||||||
var collision = SAT.collides(bodyA, ray);
|
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) {
|
if (collision.collided) {
|
||||||
collision.body = collision.bodyA = collision.bodyB = bodyA;
|
collision.body = collision.bodyA = collision.bodyB = bodyA;
|
||||||
collisions.push(collision);
|
collisions.push(collision);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue