我想围绕原点旋转4点。当我不旋转点时,它们出现在正确的位置。我做的是这样的:围绕原点旋转点
let origin = this.transform.position;
for (let i in this._pointsOrig) {
let point = this._pointsOrig[i];
this._points[i] = new Vector2(
point.x + origin.x,
point.y + origin.y
);
}
,给了我这样的结果:
注:蓝十字为原点,和绿色的矩形轮廓点
当我尝试旋转矩形时,如下所示:
// degrees is between 0 & 360, so convert to radians
let rotation = this.transform.rotation.degrees * (Math.PI/180);
let cos = Math.cos(rotation);
let sin = Math.sin(rotation);
let origin = this.transform.position;
for (let i in this._pointsOrig) {
let point = this._pointsOrig[i];
this._points[i] = new Vector2(
(cos * (point.x - origin.x)) + (sin * (point.y - origin.y)) + origin.x,
(cos * (point.y - origin.y)) - (sin * (point.x - origin.x)) + origin.y
);
}
我得到这个矩形现在在左下角的结果。
我不知道我需要做这样的点围绕原点旋转。
非常感谢您!这似乎解决了这个问题!它现在以'y'度旋转的方式旋转'x'边数! –