【发布时间】:2023-03-22 23:05:02
【问题描述】:
我需要围绕自身旋转一个三角形(称为船)。
这是我到目前为止得到的,但它不起作用。它越来越小,直到消失。
void RotatePoint(Point *P, float angle)
{
float theta = angle * (180/3.1415);
P->x = (P->x * cos(theta)) - (P->y * sin(theta));
P->y = (P->y * cos(theta)) + (P->x * sin(theta));
}
void RotateShip(Ship *ship)
{
Rotate(&ship->A, rotateAngle);
Rotate(&ship->B, rotateAngle);
Rotate(&ship->C, rotateAngle);
}
点P是我要旋转的点,点C是三角形的中心。我想如果我旋转所有三个顶点,三角形就会旋转。
就我而言,我是这样初始化的:
void initShip(Ship *ship)
{
ship->center.x = (SCREEN_W)/2.0;
ship->center.y = (SCREEN_H)/2.0;
ship->A.x = 0;
ship->A.y = -5;
ship->B.x = 15;
ship->B.y = 25;
ship->C.x = -15;
ship->C.y = 25;
ship->color = al_map_rgb(255, 255, 255);
}
船舶 A、B 和 C 是到三角形中心的距离。我绘制它,将 A、B 和 C 添加到中心顶点。
A=-0.699857,-19.963261
A=-0.000857,-19.951065
A=-0.699001,-19.914387
A=-0.001712,-19.902250
A=-0.698147,-19.865631
A=-0.002565,-19.853554
我按一键后一键,使其顺时针和逆时针旋转。注意 A 是如何缩小的。 我不知道我在做什么。当它到达顶部时,我应该回到 20.00。这样我的三角形正在缩小。 我用的是cos(0.035)和sin(0.035),意思是2度。
【问题讨论】:
-
为什么不起作用?你做了什么来调试它?
-
它就消失了。绘图功能是这样的:
void drawShip(Ship *ship) { al_draw_triangle(ship->center.x + ship->A.x, ship->center.y + ship->A.y, ship->center.x + ship->B.x, ship->center.y + ship->B.y, ship->center.x + ship->C.x, ship->center.y + ship->C.y, ship->color, 1); }当我按键旋转它时,它就消失了。我的数学一定有问题,但我不知道是什么问题。 -
请做一个minimal reproducible example,不需要整个绘图和其他图形的东西,只需要一个打印坐标几次的main();展示它们如何变小,尤其是速度如何。
-
除其他外,我还想查看您正在使用的坐标类型。诠释?漂浮?双倍?
-
坐标相对于中心是否变小了?还是这艘船也向 (0,0) 移动?