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:
parent
ab0283b5b3
commit
749ed5066e
1 changed files with 17 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue