簡體   English   中英

如何圍繞屏幕中心旋轉等距相機?

[英]How do I rotate an isometric camera around the screen center?

我有一個基於平鋪的項目游戲,使用多個平鋪圖層獲得了很好的偽3D效果,但我希望能夠旋轉相機(基本上是旋轉精靈)。

但是,簡單地旋轉精靈並不等於旋轉世界,對吧?

通過這個,我得到:

x = (x - y) * (tile_width/2);
y = (x + y) * (tile_width/2);

但是,看到了嗎? 這只適用於45度旋轉瓷磚! 如何修改這些公式中使用的角度(或者更好,更合適的角度)?

川 等距

旋轉精靈只是旋轉世界/相機的一部分。

要旋轉世界/相機,每個瓷磚需要沿弧線移動,並同時旋轉。 要做到這一點,你需要使用極坐標。 計算從旋轉中心到每個瓷磚中心的距離和角度。 然后將所需的旋轉角度添加到每個圖塊的極角。 通過轉換回笛卡爾坐標來計算切片中心的新xy值。

這是代碼的樣子,假設每個圖塊由一個結構體表示,並且該結構具有圖塊中心的原始xy坐標(即當世界未旋轉時圖塊中心的坐標) )。

    // 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM