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.



8 comments:

papillon68 said...

hank you very much for the gluPerspective code, I was really looking into it !

Tom said...
This comment has been removed by the author.
Tom said...

I don't think the calls to glMatrixMode and glLoadIdentity are correct. The ordinary gluPerspective multiplies its result with to the currently selected matrix stack; while it's generally incorrect to load a perspective matrix to the modelview matrix stack, there are some useful effects of pointing it towards the texture matrix stack.

Manu said...

Tom is right, this implementation is incorrect and can lead to unexpected results

Edwin said...

scrub m65 kamagra attorney lawyer body scrub field jacket lovegra marijuana attorney injury lawyer

JeansPilot said...

JeansPilot offers the chance to buy a large variety of men’s and women’s jeans clothing from the world famous Italian Brands.
Online jeans clothing store looks for original fashion clothing sales and clearances of worldwide known designers. We participate in fashion auctions to get the lowest possible price for Top quality Clothes, Shoes and Accessories.
Buy Jeans

aeroson said...

i think this is a bit better

gluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
{
GLfloat range=zNear*tan(fovy*0.008841941282883074);
aspect*=range;
glFrustum(-aspect,aspect,-range,range,zNear,zFar);
}

aeroson =^_^=

h4ns said...

What youre saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I also love the images you put in here. They fit so well with what youre trying to say. Im sure youll reach so many people with what youve got to say.

Arsenal vs Huddersfield Town live streaming
Arsenal vs Huddersfield Town live streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Notts County vs Manchester City Live Streaming
Notts County vs Manchester City Live Streaming
Bologna vs AS Roma Live Streaming
Bologna vs AS Roma Live Streaming
Juventus vs Udinese Live Streaming
Juventus vs Udinese Live Streaming
Napoli vs Sampdoria Live Streaming
Napoli vs Sampdoria Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
AS Monaco vs Marseille Live Streaming
AS Monaco vs Marseille Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Technology News | News Today | Live Streaming TV Channels