0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-03-14 00:38:41 -04:00
This commit is contained in:
Gustavo Canedo 2024-11-27 16:05:09 +00:00 committed by GitHub
commit c582be48bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -836,6 +836,28 @@ var Axes = require('../geometry/Axes');
body.torque += offset.x * force.y - offset.y * force.x;
};
/**
* Applies a relative force to a body from a given relative position, including resulting torque.
* @method applyForce
* @param {body} body
* @param {vector} relativePosition
* @param {vector} relativeForce
*/
Body.applyRelativeForce = function(body, relativePosition, relativeForce) {
var sin = Math.sin(body.angle);
var cos = Math.cos(body.angle);
Body.applyForce(
body, {
x: body.position.x + cos * relativePosition.x - sin * relativePosition.y,
y: body.position.y + sin * relativePosition.x + cos * relativePosition.y,
}, {
x: cos * relativeForce.x - sin * relativeForce.y,
y: sin * relativeForce.x + cos * relativeForce.y,
}
);
};
/**
* Returns the sums of the properties of all compound parts of the parent body.
* @method _totalProperties