(serial) Drinking coffee and learning unity--The second chapter prepares the knowledge system

Source: Internet
Author: User
Tags modulus scalar

Chapter II Preparation of the knowledge system

This chapter deals with many basic disciplines such as space mathematics, analytic geometry, linear algebra, computer graphics, algorithms, data structures, etc. Compared to the previous chapter, although boring, but can not be called the chapter of nonsense, even if a cursory look at, also than directly jump over the good, detailed reading, will let the reader after the development of the road to go more flat.

And the knowledge of this chapter is not only helpful for your Unity game development, it's very useful for most software developers.

As a traditional 3D game programming, the need to use a wide range of knowledge, involving a particular number of disciplines. But usually programming books, will weaken the mathematics knowledge, the mathematics book, will weaken the programming knowledge. This is the gap between mathematics and programming that I mentioned in Chapter I. and connecting the link between math and 3D game programming, we simply call him space math. Although unity has encapsulated the underlying graphics interface without our writing to complete the game development, it is hard to say that a program written by someone who doesn't know anything about graphics, GPU programming, or computer graphics can be a problem, both in terms of performance and compatibility. Not to mention the vector multiplication, Euler angle, which we learned at the beginning of unity programming. It's hard to understand what the code is doing without the knowledge to pave it. Imagine when we set the Euler angle of a character, you shout, not the Euler angle! We're not learning anything in the graph. Eulerian graph ( all edges once and only once for all vertices in the graph are called Oraton paths, and loops through all the edges once and only once across all vertices are called the Euler loops. A graph with a Euler loop is called a Eulerian graph. ), it must have something to do with that. That's a mistake! Euler's angle and Eulerian graph are the two things that unrelated.

Frankly speaking, I love and hate maths. Love math because a lot of time math knowledge let us verify a lot of problems. Hate maths because simple mathematics is too obscure and abstruse. Thinking back to my study career, English and physics and chemistry has been my specialty dishes, mathematics results from the beginning of the sinusoidal wave in general. After work, more and more aware of the importance of mathematics, now all walks of life need a basic discipline can be said to be a branch of natural science, and the natural science from the beginning of the death of the thigh, no mathematical support, any natural science is no longer exist. So please adjust the good mentality following the author to learn the basic knowledge of this chapter, encountered the knowledge of mathematics faint smile, unable to understand the simple gestures.

disciplines that are closely linked to unity development

Computer graphics, linear algebra, solid geometry, data structure these are obviously related disciplines, of course, more advanced, network programming, computer composition principle, database, etc. is also indispensable. Readers should understand that this chapter can not put so many disciplines into a chapter, can only be selected important content, each of which may be a year in the university curriculum, for a piece of knowledge points, I hope readers have a strong desire to consult relevant information to learn.

Computer Graphics Section

Concept: Computer graphics A main research using computers and graphics equipment to input, representation, transformation, operation and output graphics principles, algorithms and systems of science. In game development we are more concerned with how to output images that are close to the real picture.

In computers, graphics generally have two categories, bitmaps (consisting of pixel dots) and vectors (consisting of vectors). The former is characterized by: high occupancy space, compression irreversible, amplification will be distorted but because it is already a pixel color, so the computer does not need special treatment can be used to express the display. The latter is small and can be scaled at will, but the final display on the screen still needs to be converted.

And how does the monitor turn the graph into a light signal for our retina to see? The development of mainstream displays can be broadly divided into 3 chunks:

Cathode ray tube display (Crt--cathode ray Tube), this kind of display of the previous people must know, physics textbooks are also described in detail, the negatively charged rays of the magnetic field after an adjustable field deflection, hit the screen in different positions, produce images.

Liquid crystal Displays (Lcd--liquid crystal display), should be basically all the readers are currently using the display bar, LCD is very thin, our mobile device is also due to the LCD display can be ultra-thin. Its main principle is to stimulate the liquid crystal molecules to produce points, lines, surface with the back of the lamp composition screen.

Plasma display panels (Pdp--plasma display Panel) are the latest generation of display devices using the high-speed plasma plane screen technology of recent years. The principle of imaging is to arrange thousands of sealed low-pressure gas chambers on the display, through which the current is excited to emit invisible ultraviolet light, and then the ultraviolet light strikes the red, green, and Blue 3 -color phosphor on the back of the glass to produce visible light that can be seen by the naked eye.

Computer graphics processor

Graphics processor (Gpu--graphics processing Unit ), is an important component connecting the monitor and the PC motherboard, which drives the display information required by the computer system and provides a line scan signal to the monitor to control the display's correct display. its initials are very much like our CPU CPUs, gpu cpu can perform various executions, gpu only handles graphics directives. Its main task is to build and render the video information entered by the system, and the graphic functions are basically integrated here, such as many 3d video cards are supported by opengl hardware acceleration, directx

 

gpu gpu+ video memory video card, where ramdac gpu performance. The bigger the better, the quicker the better. So a good graphics card is not only gpu ( "

Coloring (Shade) and Rendering (render)

shading and rendering look functionally similar, but they are quite different. Shading is used to show simple lighting effects, shadow effects, and surface texture effects. Rendering is the process of outputting a model or scene to an image file or video signal.

The Book of computer graphics is here, and this vast discipline still has a lot of knowledge for the reader to learn by themselves.

Linear algebra Section

Vectors and scalars

The first chapter has mentioned that most parts of unity use vectors to express attributes. So what is a vector? What is a scalar? The amount that can be expressed in a real number after the unit is called a scalar, such as length, area, time, and so on. The amount of both direction and size is called a vector (also called a vector). such as speed, force, displacement and so on.

Specifically, in 3D programming, we generally believe that dots and vectors are a concept, and this book does not distinguish between the 2 nouns. The vector has a characteristic that it has no position concept. This means that as long as there are two vectors of the same length and direction, even if the starting point is different, we think it is the same vector.

Coordinates

The coordinate system should be something that everyone is familiar with. The coordinate system is used to quantify space. I would simply say a few common coordinate systems. We have the most contact coordinate system, it should be a planar Cartesian coordinate system, and then the texture map will refer to a texture coordinate system, in fact, is a special planar Cartesian coordinate system. The planar Cartesian coordinate system has two constraint words: plane, right angle. It is clear that the coordinate system may not be a plane or a right angle.

Planar Cartesian coordinate system we simply call it a 2-dimensional coordinate system because it has two axes: X and Y. From 1-D to 2-D, to 3-dimensional, to a higher-dimensional coordinate system, to describe the higher dimensions of space. One of the things we can most directly understand is the 3-dimensional space, 4-dimensional space, the need for a very high imagination to imagine, more abstract, and as human evolution can directly perceive and control the higher dimensions, it is not impossible, many science fiction often describes the high dimensional space.

From the point of view of physics, the dimensions of the universe are 10 dimensions, and the dimensions in physics are different from the dimensions in mathematics. Man is a low-dimensional creature that wants to recognize and understand the higher dimensions of space, the simplest way is projection. For example, in 4-dimensional space in the super-cube, we humans are difficult to directly understand, can be projected in some way to 3-dimensional space, see the Ultra-cube in the 3-dimensional space of the shadow to imagine the 4-dimensional space of the super-cube appearance, like the projection of people to the wall, according to the shadow to imagine the same person Why is it that, because the projection angle is different, the resulting shadow will be different.

Yesterday I went to the cinema to see the recent fame and noise of sci-fi film, "Star Crossing", wherein the description of the black hole is a future human build a high dimensional space of the super-cube. I like the film, and many of the details are very thoughtful, such as when astronauts describe the wormhole. Many people previously understood that the wormhole is a round hole, and this movie gives me the image and explanation of the wormhole sphere more convincing. The wormhole is a possible solution in the relativistic equation, discovered by Einstein and Rosen, whose physical meaning is that the gravitational field can bend space-time so that the two positions that would have been so distant are bent and become very close, making it a shortcut to connect the 2 positions. The astronaut bent a piece of paper, then, with a pen through, and then unfold, said: "This paper is a two-dimensional space, through the higher dimensions (3 dimensional space) curved the space after the formation of wormholes, and then expand the paper to restore the two-dimensional space, we see the wormhole from 3-dimensional space to 2-dimensional space projection into a circular hole. Then the two positions in the three-dimensional space are bent through a higher dimension to form a wormhole and projected in a 3-dimensional space, it should be a sphere rather than a circle! “。 If you see this movie when you understand the words he said, I believe you have a good space imagination! It can be deduced that the wormhole in 4-dimensional space should be a super-sphere, and so on.

Speaking of the change of dimension, I have to tell you one of my favorite stories. As I am a two-dimensional creature, living in a flat space for a lifetime, we think a square is a very closed shape, so we put valuable items in a square to store, and think, "as long as my square is not cut, how can the inside of the thing be taken away?" ”。 Until one day I came to three-dimensional space, I found that I can directly from the square up and down to take things away, completely need to pay attention to the square when I was shocked! The original square is not so unbreakable Ah!! After listening to this story, we change a version can be changed to I am a three-dimensional creature, I think the cube is a very closed shape, such as a safe, we used to store valuables, until one day I entered the four-dimensional space and found that I can directly from a completely airtight box to take things without destroying the box ... ...... In fact, space for people's cognition, each more than one dimension, not just more than an axis so simple, but to bring an infinite number of possibilities and subversion.

To get to the next level, we use n axes to describe the coordinate system of n dimensional space, that is, the planar Cartesian coordinate system removes the plane (higher dimension) and the right angle (joins the bevel) The two constraint words, has a tall name: Cartesian coordinate system. Haha, so when you want people to think you're tall, you can say this: we're given 2 points in a Cartesian coordinate system ... The Latin name of Descartes is called Renatus · so the Cartesian coordinate system has a bigger name: the Karthi-Matthews coordinate system.

Descartes, a mathematician, philosopher and all kinds of family, he is also the father of analytic geometry. The various branches of our natural sciences were not so clear long ago, so this description is often seen, and Newton is still a theologian. How does Descartes create a Cartesian coordinate system? There is a fictional story about the legend that a long time ago, a country to build a city-Descartes city, the designer designed a map, the first use of vertical street layout, the central two streets through the center of the town to the north and eastward. The other streets are both, and each location on the map can be described by the two streets of the east and south. At the end of the day, when the designer gave the design to the architect to build it, the architect found that it was correct not to know how to use the design to build the city without writing. At last they had a meeting to discuss, the analysis of the town center in the lower left corner to see this plan is better. This is, of course, a legend, in fact, a quadrant of a planar Cartesian coordinate system can be in 8 shapes in a plane:


That is, the coordinates of the dots in 4 positions, as well as two axes (axis) of the position of a total of these 8 combinations.

In these 8 cases, the above 4 kinds, we think is the same, is the previous story, as long as we rotate this map, different directions will get the 4 cases, the following 3 can be rotated into the first one. The following 4 kinds of things can actually be the first one, and the process is to turn the paper upside down, or to look at the paper from the back, except for rotation.

That is, the two-dimensional Cartesian coordinate system can always be rotated (the paper flip can be thought to revolve around the axis, otherwise by the geometric center rotation) to get the same form.

However, 3-dimensional Cartesian coordinates do not have this feature.

In the three-dimensional Cartesian coordinate system, from the above diagram, we are divided into two coordinate systems: left-handed and right-handed coordinate system, that is, extend our left hand and right hand, the thumb, index finger, middle finger 22 vertical, and then according to the big, food, in the order corresponding to the x, Y, Z axis of the positive direction, We found that we could not, at any rate, turn the left-handed coordinate system into a right-hand coordinate by rotating these 3 fingers. (PS: In fact, we can rotate the two-dimensional coordinate system to one, with the help of the third dimension, flipping is reversed in three-dimensional space, changing the direction of the time is rotated along the z axis. So the previous story can be understood that because of our human cognition is limited, for more than 4 dimensions of space is very difficult to understand, so the left-handed coordinate system and the right-hand coordinate system to the higher dimensions can also be rotated to the 4th dimension axis to one? )

After understanding the left-handed and right-handed coordinates, we must distinguish between the different types of 3-D coordinate systems, given the current human perception. The coordinate system used in unity is a left-handed coordinate system, while the coordinate system used in modeling tools such as 3DMax is the right-handed coordinate system, which needs to be converted when necessary.

At the same time, in the left-handed and right-handed coordinate systems, some of our laws need to be determined using different hands, such as the direction of the Vector fork, the direction of the rotation vector, and the corresponding hand to be used. The specific right and left hand rules are mentioned later in this chapter.

In addition to the Cartesian coordinate system, the common coordinate system has a polar coordinate system. A polar coordinate system is a coordinate system composed of Poles , Poles, and polar diameters. Polar coordinates are used to describe curves and surfaces that are very stress-giving. We just need to know. The earth uses a polar coordinate system to describe much more than a Cartesian coordinate system. The sine curve in polar coordinates is very beautiful and is a rose line. There are some equations that can only be described in polar coordinate systems, and the patterns are beautiful.

Descartes also has a legend, that he was in his later years is the Princess Christine's teacher, the two teachers and students staged a shocking love, the king knew, the King wrath. So the king ordered the expulsion of Descartes. After Descartes was expelled, the two were very much missing each other, so Descartes often wrote to Kristen about Acacia, and Kristen wrote back to Descartes after reading it. Then the abominable King found again at this time, so the Descartes letter to intercept all, Christine Long received not Descartes letter, thought Descartes do not love him, increasingly thin. Descartes, too, was haggard and disease. When Descartes was dying, he could not help but love to write the last letter to Christine died, the contents of the letter is only a short line of mathematical equations. This is basically no one in the world to understand the love letter, the King saw after the unknown so, to see Christine's gaunt face and then think of a mathematical equation, to the letter to Christine Hope she can feel better. After Christine opened the letter tears, know that Descartes still love him, this shortest love letter at that time the world on their teachers and students can understand, the mathematical equation is:r=a (1-sintheta) .

The image of this equation can only be expressed in polar coordinate system, and its image is a love.


Readers, what are you waiting for? Is there a new skill to get when you confess?

Operation of vectors

Why put the operation of the vector in the back of the coordinate system, because the projection of this method, and the vector operations often need projection.

Vectors are equal: Two vectors are equal in size and direction.

Vector modulo: For a vector u, we only take its size, ignoring its direction, it is called modulo. Use symbols to represent the modules of U. Since vectors do not have a concept of position, we can assume that any n-dimensional vector can be a starting point on the dot of a planar coordinate system, so for any vector we can be represented by the coordinates of the end point. Therefore, the book of the Agreement points and the concept of vectors are not differentiated. For a 3-dimensional vector, the end point is P (x, Y, z), we can easily calculate the modulus according to the Pythagorean theorem.

Vector projection: For a vector u, it is projected to another vector V, the angle is theta, we play the end of U to do a perpendicular to V, also by the Pythagorean theorem to know that u in v projection size, direction is <90° and >240° and V, >90° and <240° When with V reverse

In particular, when a vector u is represented by the end point P (x, Y, z), its projection size on any vector of 3 axes is x, Y, Z.

Unit vectors: Vectors of size 1 in any direction are called unit vectors in this direction .

vector addition: vector u (end point is x1,y1,z1) and Vector V (x2,y2,z2) are added and still get a vector. Its mathematical process is. We refer to this vector as a combined vector of U and v. The synthesis and decomposition of force in physics corresponds to the addition and projection of vectors, and the addition of vectors conforms to a parallelogram rule that everyone should be familiar with.

Vector subtraction: Refers to the vector subtraction, not the first to say the negative vector (or vector inversion). Since the vector has both size and direction, and the size is a scalar, can be expressed in real numbers, so there are positive and negative. and the direction of the positive and negative two direction, we also use positive and negative to express. So a vector is reversed, and we can think of the inverse of the real number, or the direction of the reverse. After the vector u is reversed, U is the same as the U, in the opposite direction. So the vector u and v subtract, and we can think of you as the sum of you and-V.

Vector multiplication: There are three vector multiplication, namely, the number multiplication of vectors, the point multiplication of vectors and the cross multiplication of vectors.

Multiplication: A scalar k multiplied by a vector u ku,ku is still a vector.

When K>0, the KU and U are in the same direction, and vice versa;

Point multiplication: The point multiplication is also called the inner product, and the result is still a vector. U v can be decomposed into u ' modulo with V in V for multiply. Calculation method:. Since we can decompose the projection with the multiplication, the modulus after the point multiplication can be calculated as follows:.

Characteristics of the dot multiplication:


What are the benefits of these 3 properties? Let's take a look, since the calculation of the inner product only needs to multiply the coordinates of the end point, and the computational angle is rather complex, so when we just need to judge two vectors (two straight lines can also be converted to two unit vectors) angle is vertical, obtuse, acute angle, with these 3 features will be very fast. There are a lot of specific application scenarios.

Cross-multiplication: The cross-multiplication is also called the outer product, and the result is still a vector.



Given 2 vectors, when determining the method of its cross-multiplication, there is the law of the right hand (the 3-dimensional coordinate system is the coordinate system of which hands are used for gestures). If it is a left-handed coordinate system, given a and B, extend your left hand, four fingers straight toward a direction, thumb and index finger perpendicular, and then four points to the palm of the direction of bending to B, then the direction of the thumb pointing to the direction of the cross-multiply vector. Given the situation, the left hand gestures out the thumb upward. If a B is swapped, then we need to turn the hand over, that is, the thumb down. Therefore, it is known that the cross-multiplication does not satisfy the commutative law, and the direction will be reversed once the order of the forks is exchanged. We call it anti-symmetry (anti-commutative law)

Matrix

To continue tomorrow ......

(serial) Drinking coffee and learning unity--The second chapter prepares the knowledge system

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.