【问题标题】:Rotating the object makes it smaller旋转对象使其变小
【发布时间】:2015-02-01 22:10:16
【问题描述】:

当我使用我创建的函数在opengl es中旋转模型矩阵时,模型矩阵在旋转时使模型变小,我不明白为什么。

这里是旋转函数的代码(仅绕z轴旋转)。

public void rotateZ(float angle){
    float cos = (float) (Math.cos(Math.toRadians(angle)));
    float sin = (float) (Math.sin(Math.toRadians(angle)));
    Matrix4x4 ret = IdentityM();
    ret.setValue(cos, 0, 0);
    ret.setValue(-sin, 0, 1);

    ret.setValue(sin, 1, 0);
    ret.setValue(cos, 1, 1);

    Multiply(ret);
}

这里是乘法函数的代码:

public void Multiply(Matrix4x4 m){
        float[][] m1 = m.toFloatMat();
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 4; j++){
                float value = 0f;
                for(int t = 0; t < 4; t++){
                    value += matrix[i][t] * m1[t][j];
                }
                matrix[i][j] = value;
            }
        }
}

还有setValue函数:

public void setValue(float v, int i, int j){
        matrix[i][j] = v;
}

对象只是越来越小,我不明白为什么>

【问题讨论】:

    标签: java math opengl-es rotation


    【解决方案1】:

    在您的 Multiply 函数中,您在计算产品时覆盖了原始矩阵。做一个临时矩阵来存储结果,然后写回类成员matrix

    【讨论】:

    • Upps 这是我第二次犯这些小错误,这让我发疯了哈哈
    猜你喜欢
    • 1970-01-01
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    • 2015-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多