Unity3D Basics - Let’s talk about the three-dimensional world and the commonly used coordinate systems in Unity3D

Recently I was watchingUnity's rotation transformation. As I looked at it, I realized that there were some basic knowledge in it that I still didn't fully understand, so In order to clear the obstacles, I jumped into the study of basic knowledge (I was also drunk. Every time I read something, I would not let go if I saw something I didn’t understand, and ended up going astray). Without further ado, let’s learn next. Next3DA basic knowledge point in mathematics - the coordinate system.

1.Cartesian coordinate system

Generally speaking, the Cartesian coordinate system refers to the Cartesian coordinate system without special instructions, but the Cartesian coordinate system is a special case of the Cartesian coordinate system.

Definition:1.Each2DDescartes Each coordinate system has a special point, which is the origin (0,0), which is the center of the coordinate system.

            2.Every2D Cartesian coordinate system has two straight lines passing through the origin. Both sides extend infinitely, called axes, and the two axes are perpendicular to each other

Cartesian coordinate system positioning:A coordinate system is a framework for precisely positioning points. To locate points in the Cartesian coordinate system, the concept of Cartesian coordinates is introduced. In the 2D plane, two numbers (x, y) are A point can be defined. sitEach component of the object indicates the distance and orientation between the point and the origin, and each component is the signed distance of the corresponding axis. Signed distance means that the distance is positive in one direction and negative in the opposite direction.

2. 3D coordinate system

The 3D coordinate system represents a three-dimensional space system. 3D The coordinate system has three axes. /span>3 coordinate system, the point position requires 3D The axes are perpendicular to each other, that is, each axis is perpendicular to the other two axes. In the 3 axis,ZThe coordinate system has one more2D 数:xyz

Left-hand coordinate system, right-hand coordinate system:

3D There are two completely different coordinate systems, the left-handed coordinate system and the right-handed coordinate system. If they belong to the same coordinate system, they can be coincident through rotation, otherwise they cannot be coincident. There is no good or bad between the two coordinate systems, onlyIt is applied to different scenarios. Left-handed coordinate systems are used in computers, and right-handed coordinate systems are used in linear algebra.

3.Multiple coordinate systems:

 Why use multiple coordinate systems? Because it is more convenient to use different coordinate systems in different situations. Certain information is only available in specific contexts. Here are some commonly used coordinate systems:

1. World coordinate system

It is a special coordinate system that establishes the reference frame needed to describe other coordinate systems. On the other hand, the time coordinate system can be used to describe the position of other coordinate systems, but a larger coordinate system cannot be used.Describe the world  Boundary coordinate system.

2. Object coordinate system

The coordinate system associated with a specific object. When an object moves or changes direction, the coordinate system associated with the object also moves and changes direction. For example, telling you "take a step forward" means sending a message to your object coordinate system. instructions. Concepts such as "front, back, left, and right" are meaningful only in the object coordinate system. "Turn left" is the object coordinate system, and "turn east" is the world coordinate system. Sometimes the object coordinate system is also called the model coordinate system. The model The coordinates of the vertices are described in the model coordinate system.

3.Camera coordinate system

The observer is closely related to the coordinate system. The camera coordinate system is regarded as a special object coordinate system that defines the camera's screen viewable area. In the camera coordinate system, the camera is in the original point, x-axis to the right, z axis forward, y< a i=4>axis upward. Axis conventions regarding camera coordinate systems may differ. In many graphics books, it is customary to use a right-handed coordinate system, with the zz axis pointing outward, that is, pointing from the screen to the reader. 2DscreenThe content displayed on the screen is3D The camera coordinate system is presented through projection conversion.

4.Inertial coordinate system

In order to simplify the conversion between the world coordinate system and the object coordinate system, the inertial coordinate system is created. The origin of the inertial coordinate system coincides with the origin of the object coordinate system, but the axis of the inertial coordinate system is parallel to the world coordinate system axis. Therefore, the conversion from the object coordinate system to the inertial coordinate system only requires rotation, and from the inertial coordinate system to the world coordinate system only requires translation.

5. Nested coordinate system

Each object in the 3D virtual world has its own coordinate system—its own origin and coordinate axis. Each model has its own origin and coordinate axis, and the child objects of the model are in this nested coordinate system.

Conversion from object coordinate system to world coordinate system:

1. Rotate the object coordinate system to the inertial coordinate system. Rotate the object coordinate system to coincide with the inertial coordinate system.

2. Move the origin of the inertial coordinate system to the world coordinate system

4. Introduction to some commonly used coordinate systems in Unity

First of all, Unity is a left-handed coordinate system. Commonly used coordinate systems are:

1. World coordinate system

We add objects to the scene, and they are displayed in the scene in world coordinates. Transform.position can obtain the position coordinates.

2.Screen coordinate system

is defined in pixels, with the lower left corner of the screen as (0,0) and the upper right corner as ( Screen.width,Screen.height), Z’s position is in the world unit of the camera to measure. Note: The mouse position coordinates belong to the screen coordinates. Input.mousePosition can be used to obtain the position coordinates. The finger touching the screen is also the screen coordinates. Input.GetTouch(0).positionYou can get the coordinates of a single finger touching the screen.

3. System GUI Interface system

This coordinate system is similar to the screen coordinate system, except that the upper left corner of the screen is the point (0,0) , the lower right corner is (Screen.width, Screen.height).

4. Viewport coordinate system:

Viewport coordinates are standard relative to the camera. The lower left corner of the camera is (0,0), and the upper right corner is (1,1 The position of the ) point, Z, is measured in the camera's world units.

World coordinates—Screen coordinates:camera.WorldToScreenPoint(transform.position); object in the scene. camera is the cameraThis converts world coordinates to screen coordinates. Among them,

Screen coordinates—Viewport coordinates:camera.ScreenToViewportPoint(Input.GetTouch(0). position);This converts screen coordinates to viewport coordinates. Among them, camera is the camera object in the scene.

ViewportToScreenPoint—Screen screencamera.ViewportToScreenPoint();

Viewport coordinates—World coordinates:camera.ViewportToWorldPOint();



Guess you like

Origin blog.csdn.net/u014086857/article/details/54708188