开发者

Raw OpenGL equivillant of GLUPerspective?

how c开发者_JS百科ould I do the same as GluPerspective without Glu? Thanks

ex: gluPerspective(45.0, (float)w / (float)h, 1.0, 200.0);


void gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar )
{
    GLdouble xmin, xmax, ymin, ymax;

    ymax = zNear * tan( fovy * M_PI / 360.0 );
    ymin = -ymax;
    xmin = ymin * aspect;
    xmax = ymax * aspect;

    glFrustum( xmin, xmax, ymin, ymax, zNear, zFar );
}


It's explained fairly clearly in the gluPerspective documentation. You just build up the appropriate 4x4 transformation matrix and use glMultMatrix to multiply it into the current transform:

void myGluPerspective(double fovy, double aspect, double zNear, double zFar)
{
    double f = 1.0 / tan(fovy * M_PI / 360);  // convert degrees to radians and divide by 2
    double xform[16] =
    {
        f / aspect, 0, 0, 0,
        0,          f, 0, 0,
        0,          0, (zFar + zNear)/(zNear - zFar), -1,
        0,          0, 2*zFar*zNear/(zNear - zFar), 0
    };
    glMultMatrixd(xform);
}

Note that OpenGL stores matrices in column-major order, so the order of array elements above is transposed from what's written in the gluPerspective documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜