(这都是正交模式,原点在左上角,x 向右为正,y 沿 y 轴为正)
我在世界空间中有一个矩形,它可以有一个旋转 m_rotation(以度为单位)。
我可以很好地处理矩形,它可以旋转、缩放,以及你想要它做的一切。
我真正感到困惑的部分是从其局部坐标计算矩形世界坐标。
我一直在尝试使用以下公式:
x' = x*cos(t) - y*sin(t)
y' = x*sin(t) + y*cos(t)
where (x, y) are the original points,
(x', y') are the rotated coordinates,
and t is the angle measured in radians
from the x-axis. The rotation is
counter-clockwise as written.
-credits duffymo
我尝试实现这样的公式:
//GLfloat Ax = getLocalVertices()[BOTTOM_LEFT].x * cosf(DEG_TO_RAD( m_orientation )) - getLocalVertices()[BOTTOM_LEFT].y * sinf(DEG_TO_RAD( m_orientation ));
//GLfloat Ay = getLocalVertices()[BOTTOM_LEFT].x * sinf(DEG_TO_RAD( m_orientation )) + getLocalVertices()[BOTTOM_LEFT].y * cosf(DEG_TO_RAD( m_orientation ));
//Vector3D BL = Vector3D(Ax,Ay,0);
我为平移点创建一个向量,将其存储在矩形 world_vertice 成员变量中。没关系。但是,在我的主绘制循环中,我从 (0,0,0) 到向量 BL 画了一条线,看起来这条线从矩形上的点开始呈圆形(矩形左下角)围绕世界坐标的原点。
基本上,随着 m_orientation 变大,它会在 (0,0,0) 世界坐标系原点周围画一个大圆圈。编辑:当 m_orientation = 360 时,它被设置回 0。
我觉得我做错了这部分:
t 是以弧度为单位从 x 轴测量的角度。
可能我不应该在这个公式中使用 m_orientation (矩形旋转角度)?
谢谢!
编辑:我这样做的原因是为了碰撞检测。我需要知道矩形的坐标(即将成为刚体)在世界坐标位置中的位置以进行碰撞检测。