🔢 四元数
浮点四元数,可表示三维空间中围绕轴的旋转
🎒 示例
local new_quaternion = Quat(0.5, 0.5, 1, -1)
local rotation = new_quaterion:Rotator()
🛠 构造函数
Default Constructor
No description provided
local my_quat = Quat(X?, Y?, Z?, W?)
Parameters
| Type | Name | Default | Description |
|---|---|---|---|
| number | X | 0 | 四元数的 X 分量 |
| number | Y | X | 四元数的 Y 分量 |
| number | Z | X | 四元数的 Z 分量 |
| number | W | X | 四元数的 W 分量 |
🧽 属性
🦠 函数
信息
此结构支持 *、+、- 和 tostring 运算。
| Returns | Name | Description | |
|---|---|---|---|
Normalize | 就地归一化该四元数 | ||
| Rotator | Rotator | 获取该四元数的旋转体表示形式 | |
| Quat | Inverse | 返回该四元数的逆 | |
| Vector | RotateVector | 使用该四元数旋转一个向量 | |
| Vector | UnrotateVector | 使用该四元数反向旋转一个向量 | |
| Vector | GetForwardVector | 从该四元数中获取前向方向向量 | |
| Vector | GetRightVector | 从该四元数中获取右向方向向量 | |
| Vector | GetUpVector | 从该四元数中获取朝上方向向量 |
Normalize
就地归一化该四元数
my_quat:Normalize()
Rotator
获取该四元数的旋转体表示形式
local ret = my_quat:Rotator()
Returns
| Type | Description |
|---|---|
| Rotator | 该四元数的旋转体表示形式 |
Inverse
返回该四元数的逆
local ret = my_quat:Inverse()
Returns
| Type | Description |
|---|---|
| Quat | 该四元数的逆 |
RotateVector
使用该四元数旋转一个向量
local ret = my_quat:RotateVector(vector)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | vector | Required parameter | 要旋转的向量 |
Returns
| Type | Description |
|---|---|
| Vector | 旋转后的向量 |
UnrotateVector
使用该四元数反向旋转一个向量
local ret = my_quat:UnrotateVector(vector)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | vector | Required parameter | 要反向旋转的向量 |
Returns
| Type | Description |
|---|---|
| Vector | 反向旋转后的向量 |
GetForwardVector
从该四元数中获取前向方向向量
local ret = my_quat:GetForwardVector()
Returns
| Type | Description |
|---|---|
| Vector | 前向向量 |
GetRightVector
从该四元数中获取右向方向向量
local ret = my_quat:GetRightVector()
Returns
| Type | Description |
|---|---|
| Vector | 右向向量 |
GetUpVector
从该四元数中获取朝上方向向量
local ret = my_quat:GetUpVector()
Returns
| Type | Description |
|---|---|
| Vector | 朝上向量 |