mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-21 17:14:38 -05:00
implemented static compound bodies
This commit is contained in:
parent
6a26696fc7
commit
90adf147e9
1 changed files with 20 additions and 15 deletions
|
@ -213,21 +213,24 @@ var Body = {};
|
||||||
* @param {bool} isStatic
|
* @param {bool} isStatic
|
||||||
*/
|
*/
|
||||||
Body.setStatic = function(body, isStatic) {
|
Body.setStatic = function(body, isStatic) {
|
||||||
body.isStatic = isStatic;
|
for (var i = 0; i < body.parts.length; i++) {
|
||||||
|
var part = body.parts[i];
|
||||||
|
part.isStatic = isStatic;
|
||||||
|
|
||||||
if (isStatic) {
|
if (isStatic) {
|
||||||
body.restitution = 0;
|
part.restitution = 0;
|
||||||
body.friction = 1;
|
part.friction = 1;
|
||||||
body.mass = body.inertia = body.density = Infinity;
|
part.mass = part.inertia = part.density = Infinity;
|
||||||
body.inverseMass = body.inverseInertia = 0;
|
part.inverseMass = part.inverseInertia = 0;
|
||||||
|
|
||||||
body.positionPrev.x = body.position.x;
|
part.positionPrev.x = part.position.x;
|
||||||
body.positionPrev.y = body.position.y;
|
part.positionPrev.y = part.position.y;
|
||||||
body.anglePrev = body.angle;
|
part.anglePrev = part.angle;
|
||||||
body.angularVelocity = 0;
|
part.angularVelocity = 0;
|
||||||
body.speed = 0;
|
part.speed = 0;
|
||||||
body.angularSpeed = 0;
|
part.angularSpeed = 0;
|
||||||
body.motion = 0;
|
part.motion = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -589,10 +592,12 @@ var Body = {};
|
||||||
properties.mass += part.mass;
|
properties.mass += part.mass;
|
||||||
properties.area += part.area;
|
properties.area += part.area;
|
||||||
properties.inertia += part.inertia;
|
properties.inertia += part.inertia;
|
||||||
properties.centre = Vector.add(properties.centre, Vector.mult(part.position, part.mass));
|
properties.centre = Vector.add(properties.centre,
|
||||||
|
Vector.mult(part.position, part.mass !== Infinity ? part.mass : 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
properties.centre = Vector.div(properties.centre, properties.mass);
|
properties.centre = Vector.div(properties.centre,
|
||||||
|
properties.mass !== Infinity ? properties.mass : body.parts.length);
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue