如何在lhs和rhs之间转换opengl投影矩阵?

时间:2012-06-13 13:05:18

标签: opengl-es opengl-es-2.0 projection-matrix

我有一个lhs着色器,但碰巧有一个rhs投影矩阵,如何在它们之间进行转换?

1 个答案:

答案 0 :(得分:2)

来自Qt的代码:

/*!
    Flips between right-handed and left-handed coordinate systems
    by multiplying the y and z co-ordinates by -1.  This is normally
    used to create a left-handed orthographic view without scaling
    the viewport as ortho() does.

    \sa ortho()
*/
void QMatrix4x4::flipCoordinates()
{
    if (flagBits == Scale || flagBits == (Scale | Translation)) {
        m[1][1] = -m[1][1];
        m[2][2] = -m[2][2];
    } else if (flagBits == Translation) {
        m[1][1] = -m[1][1];
        m[2][2] = -m[2][2];
        flagBits |= Scale;
    } else if (flagBits == Identity) {
        m[1][1] = -1.0f;
        m[2][2] = -1.0f;
        flagBits = Scale;
    } else {
        m[1][0] = -m[1][0];
        m[1][1] = -m[1][1];
        m[1][2] = -m[1][2];
        m[1][3] = -m[1][3];
        m[2][0] = -m[2][0];
        m[2][1] = -m[2][1];
        m[2][2] = -m[2][2];
        m[2][3] = -m[2][3];
        flagBits = General;
    }
}