找回密码
 立即注册
查看: 136|回复: 0

Unity中的旋转

[复制链接]
发表于 2023-1-11 16:57 | 显示全部楼层 |阅读模式
坐标系

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(-
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-5-18 20:35 , Processed in 0.088457 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表