PDA

View Full Version : 3D clipping and gluPerspective()



Perspective
02-20-2003, 04:31 PM
i am a little confused about 3D clipping using gluPerspective(). from what ive read, i thought that anything out side of the viewable 'perspective' should not be rendered (ie. no projection calculations done). but i did a little test and i dont think this is the case...

i added 50 high poly models to an area of the scene. when looking at them (they are inside viewable frustum) the program was slow and choppy as excpected. When i turned the camera away from them (no longer in the viewable perspective/frustum) the program was still slow and choppy which implies rendering calculations are still being done for these non-viewable objects.

my question is: do i have to manually calculate what is viewable and only draw/render that? or can openGL (gluPerspective) do this for me. if it can do the 3D clipping for me, what am i doing wrong??

this is how i set up my perspective...

gluPerspective(55.0f,(GLfloat)width/(GLfloat)height,0.1f,50.0f);

HalcyonBlaze
02-20-2003, 05:48 PM
Hey Perspective,

OpenGL clips the polygons outside the view frustum after all the vertex operations in the pipeline. If you want to lower the work done at the vertex operation stage, then you need to do your own clipping at the software level (before data goes into the videocard).

- Halcyon

Perspective
02-21-2003, 10:23 AM
yeah, thats what i figured i would have to do. im thinking i will keep 5 plane equations (representing the view frustrum) and check world coordinates to see if objects are viewable or not. does this sound like a good aproach or are there better ways?

miko
02-22-2003, 02:40 AM
you actually have to keep 6 equations (near, far, left, right, bottom, top). a very nice approach how to compute eqautions from current matrices is here http://www.markmorley.com/opengl/frustumculling.html

miko
02-22-2003, 02:42 AM
i was just promoted to frequent contributor!!!! (i know a little less than glVertex but i'm a frequent contributor http://www.opengl.org/discussion_boards/ubb/smile.gif) maybe i should stop kidding...

Perspective
02-22-2003, 10:09 AM
yeah, thats right. but if i calculate the 5 plane equations based on the camera position then the 'front' plane (closest to camera) is just orthogonal to the camera direction, so world coordinates of objects behind the camera's point are behind the front plane. this would save storing the front clipping plane and the camera's position as 2 different things. i only need the camera position/direction and the left, right, top, bottom, and back planes.

thanx for the link, i will check that out.

chxfryer
02-22-2003, 01:14 PM
www.gametutorials.com (http://www.gametutorials.com) has another tut on frustum culling.