Sign in to follow this  
charpi

quick gluLookAt and glFrustum help.

Recommended Posts

Hi. I have extensively searched this site for solutions but found none, so I created this thread. Probably the solutions I found on other threads are correct but I'm relatively new to this thing and implemented the correct solutions wrongly, but anyway...a few questions. C SPECIFICATION void glFrustum( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar ) PARAMETERS left, right Specify the coordinates for the left and right vertical clipping planes. bottom, top Specify the coordinates for the bottom and top horizontal clipping planes. zNear, zFar Specify the distances to the near and far depth clipping planes. Both distances must be positive. What exactly is this "clipping plane"? I tried values between -1.0 to 1.0 (left and right)and -1000 to 1000 and my model renders out the same, does it mean the scope of which the "camera" can see? Because so far how I play with it there doesn't seem to be much difference. Same goes for the next 2 parameters. zNear and zFar, how exactly do you determine these values? Lets say my model has vertices ranging from -2.0 to 2.0, so does that mean that zNear must be less than -2.0 and zFar must be more than 2.0 for my model to fully render? next... C SPECIFICATION void gluLookAt( GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, GLdouble centerY, GLdouble centerZ, GLdouble upX, GLdouble upY, GLdouble upZ ) PARAMETERS eyeX, eyeY, eyeZ Specifies the position of the eye point. centerX, centerY, centerZ Specifies the position of the reference point. upX, upY, upZ Specifies the direction of the up vector. I understand that in normal situations the last 3 parameters can be 0,1,0. My problem is with the first six. eyeX,eyeY and eyeZ should be the point which is the camera right? and centerX, centerY and centerZ should be the point that it is looking at. So... I assume that unless blocked, all models rendered between these 2 points and slightly behind the centre point can be seen? Heres by implementation: glFrustumf(-240.0f, 240.0f, -320.0f, 320.0f, -10.0f, 10.0f); //so the viewing volume should be 480 by 640 by 20 right? then after that I did a gluLookAt(eyeX :eyeY :eyeZ :0.0f :0.0f :-4.0 :0.0f :1.0f :0.0f); eyeX and eyeY = 0.0; so I would be at point (0,0,eyeZ) looking at point (0,0,-4) right? Just to confirm whether my current train of thought is correct first before moving on to my implementation questions Thanks alot

Share this post


Link to post
Share on other sites
ok, realised that I have read that before and re-read that in case I have missed anything. I'm quite convinced that I'm missing some major point because I implemented my program similarly to what the article said.

Heres what I did:

glFrustumf(-240.0f,240.0f,-320.0f, 320.0f, 0.1f, 100f);

and my gluLookAt is

gluLookAt(0.0f, 0.0f, eyeZ, 0.0f,0.0f, -10.0f,0,1,0);

my model is rendered at origin

for every keyframe,

eyeZ = eyeZ + 0.01;

so I'm moving the camera backwards away from the model. I'm supposed to see my model becoming smaller until 100f is reached then the model disappears completely right? My results are that the model DOES disappear after it is further than 100f away from the camera, but it doesn't get any smaller as the camera is moving away from it.

I seem to be missing something

thanks again for your help

Share this post


Link to post
Share on other sites
Your field of view is way to large. The left- and right-parameters is the width of the view volume at the near clip plane. So at 0.1 units away, your view volume is already 480 units wide.

Let's make a primitive diagram of the view volume as seen from above. The x is the view point, the horizontal bars are the near and far clip plane, and the slanted lines are the view volume border.

b \-------------/
\ /
\ /
\ /
a \-----/
\ /
\ /
0 x

A 0 B

The viewpoint, x, is located at (0,0). The distance to the near clip plane is a, and the distance to the far clip plane is b. A and B are the left and right parameters, and determines the width of the near clip plane at distance a.

As you can see, if a is 0.1, and A/B very large compared to a, then the view volume is extremely wide, close to 180 degrees. For objects to appear reasonably large on the screen, you need to position them very close. Moving them away a little bit makes them extremely small. For example, at a depth of 10, which is only one tenth of the way to the far plane, the view volume is already 48000 units wide, so an object would need to be very large in order to occupy even a small part of the window.

More reasonable is a field of view of about 90 degrees, which means A=-a and B=a. That is, left and right should be -0.1 and 0.1, respectively.

Share this post


Link to post
Share on other sites
ok thanks alot, most of my problems are solved because of this. Final question though, is it a norm to have zNear and zFar a greater value then A/B?

Also, any area outside the trapezium aA,bA,bB,aB cannot be seen right?

Share this post


Link to post
Share on other sites
The values of A/B, near and far should reflect your scale and desired view. The near and far planes should be chosen such that you can see a desired distance. A and B should be chosen such that you get the desired field of view. What is norm depends on scene and desired view.

And anything outside the view volume is clipped, as it would end up outside the viewport otherwise.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this