旋转矩阵缩小对象?

问题描述 投票:1回答:2

我的数学错了吗?假定用户能够输入以度为单位的角度,并分别旋转矩阵。相反,它会收缩对象并将其翻转...调用

glmxRotate(&modelview, 0.0f, 0.0f, 1.0f, 90.0f);

((以modelview为单位矩阵)产生:

常规:http://i.imgur.com/eX7Td.png

旋转:http://i.imgur.com/YnMEn.png

这里是glmxRotate:

glmxvoid glmxRotate(glmxMatrix* matrix, glmxfloat x, glmxfloat y, glmxfloat z,
    glmxfloat angle)
{
    if(matrix -> mx_size != 4){GLMX_ERROR = GLMX_NOT_4X4; return;}

    //convert to rads
    angle *= 180.0f / 3.14159;

    const glmxfloat len = sqrtf((x * x) + (y * y) + (z * z)),
                    c = cosf(angle),
                    c1 = 1.0f - c,
                    s = sinf(angle);

    //normalize vector
    x /= len;
    y /= len;
    z /= len;

    glmxfloat rot_mx[] = {x * x * c1 + c,
                          x * y * c1 + z * s,
                          x * z * c1 - y * s,
                          0.0f,

                          x * y * c1 - z * s,
                          y * y * c1 + c,
                          y * z * c1 + x * s,
                          0.0f,

                          x * z * c1 + y * s,
                          y * z * c1 - x * s,
                          z * z * c1 + c,
                          0.0f,

                          0.0f,
                          0.0f,
                          0.0f,
                          1.0f,};

    _glmxMultiMatrixArray(matrix, rot_mx, 4);
}

此外,如果在最后四列中用翻译定义了翻译矩阵,那么由于结果将始终产生0,将如何翻译身份矩阵?

c opengl trigonometry model-view rotational-matrices
2个回答
1
投票

您的矩阵对我来说似乎是正确的,尽管您知道您与弧度乘法的角度实际上是弧度与角度相乘吗?

//convert to rads
angle *= 180.0f / 3.14159;

应该为Pi/180.f


0
投票

由于浮点数存储在正弦中的空间非常有限,并且cos未被精确计算,这意味着每次旋转对象都会发生小错误,这意味着随着时间的推移,对象会越来越小。如果不希望发生这种情况,请使用四元数进行旋转。https://www.npmjs.com/package/quaternion

© www.soinside.com 2019 - 2024. All rights reserved.