Unity中的旋转
坐标系Unity采用左手坐标系(正向角度为顺时针方向,右手系正向角度为逆时针方向)
x轴旋转\theta,旋转矩阵为
R_x(\theta) = \begin{bmatrix}1 & 0 & 0 \\0 & \cos \theta & \sin \theta \\0 & -\sin \theta & \cos \theta \end{bmatrix}
y轴旋转 \alpha ,旋转矩阵为
R_y(\alpha ) = \begin{bmatrix}\cos \alpha & 0 & -\sin \alpha \\0 & 1 & 0 \\\sin \alpha & 0 & \cos \alpha \end{bmatrix}
z轴旋转 \beta ,旋转矩阵为
R_z(\beta) = \begin{bmatrix} \cos \beta & \sin \beta & 0 \\-\sin \beta & \cos \beta & 0 \\ 0 & 0 & 1 \end{bmatrix}
顺归
unity中旋转顺归是:Z,X,Y 顺序。
In Unity these rotations are performed around the Z axis, the X axis, and the Y axis, in that order.
using UnityEngine;
public class Test : MonoBehaviour
{
public GameObject actor;
// Update is called once per frame
void Update()
{
var angle = actor.transform.rotation.eulerAngles;
var a = angle.z * Mathf.Deg2Rad;
var c = Mathf.Cos(a);
var s = Mathf.Sin(a);
var rZ = new Matrix4x4(
new Vector4(c,s, 0, 0),
new Vector4(-
页:
[1]