[英]How do I rotate an isometric camera around the screen center?
旋轉精靈只是旋轉世界/相機的一部分。
要旋轉世界/相機,每個瓷磚需要沿弧線移動,並同時旋轉。 要做到這一點,你需要使用極坐標。 計算從旋轉中心到每個瓷磚中心的距離和角度。 然后將所需的旋轉角度添加到每個圖塊的極角。 通過轉換回笛卡爾坐標來計算切片中心的新x
和y
值。
這是代碼的樣子,假設每個圖塊由一個結構體表示,並且該結構具有圖塊中心的原始x
和y
坐標(即當世界未旋轉時圖塊中心的坐標) )。
// compute the distance from the center of the tile to the center of rotation
double dx = tile[t].x - centerOfRotation.x;
double dy = tile[t].y - centerOfRotation.y;
// compute the new location of tile in polar coordinates relative to the center of rotation
double r = sqrt(dx*dx + dy*dy);
double angle = atan2(dy, dx) + angleOfRotation;
// compute the display location for the tile
x = centerOfRotation.x + r * cos(angle);
y = centerOfRotation.y + r * sin(angle);
// note that the tile itself needs to rotated as well, using angleOfRotation
// also, all angles are in radians
嘗試旋轉圖形時,有助於簡化操作。 使用少量瓷磚,使瓷磚具有強烈邊框的不同顏色,以及用於顯示方向的識別標記。 這是一個示例,在初始方向上有9個瓷磚,逆時針旋轉30度。
以下是可能出錯的一些示例:
1)移動瓷磚而不旋轉瓷磚
2)旋轉瓷磚而不移動瓷磚
3)順時針旋轉瓷磚,同時逆時針移動瓷磚
底線:幾乎任何錯誤都會導致圖像有間隙。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.