Implementation of computer 3D graphics in Unity (Vector3, Maxtrix4 * 4, Transform)

Source: Internet
Author: User

Directly jump into the front body to recall the previous knowledge of space vector graphics in Direct3D and to study how Unity3D is represented.

Vector3, in D3D, D3DXVECTOR3 inherits from the _ D3DVECTOR struct. The _ D3DVECTOR struct contains only three single precision numbers X, Y, and Z. Used to represent vectors. Vector3 class definition in Unity3D (only useful): attributes: x, y, and z indicate a space vector. This is used to access x, y, and z data using arrays. For example, [0] [1] [2] normalized returns the value after the unitized vector (read-only ). A unit vector is a very important concept. It is often the basis of various computations. It ensures that the vector length is changed to 1 without changing the direction. The formula is as follows:

Magnitude returns the vector length value (read-only), which is really strange. It is the modulo operation of the vector to get the length of the vector. The formula is x square + y square + z square, and the root number is. I don't even remember it. Sqrmagnitude returns the square length of the vector (read-only ). The one above does not have a root number.

Directly jump into the front body to recall the previous knowledge of space vector graphics in Direct3D and to study how Unity3D is represented.

Vector3, in D3D, D3DXVECTOR3 inherits from the _ D3DVECTOR struct. The _ D3DVECTOR struct contains only three single precision numbers X, Y, and Z. Used to represent vectors. Vector3 class definition in Unity3D (only useful): attributes: x, y, and z indicate a space vector. This is used to access x, y, and z data using arrays. For example, [0] [1] [2] normalized returns the value after the unitized vector (read-only ). A unit vector is a very important concept. It is often the basis of various computations. It ensures that the vector length is changed to 1 without changing the direction. The formula is as follows:

Magnitude returns the vector length value (read-only), which is really strange. It is the modulo operation of the vector to get the length of the vector. The formula is x square + y square + z square, and the root number is. I don't even remember it. Sqrmagnitude returns the square length of the vector (read-only ). The one above does not have a root number.

Method: Scale (a: vector3, B: vector3): vertor3 scaling returns the corresponding coordinates of each coordinate of a multiplied by the corresponding coordinates of B. Note that it is a static function. Normalize () vectoring. Note that the length of the magnize vector will change to 1.

Some attributes specific to the class (directly sticking to help): zero Shorthand for writing Vector3 (0, 0, 0) one Shorthand for writing Vector3 (1, 1, 1) forward Shorthand for writing Vector3 (0, 0, 1) up Shorthand for writing Vector3 (0, 1, 0) right Shorthand for writing Vector3 (1, 0, 0)

Maxtrix4 * 4: matrix is also an important concept of 3D graphics. It is very common in D3D, but U3D seems to have been encapsulated into various objects, so it is easy to ignore it, however, it cannot be ignored. In the 3D world, each object has its own world matrix. The camera has a camera matrix, and the projection scenario has a projection matrix, various translation, rotation, and scaling operations on vertices, vectors, and objects are done through matrices. The standard 4x4 matrix of a computer 3D object is defined as follows: (indicating that the matrix braces are not displayed. The reader should treat the Left 4 rows [and the Right 4 rows] as a pair of braces) [x, y, z, 0] <-vector of the right direction of an object [x, y, z, 0] <-vector of the upper direction of an object [x, y, z, 0] <-vector of the object's Forward Direction [x, y, z, 1] <-coordinates of the object. Note: The coordinates of the first three rows must be 90 degrees mutually, (Unless in special cases, such as space distortion =. =) because they are three coordinate axes of objects. The 0 0 0 1 in the fourth column is used to complete the 4*4 matrix, which is convenient for calculation. Like a matrix, a unit matrix and a 0 matrix exist. [1 0 0] [0 1 0] I won't talk about anything else. It is completely encapsulated in Unity (see Transform) [0 0 1]

Transform: This is the matrix operation encapsulated by U3D. It is used for scaling, translation, and positioning. (This operator puts the matrix here, all objects can be stored in the transform type ). The function implemented by Transform is nothing more than the calculation of the object matrix. The details are as follows:

Variables position Vector3 type, object location, relative to the world coordinate system value. Is the value of the last row of the matrix. LocalPosition Vector3: the position of the object relative to the parent element. eulerAngles Vector3: the value of the European angle after rotation relative to the world coordinate. It is easy to understand the rotation value of the coordinate of each vector. LocalEulerAngles Vector3 type, which is relative to the Euclidean angle of the parent element. Right Vector3 type, indicating the unit vector in the direction of the X axis (Red axis in U3. Up Vector3 type, indicating the unit vector in the Y axis (green axis in U3) Direction. Forward Vector3 type, indicating the unit vector in the Z axis (blue axis in U3) Direction. Rotation Quaternion type (quatermion is a four-dimensional number, w variable more than vector3 represents the rotation angle), the world coordinate rotation .. LocalRotation Quaternion type, the degree of rotation of the local coordinate (relative to the parent element ). LocalScale Vector3 is a parent Transform type that scales relative to the local coordinate system (that is, the multiplication of the matrix) and its parent element. WorldToLocalMatrix Matrix4 * 4: converts a point from the world coordinate system to the local coordinate system. (Use a matrix after all, haha) read-only localToWorldMatrix Matrix4 * 4 type, convert a point from the local coordinate system to the world coordinate system. (Read-only) root Transform type. The Transform at the top is returned, which is the father of his father... (If any) childCount int type, the number of your child elements... LossyScale Vector3 type, scaled relative to the world coordinate system.

Functions Translate (translation: Vector3, relativeTo: Space = Space. self): void to translate objects. space can be Self and World. Needless to say, Rotate (eulerAngles: Vector3, relativeTo: Space = Space. self): void rotates the RotateAround (point: Vector3, axis: Vector3, angle: float) around the Euler's angle vector: void point rotates the angle LookAt (target: transform, worldUp: Vector3): void sets the Z axis of the object to target object TransformDirection (direction: Vector3): Vector3 converts direction from local coordinates to the world coordinate InverseTransformDirection (direction: Vector3 ): vector3 coordinates derection from the world to the local TransformPoint (position: Vector3): Vector3 likewise, InverseTransformPoint (position: Vector3): Vector3 DetachChildren (): void remove all sub-objects Find (name: string): Transform: find and return the sub-object IsChildOf (parent: Transform) by name: bool to see if it is another sub-Object

Related Article

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.