Jian Ying will play with you on graphics (3 ).

Source: Internet
Author: User
Tags mathematical functions

Today's topic is mathematics, especially vector.

Opening nonsense

Wang quanan went in again. Recently, it is not good to cite the island culture to start.

The Mid-Autumn Festival reminds me of a popular song.

 

When the moon was there, I asked the group of friends about the wine.
I don't know if this version is available tonight.
I am afraid that the project manager will yell at me late at night.
Added, deleted, and modified code. It seems that the Code is not saved .....

Take a deep breath and watch the screen. Tears are flowing.
Do not hate it. Who did not forget to save the code?
People have joys and sorrows, and there is a loss conflict between codes.
Long-lasting, don't discover leader.

 

How did our friends spend the Mid-Autumn Festival? Is there a Project Manager yelling at you?

Welcome to deyun community to listen to crosstalk. Oh no, I don't think it's right to listen to Mr. Li's story. We are playing code series and graphics.

 

Graphics is a comprehensive discipline, and a large part of it is 3D mathematics.

What is the difference between 3D mathematics for graphics and 3D mathematics for client logic?

I don't know where the demarcation line is. I only know the game client. 3D mathematics is everywhere.

If you cannot hide it, let's have a good time.

Fast Improvement

Now, I want to teach you how to quickly improve your business (zhuangbi.

Today, I am talking about the last tips to improve the business level.

You must develop your own ideas. What Baidu cannot find.

In this way, you can greatly improve the impression of others on you.

Tolerance, persistence, and enlightenment. I have taught you a full set of cheats this time. Let's review them.

Endure: do not take the initiative to teach others. If others have doubts, they will find you. active teaching may lead to resentment.

Hold: You must have a selective answer. Do not give answers to inaccurate things to improve accuracy.

Wu: You must have your own opinions.

With this set of knowledge, the level of the business (zhuangbi) will become unmanageable.

 

Now I will give you a brief introduction to the unity3d mathematical library, which will help you improve your business.

Basic Mathematical tools:

Unityengine. mathf

Focuses on the static types of mathematical functions related to float numeric computing, such as cos sin sqlr

Compared with system. Math, mathf is more convenient because the longest data type we use is float.

Unityengine. Random

The random number generator is used in a different way than system. Random. It works in the same way, but it is static. You can write less than two rows.

Specific mathematical tools:

The mathematical functions corresponding to specific mathematical tools are in this type.

Vector2 vector3 vector4

Indicates vectors or vertices. Their related computing functions are all in vector2 vector3 vector4.

For example, vector3.cross cross Cross Product vector3.dot Product

Rect

Represents a 2D rectangular area

Bounds

Represents a 3D Square area

Matrix4x4

Indicates the matrix. The matrix represents a space transformation in the form of scum of the soil.

Quaternion

It represents the Quaternary element, And the Quaternary element represents a rotation by means of soil slag loss. This article will introduce it later.

These are commonly used mathematical tools, and float, which are our most commonly used mathematical tools.

Understanding the meaning of Computing

Speaking of mathematics, it is a helper for many people to help with sleep.

Two math books before going to bed give you a good night's sleep.

It is true that those terms will make people sleep.

Start now.

An error is shown. Sorry.

Archimedes said: Give me a pivot and I will be able to shake the earth

"Give me a pixel and I will be able to get a 3D engine

Mr. Li said :..........

Wei people told us that to learn real things, we have to go from a single row to a single row.

I have prepared a group of examples.

The examples mentioned below can be used online.
Http://lightszero.github.io/basemath/outweb.html
The sample code can be obtained from the following GitHub address:
Https://github.com/lightszero/BlockFun/tree/master/unity/basemath

What is the use of random numbers?

Random correspondence is fixed, resulting in more natural changes. However, random numbers are also controlled, which is a problem in probability theory,

We have prepared two examples. One is to use a random number to calculate the circumference rate.


You can use a random number to calculate the circumference rate.

Randomly draw points on the texture and calculate the area inside and outside the circle respectively. The area of the circular area is 0.5*0.5 * Pi, and the area of the square is 1*1.

Then Pi = Area of the circle/square area * 4.

The total number of points can be considered Square area.

Points falling in the circle can be considered as the area of the circle.

The other is to use random numbers to distribute roles.


In the figure, the teacher on the screen uses a random number for distribution. Each time you open the screen, it will be different.

Vector

Vector is the focus of this Article

Vector3 is a data structure that can represent both a scalar point and a vector.

What do you want him to be? He is also a bit confusing.

This is actually a common problem that we only care about the numerical value in programming.

Think about float. The unit and function are not in it.

Expression scaling, float can, expression speed, float can, expression length, float can, expression time, float can.

What is the significance of granting data structures to humans.

 

For addition and subtraction of coordinates, these numbers are not required. Let's clarify the two very important operations, vertex and cross product.

 

Significance of vector dot product:

Do you still remember how the target military team identified the enemy's field of view? It depends on the dot product to determine whether our pig feet are exposed to the enemy's conical field of view.

The significance of dot product mainly lies in finding the angle between two vectors. Imagine the relationship between the angle and the field of vision.

In the shader illumination model, the light intensity is determined by the normal direction of the triangle and the light direction, and the angle is obtained by vector. This is the significance of dot product.

We have prepared an example for dot product.

A screen teacher, the mouse position represents the direction of the teacher's eyes.
The intensity of attention is about 30 degrees.
The red voice teacher looked at the location where Mr. Cang was white, and the invisible location was red.

 

Significance of vector cross product:

If you have a fleet of planes and want them to maintain the formation during the flight, the calculation of the vector cross product can satisfy you. The cross product is used to find the vector perpendicular to the two vectors.

By using this feature, you can calculate the frontend, left, and right sides of the team leader at any time. Of course, you can also align with other things.

In the calculation of direct plot, a major application of the cross product is to automatically calculate the normal. The vector perpendicular to any two sides of a triangle must be perpendicular to this triangle, which is the normal of this triangle.

We have also prepared an example for cross product.

No matter which direction the red music teacher looks at, the red music Corps will always remain standing around the red music teacher.

 

Insert

Interpolation is the most important idea in client development.

It is the basic idea of animation. For vector3, interpolation has two completely different meanings.

Because vector3 expresses two meanings at the same time, as a scalar, it represents a point in 3D space.

Coordinate Interpolation of vertices and points is a straight line between two points.

Moving along the established route basically comes from point interpolation.

 

As the vector vector3, it expresses a direction, and the opposite direction and the direction are interpolated, which is a rotating fan surface.

For example, the classic sick, his face is directed wherever you are.

However, when you use vector3 as a vector, you will get a strange result.

, From direction A interpolation to direction B, direct use of vector interpolation will lead to a Length Change in the middle value, in ab180 degrees, then think about this strange result.

Interpolation of vectors relies on the tool of the Quaternary element, which will be mentioned later.

Vector interpolation and vertex interpolation have a typical case in the calculation of direct plotting.

 

We have also prepared an interpolation example.
On the basis of the above, change to the red voice teacher and click the mouse before turning.
Will gradually turn through Interpolation
However, in order to quickly complete the security task, the red audio Corps uses a straight line movement, and the formation remains unchanged.
The red audio Corps moves through coordinate interpolation.

This article is over. The following example describes other mathematical tools.

The vector is clear.

Matrix

Remember, we once introduced that matrix is a dirty mathematical tool.

The meaning of a matrix is a spatial transformation: rotation, jumping, and my eyes.

A matrix can describe any spatial transformation. Information about rotation, translation, and scaling.

Although matrices can also be used to describe the effects of trapezoid transformation and the collapse of the parallelogram, they are not commonly used.

The rotation, translation, and scaling parameters are stored in a 3*4 matrix.

You can save a matrix to describe the position of an object in another space.

Insert

Unfortunately, matrices are not suitable for interpolation.

Only translation can be directly interpolated.

Like the vector matrix, direct mathematical Interpolation of rotation produces singular results.

For scaling, the matrix also produces an inconspicuous error.

If the model scales unevenly with the XY axis, the same matrix is not suitable for the normal of the model, resulting in no vertical line between the normal and the surface.

This is why the reverse matrix is used in the illumination model.

Quaternary

It is also a tool used to describe the dregs of a soil. The information described is called an angle pair.

An Angle pair is a rotation axis with a rotation angle.

Set the axial volume to N and the rotation angle to T.
The value of the Quaternary element is:
X = n. x * sin (T/2)
Y = n. y * sin (T/2)
Z = n. z * sin (T/2)
W = cos (T/2)

As for the interpretation of the super-complex number, you just need to know how to improve the zhuangbi level.

In fact, just to get the new axis-angle pair after the two rotating links for the multiplication of the four-element method.

In this way, the Quaternary Multiplication can be directly converted into a rotating Connection Tool.

Red Q1 indicates a rotation, and green Q2 indicates a rotation. Their multiplication result is blue Q3.

The information expressed by the Quaternary element is a rotation transformation, which can be directly stored as the rotation volume of an object.

 

Another piece of personal opinion may be full of ignorance and prejudice. Just listen:

The invention of the Quaternary element was in 1843, and the graphics was born in 1963, but in 1985, the Quaternary element was used to express rotation and gradually promote it.

It is used as a computing tool of coordinate pairs in graphics.

I'm not convinced of the fact that the super-complex number or non-zero Quaternary multiplication ring is used to realize rotation, just like a horse.

For example, if we realized that the non-zero Quaternary multiplication ring is bound to realize rotation, how could it take more than 20 years to find a suitable method for expressing rotation.

Insert

The description of the rotation of the Quaternary element is the rotation axis + angle, which is not more suitable for the rotation interpolation than it is.

In the skeleton animation, the interpolation computation of the rotation of the skeleton uses the Quaternary element.

Region

Area is the box

There are two common forms

Axis aligned bounding box

Oriented bounding box

AABB axis alignment box.

OBB oriented surround box.

It is a method to simplify collision and perimeter testing. Pack a bunch of things in a box

I found a picture, which shows a very good image. I wrapped the villain up and determined that the villain is not in the same area. I decided that his box would be much faster.

OBB is the box of the villain in his own space. It does not change as the villain rotates and jumps.

AABB is the box of the villain in the world space, and the villain will be re-generated after rotation.

In addition to the collision box, there are other common forms of Surrounding

2d rect

3D obb aabb also has hitting balls, capsules and so on.

 

The full text is complete. Photo burst by the way

A

Jian Ying will play with you on graphics (3 ).

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.