PDA

View Full Version : perspective



t3jem
06-03-2005, 08:44 PM
I have a program where my camera roams around a forest that is 20X20 units. My problem is that I can't get the perspective right. My trees are 0.2 units wide.

Here is the code that causes the problem.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(120,4/4,0,1);
gluLookAt(view.x,view.y, view.z+0.5, view.lx, view.ly, view.lz, 0, 0, 1);
glOrtho(-1,1,-1,1,0,20);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

06-03-2005, 10:46 PM
Originally posted by Terminatore3:

{code]
gluPerspective(120,4/4,0,1);
[/CODE]
A znear of 0 is invalid and will kill your zbuffer, it must be a value greater then zero, try 0.1 instead.

A FOV of 120 is kind of extrem, I usually go for 45-60 depending on the situation.

Overmind
06-04-2005, 03:49 AM
Two more issues:

1) You have to use gluPerspective OR glOrtho, not both of them.

2) On the projection matrix you should have ONLY the projection, not the camera transformation.


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (float)width/(float)height, 0.1, 50);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(...);width and height are the dimensions of your window. The near plane should be set a bit away from the origin, never set it to 0. The far plane has to be far enough to see something, I think in your case 50 should be enough. You can play around with these values...

t3jem
06-04-2005, 12:03 PM
great!

thanks