mirror of
https://github.com/liabru/matter-js.git
synced 2024-12-27 13:59:01 -05:00
added collisionFilter support to MouseConstraint
This commit is contained in:
parent
5060c7626a
commit
cee8d55a32
1 changed files with 17 additions and 2 deletions
|
@ -42,7 +42,12 @@ var MouseConstraint = {};
|
||||||
mouse: mouse,
|
mouse: mouse,
|
||||||
dragBody: null,
|
dragBody: null,
|
||||||
dragPoint: null,
|
dragPoint: null,
|
||||||
constraint: constraint
|
constraint: constraint,
|
||||||
|
collisionFilter: {
|
||||||
|
category: 0x0001,
|
||||||
|
mask: 0xFFFFFFFF,
|
||||||
|
group: 0
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var mouseConstraint = Common.extend(defaults, options);
|
var mouseConstraint = Common.extend(defaults, options);
|
||||||
|
@ -72,7 +77,8 @@ var MouseConstraint = {};
|
||||||
for (var i = 0; i < bodies.length; i++) {
|
for (var i = 0; i < bodies.length; i++) {
|
||||||
var body = bodies[i];
|
var body = bodies[i];
|
||||||
if (Bounds.contains(body.bounds, mouse.position)
|
if (Bounds.contains(body.bounds, mouse.position)
|
||||||
&& Vertices.contains(body.vertices, mouse.position)) {
|
&& Vertices.contains(body.vertices, mouse.position)
|
||||||
|
&& Detector.canCollide(body.collisionFilter, mouseConstraint.collisionFilter)) {
|
||||||
constraint.pointA = mouse.position;
|
constraint.pointA = mouse.position;
|
||||||
constraint.bodyB = body;
|
constraint.bodyB = body;
|
||||||
constraint.pointB = { x: mouse.position.x - body.position.x, y: mouse.position.y - body.position.y };
|
constraint.pointB = { x: mouse.position.x - body.position.x, y: mouse.position.y - body.position.y };
|
||||||
|
@ -196,4 +202,13 @@ var MouseConstraint = {};
|
||||||
* @type constraint
|
* @type constraint
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An `Object` that specifies the collision filter properties.
|
||||||
|
* The collision filter allows the user to define which types of body this mouse constraint can interact with.
|
||||||
|
* See `body.collisionFilter` for more information.
|
||||||
|
*
|
||||||
|
* @property collisionFilter
|
||||||
|
* @type object
|
||||||
|
*/
|
||||||
|
|
||||||
})();
|
})();
|
Loading…
Reference in a new issue