Android OpenGL ES (12): three-dimensional coordinate system and coordinate transformation preliminary.

Source: Internet
Author: User

OpenGL ES Graphics Library The final result is the display of a two-dimensional object (often referred to as model) on a planar surface, because the current part of the display can only display two-dimensional graphics. But we have to be able to construct a 3D model with spatial phenomena, and all of the models are described using three-dimensional coordinates. That is, using 3D modeling, and the OpenGL ES Library to complete the display from the 3D model to the two-dimensional screen.

This process can be divided into three parts:

    • coordinate transformations, which are described by using a transformation matrix, Therefore, learning 3D drawing requires knowledge of some spatial geometry and matrix operations. Three-dimensional coordinates are usually defined using homogeneous coordinates. Transform matrix operations can be divided into visual angle (viewing), model (Modeling) and projection (Projection) operations, which can have selection, translation, scaling, orthographic projection, perspective projection and so on.
    • because the final 3D model needs to be displayed in a rectangular window, So the parts outside this window need to be cropped to improve the efficiency of the drawing, corresponding to the 3D graphics, and the clipping is to throw away the part that is outside the cut plane.
    • In the final drawing to the display (2D screen), The corresponding relationship between the transformed coordinates and the screen pixels needs to be established, which is often referred to as the "window" coordinate transformation (Viewport) transformation.

If we use the camera to take pictures of the process of analogy, we can better understand the 3D coordinate transformation process.

    1. The first step in taking a picture is to frame the tripod and point the camera to the scene you need to shoot. , corresponding to the 3D transform for viewing transformation (pan or select camera)
    2. Then the photographer may need to adjust the angle of an object in the scene, such as when a photographer gives you a picture of a tripod, and you can adjust your standing position or position. Mapping to 3D is modeling transformation (adjusting the position, angle, or scale of the plotted model).
    3. after pressing the shutter, For a digital camera to display the currently taken photos directly on the screen, you can generally fill the entire screen (equivalent to normalizing the coordinates for NDC), where you can use the Zoom zoom function to display the portion of the photo. Corresponds to a 3D drawing equivalent to viewport transformation (which can be scaled for the final image)

Process for the Android OpenGL es coordinate transformation:

  • The Object coordinate system: Also known as the local coordinate system, is used to define the coordinate system of a model itself.
  • World coordinate system:3d The absolute coordinate system in virtual worlds, defining the origin of this coordinate system can be used to describe the location of the model, the location of the Camera, and the location of the light source.
  • View coordinate System: typically used to calculate lighting effects.
  • Clip coordinate System: uses a projection transform to crop the frustum for a 3D scene.
  • Normalized device coordinate system (NDC): Canonical coordinate system.
  • Windows coordinate system: The last screen displays the 2D coordinate systems, the general origin defined in the upper left corner of the screen.

For viewing transformation (pan, select camera) and modeling Transformation (panning, select model) can be combined to see that only the camera should be moved to the left, and the effect of moving the model right is equivalent to the camera.

So in OpenGL ES,

    • Use Gl10.gl_modelview to specify both viewing matrix and modeling matrix.
    • use GL10 . gl_projection specifies a projection transformation, OpenGL supports perspective projection and orthographic projection (typically for engineering drawings).
    • use Glviewport to specify the Viewport transform.

At this point, look at the following code, it is not difficult to understand, after the gradual introduction of various coordinate transformations.

 Public voidOnsurfacechanged (GL10 GL,intWidthintheight) {//sets the current view port to the new size.Gl.glviewport (0,0, width, height);//Select the projection matrixGl.glmatrixmode (gl10.gl_projection);//Reset the projection matrixgl.glloadidentity ();//Calculate The aspect ratio of the windowGlu.gluperspective (GL,45.0f, (float) Width/(float) Height,0.1f,100.0f);//Select the Modelview matrixGl.glmatrixmode (gl10.gl_modelview);//Reset the Modelview matrixgl.glloadidentity ();}

Android OpenGL ES (12): three-dimensional coordinate system and coordinate transformation preliminary.

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.