An analysis of OpenGL gluperspective

Source: Internet
Author: User

Gluperspective is a function in OpenGL. prototype of a function

Gluperspective (gldouble Fovy, gldouble aspect, gldouble znear, gldouble Zfar);

Fovy: The size of the angle of view. What is perspective. The upper and lower angles of the viewing body to the origin of the line of sight.

Aspect: The ratio of width to height.

Znear: The distance between the observation point and the near-edge clipping plane.

Zfar: The distance between the observation point and the far-side clipping plane.

Znear and Zfar illustrate that for a drawing, the distance from the origin of the line of sight must be between the two. functions of the function

Set the perspective projection matrix, what does that mean? We know that when we look at things, the farther we look, the smaller they appear, and the larger they become. This function is one such effect, so that we draw a graph with a different size and distance effect.

As an example:

We draw segments of the same length (2 units in length), but their z-axes are different.

Glbegin (gl_lines);
	glvertex3f ( -1.0f, 0.0f,-1.0f); Draw the first line segment
	glvertex3f (1.0f, 0.0f,-1.0f);
	glvertex3f ( -1.0f, 1.0f,-5.0f); Draw the second line segment
	glvertex3f (1.0f, 1.0f,-5.0f);
Glend ();

We see that the z-axis of the two segments is 4 units apart.

By running the results, we can see that there is a different relationship between the two line segments and the distance. The impact of perspective

What is the effect of the angle of view (range 0~180度) on drawing graphics?

When the angle of view is 0 degrees, this is the equivalent of our eyes closed, then God horse can not see.

When the angle of view is 180 degrees, this shows that our field of vision is infinite, then also can not see anything, because the drawing, relative to the "horizon" is too small, small enough to ignore.

So it is important to choose a suitable perspective (generally 45 degrees is the most suitable, but the specific case analysis).

How do you realize the effect of distance and size by the angle of view?

Let's take a look at the following 3 images:

From the top 3 pictures, did you see something? By changing the size of the view, correspondingly, the image projected into the window also releases the change in size, thus giving a near and far effect.

You can download Nate Robin's package, run the Projection.exe file inside, and then try to adjust the parameters yourself to be more clear.


To be continued~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.