OpenGL4.x不支持gluPerspective函数。故备份之

template <typename type>
inline mat4<type> mat4<type>::perspectiveProjection(type fovy, type aspect, type zNear, type zFar)
{
    type f = (type) 1 / tan(radians(fovy) / 2);
    return mat4<type>(f / aspect, 0, 0,                         0,
                      0,        f, 0,                         0,
                      0,        0, (zFar + zNear) / (zNear - zFar), (2*zFar*zNear) / (zNear - zFar),
                      0,        0, -1,                        0);
}

template <typename type>
inline mat4<type> mat4<type>::orthoProjection(type xRight, type xLeft, type yTop, type yBottom, type zNear, type zFar)
{
    type tx, ty, tz;
    tx = - (xRight + xLeft) / (xRight - xLeft);
    ty = - (yTop + yBottom) / (yTop - yBottom);
    tz = - (zFar + zNear) / (zFar - zNear);
    return mat4<type>(2 / (xRight - xLeft), 0,                  0,                tx,
                       0,                  2 / (yTop - yBottom), 0,                ty,
                       0,                  0,                 -2 / (zFar - zNear), tz,
                       0,                  0,                  0,                1);
}

 

posted @ 2014-03-06 20:52  20118281131  阅读(254)  评论(0编辑  收藏  举报