The author introduces: Jiang Xiewei, IT company technology partner, it senior lecturer, CSDN Community expert, guest editor, best seller author. National patent inventor; published books: "Hands-on teaching you architecture 3D Game Engine" electronics industry publishing house and "Unity3d actual combat core technology specific explanation" electronic industry publishing house.
CSDN Video URL: http://edu.csdn.net/lecturer/144
While learning about the unity engine or other 3D game engines. Often encountered the problem is the various coordinate space, in the previous blog has also been introduced to the reader, this blog in plain language to the reader to reveal why the need for so many coordinate space? and how to produce matrix transformations or use matrix transformations to solve this problem.
In life we often encounter the road, some people sense of direction is stronger, and some people's sense of direction is weaker, for these people to pay attention to the road, a strong sense of direction, you can tell him to go east about 300 meters. Go North 100 meters, you told him these are the axes of the Axis introduced, the direction of weak people, you can not say so. You can only say 300 meters forward, and then walk 100 meters to the left. At this point you are using the coordinate space of the pedestrian around the origin. Through this case. You can see different ways of pointing the way corresponding to our different axes.
Thus, we use different coordinate spaces in our lives under different circumstances. This is similar to the use of different spaces in the game.
Unity3d engine develops 3D games. will also face the transformation of the various coordinate space, here to the reader to popularize, so that developers do some more space to change the easy to get started. The Unity3d engine uses a model with an extension of FBX, and the model is made by the artist using the modeling tool Max to make the export, except that the model also contains pictures, such as highlights. Normals, etc., the rendering of the material can use Unity3d's own shader or write their own shader.
The model is a local space, also known as a local space, and each model has its own independent coordinate space.
When it moves or rotates. The model space will also move and rotate with it.
In a figurative analogy, when we move in the company's room, our own space is also moving, and when we turn around, our coordinate space is also trailing changes.
in the model production, the artist will give the model a coordinate, the default case is set to (0. 0,0), this coordinate is the coordinate of the parent node, and the model will have its own child node. If the object with the child's node is, for example, seen:
The coordinates of the child's node are (2,2. 0). It is the local coordinate of the sub-object, and the following will calculate its world coordinates in unity by the way of matrix transformation, and also how fast readers can use matrix transformations to obtain world coordinates in world space. The Unity3d engine uses a left-handed coordinate system, which is z-axis facing. The x-axis is facing right. The y-axis is upwards.
The effect of dragging our crafted model into the Unity editor, for example, looks like this:
Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvanh3mty3/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70 /gravity/southeast "/>
The Red Arrows represent the x-axis, and the green arrows represent the y-axis. The blue arrows represent the z-axis.
Its coordinates in the world scene are (0. 0. 0) In other words, its own local coordinates coincide with the world coordinates. Its child node is what we mentioned above, the following we will be the model for displacement, rotation, scaling to operate, we are scaling (2,2,2), rotation (0. 150. 0), Displacement (5,0,25). The performance effects in unity such as the following are seen:
We can build a model transformation matrix, here to pay attention to a problem, the order of their transformation is certain, can not be changed.
The first is scaled, rotated, and then the displacement operation is performed. The corresponding matrix transformations are seen in the following example:
Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvanh3mty3/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70 /gravity/southeast "/>
Next we model the sub-objects of the model transformation such as the following:
Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvanh3mty3/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70 /gravity/southeast "/>
Other words. In the world space, the child's position in the model is (9,4,18.0) so that we can get the child's world coordinates through the matrix transformation, in fact these basic operations are often used in game development. For example, we can use the matrix transform to achieve real-time shadow, Unity3d with the shadow because of the larger consumption, not easy in the mobile implementation, we can use matrix transformation to achieve, efficiency is improved.
The following is a continuation of the matrix implementation of observation space.
Unity3d Engine Rendering Technology Series one