【问题标题】:OpenGL 4 - Euler rotations not making any senseOpenGL 4 - 欧拉旋转没有任何意义
【发布时间】: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#


【解决方案1】:

System.Math 中的三角函数以弧度为单位测量所有角度(对于输入和反“弧”函数返回值的情况)。

如果您以度为单位进行设计,则必须记住在调用库函数之前将角度转换为弧度。

【讨论】:

    猜你喜欢
    • 2013-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多