我有一个基于瓷砖的项目游戏,得到了一个不错的伪3D效果使用多个瓷砖层,但我希望能够旋转相机(本质上,旋转的精灵)。
但是,简单地旋转精灵并不等于旋转世界,对吗?
通过这个,我必须:
x = (x - y) * (tile_width/2);
y = (x + y) * (tile_width/2);但是,看到了吗?只适用于45度旋转的瓷砖!如何修改这些公式中使用的角度(或者更好、更合适)?


发布于 2016-01-16 07:12:19
旋转精灵只是旋转世界/摄像机的一部分。
为了旋转世界/照相机,每个瓷砖需要沿着一个弧线移动,并在同一时间旋转。要做到这一点,您需要使用极坐标。计算从旋转中心到每个瓷砖中心的距离和角度.然后将所需的旋转角度添加到每个瓷砖的极角上.通过转换回笛卡尔坐标来计算瓷砖中心的新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)逆时针旋转瓷砖,同时逆时针移动瓷砖。

底线:几乎任何错误都会导致图像的空白。
https://stackoverflow.com/questions/34824468
复制相似问题