# Unity Hand Tour < four >3d rotation-four yuan, Euler angle and change matrix

Source: Internet
Author: User

http://blog.csdn.net/janeky/article/details/17272625

Today we're going to talk about rotation in unity. There are three main ways of doing this. Transformation matrices, four-and Euler-angles.

Defined

• Transformation matrices

You can perform arbitrary 3d transformations (panning, rotating, zooming, trimming) and perspective transformations using homogeneous coordinates. Generally less used. A matrix4x4 matrix class is available in unity

• Four USD

The four-dollar number is the simplest super-plural. Complex numbers are composed of real numbers plus element I, where i^2 =-1. Similarly, four of dollars are composed of real numbers plus three elements I, J, K, and they are like the following relationship: i^2 = j^2 = k^2 = Ijk = 1, each four is a linear combination of 1, I, J, and K, that is, the four-tuple can generally be represented as a + bi + CJ + DK, its In A, B, C, D is a real number ". These concepts are hard to understand. Just remember that the quaternion in Unity has 4 components (X,Y,Z,W)

• Euler angle

"A set of 3 independent angular parameters used to determine the position of a fixed-point rotating rigid body, consisting of the nutation angle θ, the precession angle (i.e., the precession angle) ψ and the rotation angle J"
In unity, Quaternion.eulerangles returns the angle of rotation, rotates the euler.z angle around the z axis, rotates euler.x degrees around the x axis, rotates euler.y degrees around the y axis

Transformation

• 1. Four meta-to-transform matrix
[CSharp]View Plaincopy
1. quaternion q = quaternion.lookrotation (new Vector3 (0,0.5,1));
2. matrix4x4 rot = new matrix4x4 ();
3. Rot.    Settrs (new Vector3 (0,0,0), Q,new Vector3 (1,1,1));

• 2. Transform matrix to four-dollar number
[CSharp]View Plaincopy
1. matrix4x4 rot = new matrix4x4 ();
2. Rot.    Settrs (new Vector3 (0,0,0), Q,new Vector3 (1,1,1));
3. Vector4 vy = rot. GetColumn (1);
4. Vector4 vz = rot. GetColumn (2);
5. quaternion newq = quaternion.lookrotation (new Vector3 (VZ.X,VZ.Y,VZ.Z),new Vector3 (vy.x,vy.y,vy.z));

Common functions
function Toangleaxis (out angle:float, out Axis:vector3): void
Rotate the angle around the axis axis to create a rotation

static function Angle (A:quaternion, b:quaternion): float
Returns the angle between A and B.

var Eulerangles:vector3
Returns the Euler angle that represents the rotation. Represents the angle of rotation, rotates euler.z degrees around the z axis, rotates euler.x degrees around the x-axis, rotates euler.y degrees around the y-axis (in this order).

function Setfromtorotation (Fromdirection:vector3, Todirection:vector3): void
Rotate the fromdirection of the object to the Todirection

function Setlookrotation (View:vector3, Up:vector3 = vector3.up): void
Create a rotation to move the z axis toward the view Y axis up

static function Slerp (From:quaternion, To:quaternion, t:float): quaternion
From the from range to the to, the moving distance is T

static function Lerp (A:quaternion, B:quaternion, t:float): quaternion
Similar to Slerp, and faster than slerp. But if the rotation angle is far apart, it will look bad.

Comparison

• Transformation matrices

Can do a variety of complex transformations, but the learning curve is relatively large, using more memory, because the amount of data stored is larger.

• Euler angle

Simple to understand, especially for art and planning colleagues. Operation speed and memory consumption are relatively small. There may be a universal lock problem (two axes of rotation coincident)

• Four USD

Avoid the problem of universal lock. Not so straightforward to understand.
Have any questions welcome to explore [email protected]

Unity Hand Tour < four >3d rotation-four yuan, Euler angle and change matrix

Related Keywords:

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.