The relationship between OpenGL's Glulookat and Glortho
Never understood the relationship between Glulookat () and Glortho ():
Glulookat () is an observation transformation, and Glortho () is an orthographic projection.
Gllookat () is the location of the camera, and Glortho () is the current visual space set to the positive projection space.
Glulookat () Action Modelview Matrix, Glortho () Action projection matrix.
Sometimes the graphics can not be seen, and sometimes can be seen, then what is their connection? We look down:
First look at the definitions of these two functions:
void Glortho ( gldouble left,
Gldouble right,
gldouble bottom,
gldouble top,
gldouble near,
gldouble far);
void Glulookat (gldouble eyex, gldouble eyey, gldouble Eyez,
gldouble CenterX, gldouble centery, gldouble Centerz,
gldouble upx, gldouble upy, gldouble Upz);
code example:
Glortho (-1,1,-1,1,-3,3); Glulookat (0,0,2.9,0,0,0,0,1,0); glcolor3f (1.0,0.0,0.0); Glviewport (0,0, -, -); Glbegin (Gl_lines); glvertex3f (-1.0,0,-0.1); glvertex3f (1.0,0,-0.1); glvertex3f (0.0, -1.0,-0.1); glvertex3f (0.0,1.0,-0.1); Glend ();
The camera range is set using the Glulookat function, but its field of view is near and far in the Glortho. As the above program is near (2.9+3,2.9-3) this range, so-0.1 just grazing, these two lines can also be seen.
Also, if your graphic is in the back of the camera, it is within the range of the <5.9 (both horizons are open intervals), or you can see the graphic.
So for logical correspondence, we should write both near and far as positive, and this positive direction refers to the distance from the camera pointing to the negative axis direction.
The relationship between OpenGL's Glulookat and Glortho