0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-30 10:20:52 -05:00

added rotation point parameter to Body.rotate, closes #410

This commit is contained in:
liabru 2017-05-04 00:31:56 +01:00
parent ab0283b5b3
commit 749ed5066e

View file

@ -492,9 +492,24 @@ var Axes = require('../geometry/Axes');
* @method rotate * @method rotate
* @param {body} body * @param {body} body
* @param {number} rotation * @param {number} rotation
* @param {vector} [point]
*/ */
Body.rotate = function(body, rotation) { Body.rotate = function(body, rotation, point) {
Body.setAngle(body, body.angle + rotation); if (!point) {
Body.setAngle(body, body.angle + rotation);
} else {
var cos = Math.cos(rotation),
sin = Math.sin(rotation),
dx = body.position.x - point.x,
dy = body.position.y - point.y;
Body.setPosition(body, {
x: point.x + (dx * cos - dy * sin),
y: point.y + (dx * sin + dy * cos)
});
Body.setAngle(body, body.angle + rotation);
}
}; };
/** /**