gpt4 book ai didi

c++ - 二维旋转opengl

转载 作者:行者123 更新时间:2023-11-28 00:53:33 25 4
gpt4 key购买 nike

这是我正在使用的代码。

#define ANGLETORADIANS 0.017453292519943295769236907684886f // PI / 180
#define RADIANSTOANGLE 57.295779513082320876798154814105f // 180 / PI

rotation = rotation *ANGLETORADIANS;

cosRotation = cos(rotation);
sinRotation = sin(rotation);

for(int i = 0; i < 3; i++)
{
px[i] = (vec[i].x + centerX) * (cosRotation - (vec[i].y + centerY)) * sinRotation;
py[i] = (vec[i].x + centerX) * (sinRotation + (vec[i].y + centerY)) * cosRotation;
printf("num: %i, px: %f, py: %f\n", i, px[i], py[i]);
}

到目前为止它接缝我的 Y 值被翻转.. 假设我输入 X = 1 和 Y = 1 的值,旋转 45 你应该看到大约 x = 0 和 y = 1.25 ish 但我得到 x = 0 y = -1.25。

我的 90 度旋转也总是返回 x = 0 和 y = 0。

p.s 我知道我只是在集中我的值(value)观,而不是把它们放回原处。不需要将它们放回去,因为我只需要知道我现在获得的值(value)。

最佳答案

我觉得你的括号位置不对。我希望:

px[i] = (vec[i].x + centerX) * cosRotation - (vec[i].y + centerY) * sinRotation;
py[i] = (vec[i].x + centerX) * sinRotation + (vec[i].y + centerY) * cosRotation;

关于c++ - 二维旋转opengl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12707399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com