Replacement for gluPerspective (with glFrustrum)
您如何将gluPerspective函数转换为glFrustum? 我尝试使用此公式,但是没有运气,因为它没有生成与gluPerspective相同的图像。
top = tan(fov*3.14159/360.0) * near
bottom = -topleft = aspect * bottom
right = aspect * top
我似乎无法正确转换视野。 举例来说,假设我的FOV为45,那么"视锥"调用中的"最高"参数是什么?
开始吧-您可以使用以下方法代替
1 2 3 4 5 6 7 8 9 10 11 | void perspectiveGL( GLdouble fovY, GLdouble aspect, GLdouble zNear, GLdouble zFar ) { const GLdouble pi = 3.1415926535897932384626433832795; GLdouble fW, fH; //fH = tan( (fovY / 2) / 180 * pi ) * zNear; fH = tan( fovY / 360 * pi ) * zNear; fW = fH * aspect; glFrustum( -fW, fW, -fH, fH, zNear, zFar ); } |
您可以在nehe页面上找到有关代码的更多说明。