Android OpenGL ES development tutorial (17): Projection Transformation projection

Source: Internet
Author: User

The previous modelview transformation is equivalent to placing the camera and adjusting the position and angle of the object to be photographed. The projection transformation corresponds to adjusting the camera lens distance to obtain the scene.

BelowCodeSet the current matrix mode to projection matrix:

Gl. glmatrixmode (gl_projection); <br/> Gl. glloadidentity ();

 

Subsequent coordinate transformations are for the projection matrix. The purpose of projection transformation is to define the Viewing Volume. On the one hand, the cone defines how objects are projected to the screen (such as perspective projection or positive side projection ), on the other hand, the cone also defines the area size of the cropping scenario.

OpenGL ES can use two different projection transformations: Perspective Projection and orthographic projection ).

Perspective Projection)

Perspective Projection is characterized by "nearly big, far and small", that is, the world that our eyes see on a daily basis. OpenGL ES defines the Perspective Projection FunctionGlfrustum ():

Public void glfrustumf (float left, float right, float bottom, float top, float near, float far)

The taper (left, bottom,-near) and (right, top,-near) define the cropping surface near the observation point, near and far define the close distance and long distance between the observation point and the two created surfaces.

Android OpenGL ES provides an auxiliary method for writing code.Gluperspective ()You can simply define a Perspective Projection Transformation:

Public
Static void gluperspective (gl10 GL, float fovy, float aspect, float znear, float zfar)

    • Fovy: defines the view angle of the video cone.
    • Aspect: defines the aspect ratio of the cone.
    • Znear: defines the close distance of the cropping surface.
    • Zfar: defines the long distance of the created plane.

Orthographic Projection)

Positive side projection. Its cone is a cuboid, which is characterized by the fact that the object size does not change with the distance to the observation point. After projection, the distance and angle between objects can be maintained. It is mainly used in engineering drawing.

The function that defines a positive projection (also called a translation projection) is:

Public void glorthof (float left, float right, float bottom, float top, float near, float far)

Crop

After the vertices in the scene are transformed by the modelview and projection coordinates, all vertices outside the viewing volumn are cropped, and the perspective projection and the normal side projection have six cropping surfaces. All vertices outside the cropping surface must be cropped to improve the Drawing performance.

 

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.