3D graphics Mathematics (2)

Source: Internet
Author: User

Model and World Space

The object is first described by the object space (the coordinate space connected to the object). Common information includes the vertex position and the surface normal vector. An object space is also called a model space or a local space.

Coordinates can be transferred from the model space to the world space. This process is called model transformation. Generally, illumination computing uses the world space, but it does not matter what coordinate space is used. You only need to ensure that the ry and the light are in the same space.

 

Camera Space

Through Visual transformation, the vertex is transformed from the world space to the camera space, which is also called the eye space. The camera space is a 3D Coordinate System with the origin in the projection center. One axis is parallel to the camera shooting direction and perpendicular to the projection plane, and the other axis is obtained from the top and bottom cropping planes, there is also an axis that is produced by intersection of the left and right cropping sides. If we consider Perspective Projection, one axis can be regarded as horizontal, and the other can be regarded as vertical.

In the left-hand coordinate system, it is often agreed that the camera orientation is + Z, while + X and + y point to the right and top directions (in the case of Perspective Projection ). This is very intuitive, as shown in Figure 15.5. The right-hand coordinate specifies-Z as the camera orientation.

 

Crop Space

From the camera space, the vertex is then transformed to the cropping space, also known as the canonicalview volume space, the matrix corresponding to the transformation is called the cropping matrix.

So far, vertices are still "pure" 3D vectors, that is, they only have three coordinate values, or add the fourth component W, and W is total 1. The cropping matrix changes the current situation and puts useful information into W. It mainly performs two tasks:

(1) Prepare a vector for perspective projection, divided by W.

(2) Normalize X, Y, and Z so that they can be compared with W for cropping.

The first purpose of the crop matrix is to prepare a vector for the perspective projection and divide the coordinate value by W. The 4D homogeneous vector is divided by W and corresponds to the 3D vector:

One purpose of the cropping matrix is to calculate the correct W value to obtain the correct projection, we already know how to project to a plane perpendicular to the Z axis and D from the origin (such as the z = D Plane ). The rectangular part of the projection plane in the cone is mapped to the screen. If D is changed, the projection Plane moves forward and backward. In a real camera, in this way, the focal length will be enlarged and reduced. However, this is not the case for the projection plane in the computer. Increasing the focal length and image size will also increase, but the "negative" (that is, the part of the projection plane in the cone) will also become larger. Because they change proportionally, the rendered image remains unchanged. Therefore, in computer graphics, scaling is completely in the shape and space of the cone, and the D value is not important. Therefore, we can select a D value and keep using it. The most convenient value for us is d = 1.

If this is the sole purpose of the cropping matrix, that is, to calculate the correct W value, it can be simplified as follows:

Multiply it by a vector like [x, y, z, 1] And then perform the perspective division:

Now we know how to use the Matrix to obtain the value of W. Here, you may find that the above work can be completed by dividing by Z. Yes, we can use only Z instead of W, but 4D coordinates can express more camera requirements, including some "singular" forms, such as the projection plane not perpendicular to the camera; another reason is that it makes Z-cropping (near and far-side cropping) consistent with X and Y-cropping to better use hardware. Generally, the homogeneous coordinate 4x4 matrix is tighter and more elegant. In any case, most APIs use it, which is the most important.

Another purpose of the cropping matrix is to normalize the X, Y, and Z components so that the six cropping surfaces have the same simple form. Points that conform to the following simple inequality are outside the cone:

Bottom Y <-W

Top y> W

Left x <-W

Right x> W

Near z <-W

Far z> W

Formula 15.3 crop the cone in the space

Conversely, the conditions in the cone satisfy the following inequalities:

-W ≤ x ≤ W

-W ≤ y ≤ W

-W ≤ z ≤ W

Any point that does not satisfy these inequalities must be dropped.

We use the zoom value of the camera to scale X and Y, so that the top, left, right, and bottom four shear planes are in the correct position. For the near and far shear surfaces, make the near shear surface Z/W =-1, and the far shear surface Z/W = 1.

Set zoomx and zoomy as horizontal and vertical scaling values, and set N and F as the distance between the near and far cut surfaces. The following matrix completes the above calculation:

The so-called "OpenGL style" means that the Z value from the near-cropping surface to the far-cropping surface is between [-W, + W], and other APIs (such as dirextx) Adjust the Z value to the range [0, w]. In other words, if the following formula is met, the point is outside the cropping area:

Near z <0

Far z> W

The points within the cone satisfy the following requirements:

0 ≤ z ≤ W

In this case, the shear matrix is slightly different (formula 15.5 ):

 

Screen Space

Once you crop the ry using the cone, you can project it to the screen space, which corresponds to the real screen pixels. Note that the output window does not necessarily occupy the entire screen, except that the screen coordinate system is usually the same as the rendering device coordinate system.

Obviously, the screen space is 2D, so we need to map 3D to 2D to get the correct 2D coordinates. The following formula summarizes the process: divide by W and adjust x and y to map to the output window shown in 15.6:

Note the minus sign before "Y", because the cropping space is + y up, while the screen space is + y down.

What about zscreen and wscreen? Because the screens are 2D, they are meaningless. However, they cannot be discarded simply. They are also useful in Z buffering and perspective correction.

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.