View Full Version : Projection in perspective mode and lookAt : Newbie questions

08-16-2013, 03:24 AM
My name is Romain and I'm new on this forum.
Little presentation :
I'm a french developper and I use openGL in my software for points, polygon and polyhedron representation.
I develop in c++ with Qt for 10 years for geological application. My formation is geophysics that is a mix between geology and physics.
On my new software, I have to show on screen several polygons, but I have a problem of understanding the parameters of gluPErpestective and gluLookAt.
In fact my 3d objects are not center on (0;0;0). The Box that contains all my objects in (-50;-50;-600) for the top-left corner of the box and (50;50;-800) for the bottom-right corner.
My objects are under the sea-level, so negative (depth in meters under the ground)
Here is my code :

glViewport(0.0, 0.0,_width, _height); //(800x800)
gluPerspective(180.0, 1.0, -50.0, 50.0);
foreach (RSolid3d* solid, _listSolid) { //iterates all solids (list of facets)
glColor3ub(solid->color().red(), solid->color().green(), solid->color().blue());
foreach (RFacet3d* facet, solid->facets()) { //iterates all facets in the solid
glBegin(GL_POLYGON) ;
if (facet->p1()) glVertex3f(facet->p1()->x(),facet->p1()->y(), facet->p1()->z()); //facet->p1() is the first point of the facet (0,37,-600) for example
if (facet->p2()) glVertex3f(facet->p2()->x(),facet->p2()->y(), facet->p2()->z());//facet->p2() is the second point of the facet (0,36,-600) for example
if (facet->p3()) glVertex3f(facet->p3()->x(),facet->p3()->y(), facet->p3()->z());//facet->p3() is the third point of the facet (0,37,-601) for example
if (facet->p4()) glVertex3f(facet->p4()->x(),facet->p4()->y(), facet->p4()->z());//facet->p4() is the fourth point of the facet (0,36,-601) for example
glEnd() ;

With this code, nothing appears on screen.
I have made some test with objects coordinates divided by 10 and other parameters of projection that show the polygon.
I think I am not so far. Maybe I do a confusion between real x,y,z cartesian axis and x,y,z camera coordinates.

Thanks a lot for a little explanation.

08-16-2013, 05:26 AM
On my new software, I have to show on screen several polygons, but I have a problem of understanding the parameters of gluPerspective and gluLookAt.
In general, gluPerspective() is used for the projection matrix while gluLookAt() is used as the initial model-view matrix. E.g.

gluPerspective(90.0, 1.0*width/height, 1.0, 100.0);

Also: the first parameter to gluPerspective() must be less than 180 and should typically be no more than 90 unless you intentionally want a "fish-eye" view.

The second parameter should be the aspect ratio (width/height). If you know the physical dimensions (millimetres, inches) of the window, using those to compute the aspect ratio will produce a more accurate result if the pixels aren't square.

The last two parameters must both be greater than zero. The ratio between the two determines the degree of non-linearity in the depth buffer resolution, with a higher ratio resulting in more non-linearity (i.e. depth resolution being finer close to the near plane and coarser close to the far plane). The near plane distance is typically set in order to avoid clipping visible polygons. The far plane distance should be as high as you can get away with, in order to minimise the non-linearity of the depth values.

08-16-2013, 06:38 AM
Thanks for your reply.
I am in progress...