Perspective in OpenGL ES

Source: Internet
Author: User

Due to the limitations of the orthogonal projection, he can only guarantee to fit the screen aspect ratio, but cannot create a range to convert the three-dimensional effect to a two-dimensional effect, so we use a technique used in the art of painting:

(About the perspective method below is a good description of the site, the map is also easy to understand: http://www.artyfactory.com/index.html )

Because we have removed the orthographic projection and are ready to use perspective projection, there are some features that must be described for perspective projection.

The perspective projection has a special noun called the cone of Sight, which has a very good introduction from a blogger:

Http://www.cnblogs.com/graphics/archive/2012/07/25/2582119.html

This blog post also has the perspective, suggest the reader to look, certainly better than I speak.

In short, the view cone constructs a pyramid-like virtual space through a matrix, the other part is invisible, the space is mapped to the device is converted to two-bit coordinates, in order to produce a three-dimensional effect, it defines a perspective method to transform, similar to this:

VP is the vertex of the cone of view, the small square is near the end, the large is far, the effect of painting after the production:

It can be seen that this produces a three-dimensional effect.

Perspective projection matrix generation can refer to the Android comes with the source of the Matrix OpenGL, but to android4.x above, it is recommended to refer to the source code to achieve their own, the following is the implementation of the book:

1  Public Static voidPerspectivem (float[] m,floatYfovindegree,floatAspectfloatNfloatf) {2         Final floatangleInRadians = (float) (Yfovindegree * math.pi/180.0);3         Final floatA= (float) (1.0/math.tan (angleinradians/2.0));4 5M[0] = A/aspect;6M[5] =A;7M[10] =-((f+n)/(fn));8M[11] =-1f;9M[14] =-((2f*f*n)/(fn));Ten  Onem[1]=0f; Am[2]=0f; -m[3]=0f; -m[4]=0f; them[6]=0f; -m[7]=0f; -m[8]=0f; -m[9]=0f; +m[12]=0f; -m[13]=0f; +m[15]=0f; A}

This is just an implementation of a simple perspective matrix, near and far between -1~-10, and the observation vertices are outside the screen, not inside the screen.

View the effect of the perspective by adding a cube rotation:

But because of the front view, the initialized views are less obvious:

This is caused by the order of the vertex data I have defined, and it is natural that when the lines are drawn together in the back line (that is, the edge line), the edges of a polygon that I define will not be overwritten, so there is a visual problem, and I will try to solve the occlusion problem in the next step.

Above.

Perspective in OpenGL ES

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.