Skip to content

Commit

Permalink
added support for compound bodies in MouseConstraint
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Feb 8, 2015
1 parent 87f9065 commit d6829bf
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/constraint/MouseConstraint.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,21 @@ var MouseConstraint = {};
for (var i = 0; i < bodies.length; i++) {
body = bodies[i];
if (Bounds.contains(body.bounds, mouse.position)
&& Vertices.contains(body.vertices, mouse.position)
&& Detector.canCollide(body.collisionFilter, mouseConstraint.collisionFilter)) {

constraint.pointA = mouse.position;
constraint.bodyB = mouseConstraint.body = body;
constraint.pointB = { x: mouse.position.x - body.position.x, y: mouse.position.y - body.position.y };
constraint.angleB = body.angle;

Sleeping.set(body, false);
Events.trigger(mouseConstraint, 'startdrag', { mouse: mouse, body: body });
for (var j = body.parts.length > 1 ? 1 : 0; j < body.parts.length; j++) {
var part = body.parts[j];
if (Vertices.contains(part.vertices, mouse.position)) {
constraint.pointA = mouse.position;
constraint.bodyB = mouseConstraint.body = body;
constraint.pointB = { x: mouse.position.x - body.position.x, y: mouse.position.y - body.position.y };
constraint.angleB = body.angle;

Sleeping.set(body, false);
Events.trigger(mouseConstraint, 'startdrag', { mouse: mouse, body: body });

break;
}
}
}
}
} else {
Expand Down

0 comments on commit d6829bf

Please sign in to comment.