glFrustum() maths... are they correct?

Moderator
Posts: 697
Joined: 2002.04
Post: #1
As I'm becoming increasingly irritated by the limitations of gluPerspective(), I thought I'd code a quick function to set-up a perspective view...
Code:
void Perspective( const double p_halfWidth,
    const double p_halfHeight,
    const double p_angle,
    const double p_far,
    double *p_near )
{
  const double near = ( p_halfWidth / tan( p_angle * ( 3.141592654 / 180.0 )));
  glFrustum( -p_halfWidth, p_halfWidth,
    p_halfHeight, p_halfHeight,
    near, p_far );
  *p_near = near;
  return;
}
It's missing a lot of useful functionality (ensuring near < far, for a start), but I've quickly tested it, and it seems to return the results I'd expect (for example, for a 45° view, as the apparent dimensions of an object halve every time the distance from the near point doubles.)

But I just wondered whether a more knowledgable coder would take a look, point out any (inevitable?) errors in the maths Huh

Mark Bishop
--
Student and freelance OS X & iOS developer
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
What on earth is wrong with using gluPerspective()?

- Alex Diener
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Having trouble with glFrustum()? KittyMac 2 3,958 May 2, 2007 01:32 PM
Last Post: arekkusu
  correct glDepthFunc() parameter? Vertizor 4 4,393 Sep 28, 2004 08:32 AM
Last Post: Vertizor