Skip to content

Commit

Permalink
added rotation point parameter to Body.rotate, closes #410
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed May 3, 2017
1 parent ab0283b commit 749ed50
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/body/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

/**
Expand Down

0 comments on commit 749ed50

Please sign in to comment.