Replacement for gluPerspectiveFor those interested, I have coded a replacment for gluPerspective so people can do away with dependancies on glu as well as glut!
Very long (& in theory accurate!) version of Pi. Hopefully an optimizing compiler will replace references to this with the value!
Half of the size of the x and y clipping planes.
Calculate the distance from 0 of the y clipping plane. Basically trig to calculate position of clipper at zNear. Note: tan( double ) uses radians but OpenGL works in degrees so we convert degrees to radians by dividing by 360 then multiplying by pi. Formula below corrected by Carsten Jurenz:
Which can be reduced to:
Calculate the distance from 0 of the x clipping plane based on the aspect ratio.
Finally call glFrustum, this is all gluPerspective does anyway! This is why we calculate half the distance between the clipping planes - glFrustum takes an offset from zero for each clipping planes distance. (Saves 2 divides)
![]() Download The Code Here: Perspective GL. Email: James Heggie. |