0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-27 09:50: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
* @param {body} body
* @param {number} rotation
* @param {vector} [point]
*/
Body.rotate = function(body, rotation) {
Body.setAngle(body, body.angle + rotation);
Body.rotate = function(body, rotation, point) {
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);
}
};
/**