UNITY 5.2 Quaternion 类

四元数其形式为 w + x i + y j + z k,其中i、j、k的關係如下:
i2 = j2 = k2 = -1
i * j = k = -j * i
j * k = i = -k * j
k * i = j = -i * k
还可以表示为:q = [w, x, y, z] = [S, V]
定义四元数q = w + x i + y j +z k 的norm为:
N(q) = |q| = x^2 + y^2 + z^2 + w^2 = w^2 + v^2
若令q = [S, V] = [cosθ, u*sinθ],其中u为单位向量,而令q'= [S', V']为一四元数,则经过倒证,可以得出q * q' * q^(-1)会使得q'绕著u轴旋转2θ。


static 变量:

public static Quaternion identity { get; }
只是一个 Quaternion 对象的定义。没有旋转值。v = (0,0,0) w = 1


static 方法:

public static float Angle(Quaternion a, Quaternion b);
返回两个旋转之间的角度
public static Quaternion AngleAxis(float angle, Vector3 axis);
通过角度和旋转轴创建一个四元数
public static float Dot(Quaternion a, Quaternion b);
返回两个四元数的点乘
public static Quaternion Euler(Vector3 euler);
通过一个欧拉角转换获取四元数
public static Quaternion FromToRotation(Vector3 fromDirection, Vector3 toDirection);
通过起始向量和终止向量获取一个四元数。
public static Quaternion Inverse(Quaternion rotation);
获取四元素的反向四元数
public static Quaternion Lerp(Quaternion a, Quaternion b, float t);
public static Quaternion LerpUnclamped(Quaternion a, Quaternion b, float t);
public static Quaternion Slerp(Quaternion a, Quaternion b, float t);
public static Quaternion SlerpUnclamped(Quaternion a, Quaternion b, float t);
从 a 到 b 转换的插值。
public static Quaternion LookRotation(Vector3 forward);
public static Quaternion LookRotation(Vector3 forward, Vector3 upwards);
通过指定向前和向上向量,获取一个旋转。有一个默认坐标系做参考。
public static Quaternion RotateTowards(Quaternion from, Quaternion to, float maxDegreesDelta);
获取一个四元数,从 from 到 to,最大度数为 maxDegreesDelta


构造函数:

public Quaternion(float x, float y, float z, float w);


public 变量:

public Vector3 eulerAngles { get; set; }
返回当前四元数的欧拉角
public float this[int index] { get; set; }
通过索引存取四元数中的元素  x, y, z, w =>  [0], [1], [2], [3]


public 函数:

public void Set(float new_x, float new_y, float new_z, float new_w);
设置四元数的新值
public void SetFromToRotation(Vector3 fromDirection, Vector3 toDirection);
设置四元数从向量转动到的向量
public void SetLookRotation(Vector3 view);
public void SetLookRotation(Vector3 view, Vector3 up);
设置四元数的朝向向量和向上向量。
public void ToAngleAxis(out float angle, out Vector3 axis);
返回四元数相对于某个轴的转动角度。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值