2D 旋转打开
2d rotation opengl
这是我正在使用的代码。
#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: %fn", 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 我知道我只是以我的价值观为中心,而不是把它们放回原来的地方。不需要把它们放回去,因为我只需要知道我现在得到的价值。
你的括号位置对我来说看起来不对。我期望:
px[i] = (vec[i].x + centerX) * cosRotation - (vec[i].y + centerY) * sinRotation;
py[i] = (vec[i].x + centerX) * sinRotation + (vec[i].y + centerY) * cosRotation;
你的括号是错误的。它应该是
px[i] = ((vec[i].x + centerX) * cosRotation) - ((vec[i].y + centerY) * sinRotation);
py[i] = ((vec[i].x + centerX) * sinRotation) + ((vec[i].y + centerY) * cosRotation);
相反
相关文章:
- 四边形的 2D 旋转
- 简化代码以避免在顺时针旋转2D矩阵时出现TLE
- 2D旋转问题C Directx
- 为什么我的 2D 阵列不旋转?
- 优化2D旋转
- 顺时针旋转2D阵列
- 无法使用 opengl 正确旋转 2D 对象
- 在C 中旋转矩阵(2D阵列)45度
- 2D 旋转打开
- 将2D转换的1D阵列顺时针旋转90度
- OpenGL - 2D敌人不旋转面对玩家
- C++ 2D 如何在宇宙飞船上"stick"排气精灵并允许其相应地旋转?
- C++ 如何保持炮塔与油箱在同一轴上旋转?(2D坦克指挥官游戏)
- 使用旋转矩阵旋转纹理2d
- 旋转 2D 正方形
- 旋转长方体2d中的关节
- 是否有一个c++源/lib来解决2D Bin Packing使用矩形Bin(而不是正方形)和旋转
- 如何围绕任意点旋转一组2D形状
- 我们如何在openGL中相对于一个点(而不是原点)旋转2d中的图形
- 使用OpenGL固定功能旋转和平移2D图像