我想圍繞原點旋轉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'邊數! –