3D imaging principle

Source: Internet
Author: User
[Rotating] three-dimensional imaging principle

Article category: Flash Programming

Http://uh.9ria.com/space-29516-do-blog-id-5510.html

Note: I have seen such an article on the Internet. I 'd like to share it with you here. Thanks to this netizen for writing these two articles without any effort. This article goes to: DDM
/Furry, flab3d.com
(Allowed reprint, reprint please note) http://hi.baidu.com/sacrtap/blog/item
/242fbf516a00ad848d5430db.html

Basic Principles of 3D image

A 3D model/scenario requires imaging and motion on the screen at least the following elements. You don't have to worry about the difficult mathematical skills or friends you have never touched. First, let's take a look at the specific computing methods.

Models and textures:

The three points are connected into a triangle, and many triangles form a model.

A texture is a plane (u, v), U, V, that is, the X, Y, it's just that we use X and Y, so we are afraid of repetition.

The Paster in flash3d calculates the second matrix parameter (matrix) of beginbitmapfill based on the different slope of each triangle and the UV corresponding to each vertex to fill the triangle with bitmap.

Exercise:

For friends who are new to graphics and mathematics, the following principle (two-dimensional and three-dimensional graphics are like this, but one more three-dimensional Z axis) will surely surprise you.

All the points/models that we think are moving are not actually moving (Relative Coordinate System), but moving is just a coordinate system. Moving, rotating, amplifying, and pivoting are all in the same principle, but they are moving, rotating, amplifying, and pivoting the coordinates of these points/models.

The movements of cameras are essentially clouds. The camera rotates around y clockwise, but the coordinate system of the model turns around y clockwise.

Any change of all vertices is obtained by multiplying a vertex (x, y, z) by a matrix. That's simple.

Never scare us away when we hear this. We don't need to study what a matrix is. We just need to know how to use it. In addition, we do not need to calculate it on our own. The flash3d engine for mathematical algorithms is all written.

If something is to be animated, whether it is two-dimensional or three-dimensional, it must multiply every point of it by a matrix, which cannot be escaped.

'Project' on the screen

Although it is '3d ', we actually watched it on a two-dimensional plane screen. Therefore, we must change the three-dimensional point (x, y, z) to only the point (x, y) displayed on the computer screen. The image can be said that the three-dimensional point is displayed as the point 'project' on the plane canvas.

Some friends may say that I just remove the Z values of X, Y, and Z. Yes, we can get a (x, y) point by directly removing it, but it looks a little strange that the projection graph does not change in size.

So we have 'perspective project'. The algorithm uses x, y divided by a z-related value W to get a perspective (x, y) that is close to big and small ), this is the most normal 3D image that we usually see.

The principle of graphics is the basis for understanding the core content of various flash3d engines. Only by understanding this knowledge can you read the source code of the engine and then add it to the ranks of writing engine code, otherwise, it will only get lost in the sea of code (sometimes it will vomit = A =). Let's take this first step together, come on!

If you have any questions, welcome to the Forum. (No registration required)

Matrix3d Model

The matrix3d class uses a 4x4 square matrix, that is, a table consisting of four rows and four columns of numbers, which contains the data for conversion. The first three rows of the matrix hold each 3D axis.
(X, y, z) data. The translation information is located in the last column. The direction and scaling data are in the first three columns. The scaling factor is the diagonal number in the first three columns. Matrix3d
Element representation:

Any movement, rotation, and scaling transformation of a point (x, y, z) in a space is obtained by multiplying this point by a matrix. The model is composed of (x, y, z) points. The entire model needs to be transformed, that is, to multiply each point by a matrix. This is mentioned in basic principles of 3D imaging.

This is the basic knowledge necessary for 3D engine development and engine code reading.

The flash3d engine provides a wide range of computing classes. (For details, see "pv3d, Sandy, away3d 3D mathematical operations)

Since (x, y, z) multiplied by 3*3 matrix can achieve the purpose of rotation and scaling, but it cannot represent movement, so in order to unify, we usually use a matrix multiplied by four rows and four columns. Our flash3d engine is also related to the 4*4/4*3 matrix algorithm we have prepared. That is to say, all transformation methods use the following formula:

After the transformation, (x', y', Z') = the original (x, y, z) multiplied by 4*4 matrix m

To use the pv3d mathematics class, write the following statement:

VaR point: number3d = new number3d (value of X, value of Y, value of Z); // original Vertex

VaR array: array = [N11, n12, N13, 0,

N21, n22, n23, 0,

N31, n32, n33, 0,

NX, NY, NZ, 1]; // each value in the constructor matrix needs an array, which is usually written in this format.

VaR matrix: matrix3d = new matrix3d (array); // constructor Matrix

Matrix3d. multiplyvector4x4 (matrix, point); // the X, Y, and Z data of the vertex is directly updated to the data after multiplication.

Which matrix m is used? The following is a list:

(The formula diagram of this tutorial, from skyman Jun's blog http://www.cnblogs.com/skyman)

Rotate

Rotation should be the most troublesome thing in 3D, because humans have limited descriptions of rotation. Many situations of controlling rotation by matrix alone are very complicated and imperceivable. Therefore, we have also invented the better control methods of rotation by using the angle and the four element. These will be discussed later.

Angle θ indicates the angle of rotation of an axis.

The following three matrices represent the rotation matrices of the point following the X axis, Y axis, and Z axis respectively.

Mobile

From the formula, we can easily see that the number of Columns 1, 2, and 3 in the 4th rows controls the movement of points in the direction of X, Y, and Z respectively.

Zoom

We can easily see from the formula that N11, n22, and n33 on the diagonal lines control the zooming of points in the direction of X, Y, and Z respectively.

These are the simplest transformation matrices. Once we are familiar with these matrices, we have taken another step forward.

Graphics should be a very interesting thing, not something as painful as many schools and student professors. In fact, the principle is very simple. If you have a little programming knowledge, you can easily make your own imaging programs.

Note: I have added two articles so that it is easy for everyone to understand.

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.