From 10e5d0fcd2e7b7fa248075e004feb5811e679481 Mon Sep 17 00:00:00 2001 From: liabru Date: Sun, 1 Feb 2015 23:59:14 +0000 Subject: [PATCH] added compound support to Query.ray --- demo/js/Demo.js | 5 ++++- src/collision/Query.js | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/demo/js/Demo.js b/demo/js/Demo.js index 7702cda..5ff40fe 100644 --- a/demo/js/Demo.js +++ b/demo/js/Demo.js @@ -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() { diff --git a/src/collision/Query.js b/src/collision/Query.js index 097f700..2bd25cb 100644 --- a/src/collision/Query.js +++ b/src/collision/Query.js @@ -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; + } + } } } }