【发布时间】:2020-11-30 06:48:20
【问题描述】:
我在 C# 中使用现代 OpenGL,我正在尝试旋转一个四边形,使其在 X 轴上成 90 度。问题是,旋转的产物没有意义。它没有侧身,而是仅在中途左右翻转。此外,仅将度数更改 1(90 到 91)会完全改变结果。
我的欧拉顺序是:Y、X、Z。
旋转矩阵
internal Matrix4 rotx;
internal Matrix4 roty;
internal Matrix4 rotz;
internal float sin;
internal float cos;
public Matrix4 CreateRotationMatrix(float anglex, float angley, float anglez)
{
//X
cos = (float)Math.Cos(anglex);
sin = (float)Math.Sin(anglex);
rotx = new Matrix4(new Vector4(1.0f, 0.0f, 0.0f, 0.0f), new Vector4(0.0f, cos, sin, 0.0f), new Vector4(0.0f, -sin, cos, 0.0f), new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
//Y
cos = (float)Math.Cos(angley);
sin = (float)Math.Sin(angley);
roty = new Matrix4(new Vector4(cos, 0.0f, -sin, 0.0f), new Vector4(0.0f, 1.0f, 0.0f, 0.0f), new Vector4(sin, 0.0f, cos, 0.0f), new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
//Z
cos = (float)Math.Cos(anglez);
sin = (float)Math.Sin(anglez);
roty = new Matrix4(new Vector4(cos, sin, 0.0f, 0.0f), new Vector4(-sin, cos, 0.0f, 0.0f), new Vector4(0.0f, 0.0f, 1.0f, 0.0f), new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
return (roty * rotx) * rotz;
}
然后我将其放入模型矩阵中,顺序为:缩放、平移、旋转。
我做错了什么?
X轴旋转90度的乘积
Y轴旋转90度的乘积
Z轴旋转90度的积
【问题讨论】:
-
您是否忘记将度数转换为弧度?
-
是的,解决了!如果您对此做出回答,我将使其成为公认的答案。谢谢!浪费了 2 个小时。
标签: c#