🧭 旋转体
旋转信息(俯仰角、偏航角、横滚角)的容器。所有旋转值均以度为单位存储。
信息
旋转体在内部进行自动压缩,这可以将其在网络中的大小减少高达 90%。 它们的组件通常每个都被压缩成 1 字节(某些例外情况需要更高的精度)。
🎒 示例
local new_rotator = Rotator(-90, 153, 24.5)
🛠 构造函数
Default Constructor
No description provided
local my_rotator = Rotator(pitch?, yaw?, roll?)
🧽 属性
| Type | Name | Description |
|---|---|---|
| number | Pitch | 绕右轴(绕 Y 轴)旋转,即抬头和低头(0=直视前方,正值为抬头,负值为低头) |
| number | Yaw | 绕上轴(绕 Z 轴)旋转,即绕圈转动,0=东,正值为北,负值为南。 |
| number | Roll | 绕前轴(绕 X 轴)旋转,即歪头,0=端正,正值为顺时针,负值为逆时针。 |
🦠 函数
信息
此结构支持 +、-、* 和 tostring 运算。
| Returns | Name | Description | |
|---|---|---|---|
| Vector | GetForwardVector | 在世界空间中,获取此组件的前向(X)单位方向向量。 | |
| Vector | GetRightVector | 在世界空间中,获取此组件的右向(Y)单位方向向量。 | |
| Vector | GetUpVector | 在世界空间中,获取此组件的上向(Z)单位方向向量。 | |
| Vector | RotateVector | 通过该旋转体旋转一个向量。 | |
Normalize | 就地归一化,移除所有绕圈圈数并计算出“最短路径”的旋转。 | ||
| Vector | UnrotateVector | 返回通过该旋转体的逆矩阵旋转后的向量。 | |
| Quat | Quaternion | 将旋转作为四元数获取。 | |
| Rotator | GetNormalized | 返回一个归一化后的新旋转体。 | |
| boolean | IsNearlyZero | 检查旋转体在指定的容差范围内是否接近于零 | |
| boolean | IsZero | 检查旋转体的所有组件是否严格为零 |
GetForwardVector
在世界空间中,获取此组件的前向(X)单位方向向量。
local ret = my_rotator:GetForwardVector()
Returns
| Type | Description |
|---|---|
| Vector | 前向方向 |
GetRightVector
在世界空间中,获取此组件的右向(Y)单位方向向量。
local ret = my_rotator:GetRightVector()
Returns
| Type | Description |
|---|---|
| Vector | 右向方向 |
GetUpVector
在世界空间中,获取此组件的上向(Z)单位方向向量。
local ret = my_rotator:GetUpVector()
Returns
| Type | Description |
|---|---|
| Vector | 上向方向 |
RotateVector
通过该旋转体旋转一个向量。
local ret = my_rotator:RotateVector(vector)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | vector | Required parameter | 要被该旋转体旋转的向量 |
Returns
| Type | Description |
|---|---|
| Vector | 旋转后的向量 |
Normalize
就地归一化,移除所有绕圈圈数并计算出“最短路径”的旋转。
my_rotator:Normalize()
UnrotateVector
返回通过该旋转体的逆矩阵旋转后的向量。
local ret = my_rotator:UnrotateVector(vector)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | vector | Required parameter | 要被该旋转体逆矩阵旋转的向量 |
Returns
| Type | Description |
|---|---|
| Vector | 逆旋转后的向量 |
Quaternion
将旋转作为四元数获取。
local ret = my_rotator:Quaternion()
Returns
| Type | Description |
|---|---|
| Quat | 作为四元数的旋转 |
GetNormalized
返回一个归一化后的新旋转体。
local ret = my_rotator:GetNormalized()
Returns
| Type | Description |
|---|---|
| Rotator | 归一化后的旋转体 |
IsNearlyZero
检查旋转体在指定的容差范围内是否接近于零
local ret = my_rotator:IsNearlyZero(tolerance?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| number | tolerance? | 0.000001 | 要检查的容差 |
Returns
| Type | Description |
|---|---|
| boolean | 旋转体是否接近于零 |
IsZero
检查旋转体的所有组件是否严格为零
local ret = my_rotator:IsZero()
Returns
| Type | Description |
|---|---|
| boolean | 旋转体是否严格为零 |
🗿 静态函数
Random
生成一个随机旋转,可选择是否包含随机横滚角
local ret = Rotator.Random(roll?, min?, max?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| boolean | roll? | false | 是否在旋转体中使用随机横滚角,否则横滚角使用 0 |
| float | min? | -180 | 最小值 |
| float | max? | 180 | 最大值 |
Returns
| Type | Description |
|---|---|
| Rotator | 随机旋转结果 |