Thursday, December 11, 2008

gluPerspective

One of the convenience methods removed from OpenGL ES is gluPerspective. At some point, I ran across the code for this method (this isn't my code, but I'm not sure who I got it from. If this came from you, let me know and I will credit you). Anyone who's feeling sad because gluPerspective is not available on the iPhone, rejoice, for here it is:
- (void)gluPerspective:(double)fovy :(double)aspect :(double)zNear :(double)zFar
{
// Start in projection mode.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
double xmin, xmax, ymin, ymax;
ymax = zNear * tan(fovy * M_PI / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustumf(xmin, xmax, ymin, ymax, zNear, zFar);
}

Seems silly to not have this, given how short it is.

No comments:

Post a Comment