0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-01-14 16:28:42 -05:00

add relativeForce

This commit is contained in:
Gustavo Canedo 2021-11-01 12:48:14 -03:00
parent e909b0466c
commit d3813fc611

View file

@ -694,6 +694,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