Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
Vector4
A 4D vector using floating-point coordinates.
說明
包含四個元素的結構體,可用於代表 4D 座標或任何數值的四元組。
使用浮點數座標。預設情況下,這些浮點值為 32 位精度,與始終為 64 位的 float 並不相同。如果需要雙精度,請在編譯引擎時使用 precision=double 選項。
對應的整數版本見 Vector4i。
注意:在布林語境中,如果 Vector4 等於 Vector4(0, 0, 0, 0) 則求值結果為 false。否則 Vector4 的求值結果始終為 true。
屬性
|
||
|
||
|
||
|
建構子
Vector4() |
|
方法
abs() const |
|
ceil() const |
|
cubic_interpolate(b: Vector4, pre_a: Vector4, post_b: Vector4, weight: float) const |
|
cubic_interpolate_in_time(b: Vector4, pre_a: Vector4, post_b: Vector4, weight: float, b_t: float, pre_a_t: float, post_b_t: float) const |
|
direction_to(to: Vector4) const |
|
distance_squared_to(to: Vector4) const |
|
distance_to(to: Vector4) const |
|
floor() const |
|
inverse() const |
|
is_equal_approx(to: Vector4) const |
|
is_finite() const |
|
is_normalized() const |
|
is_zero_approx() const |
|
length() const |
|
length_squared() const |
|
max_axis_index() const |
|
min_axis_index() const |
|
normalized() const |
|
round() const |
|
sign() const |
|
運算子
operator !=(right: Vector4) |
|
operator *(right: Projection) |
|
operator *(right: Vector4) |
|
operator *(right: float) |
|
operator *(right: int) |
|
operator +(right: Vector4) |
|
operator -(right: Vector4) |
|
operator /(right: Vector4) |
|
operator /(right: float) |
|
operator /(right: int) |
|
operator <(right: Vector4) |
|
operator <=(right: Vector4) |
|
operator ==(right: Vector4) |
|
operator >(right: Vector4) |
|
operator >=(right: Vector4) |
|
operator [](index: int) |
|
列舉
enum Axis: 🔗
Axis AXIS_X = 0
X 軸的列舉值。由 max_axis_index() 和 min_axis_index() 返回。
Axis AXIS_Y = 1
Y 軸的列舉值。由 max_axis_index() 和 min_axis_index() 返回。
Axis AXIS_Z = 2
Z 軸的列舉值。由 max_axis_index() 和 min_axis_index() 返回。
Axis AXIS_W = 3
W 軸的列舉值。由 max_axis_index() 和 min_axis_index() 返回。
常數
ZERO = Vector4(0, 0, 0, 0) 🔗
零向量,所有分量都設定為 0 的向量。
ONE = Vector4(1, 1, 1, 1) 🔗
一向量,所有分量都設定為 1 的向量。
INF = Vector4(inf, inf, inf, inf) 🔗
無窮大向量,所有分量都設定為 @GDScript.INF 的向量。
屬性說明
該向量的 W 分量。也可以通過使用索引位置 [3] 存取。
向量的 X 分量。也可以通過使用索引位置 [0] 存取。
向量的 Y 分量。也可以通過使用索引位置 [1] 存取。
向量的 Z 分量。也可以通過使用索引位置 [2] 存取。
建構子說明
建構預設初始化的 Vector4,所有分量都為 0。
Vector4 Vector4(from: Vector4)
建構給定 Vector4 的副本。
Vector4 Vector4(from: Vector4i)
從給定的 Vector4i 建構新的 Vector4。
Vector4 Vector4(x: float, y: float, z: float, w: float)
返回具有給定分量的 Vector4。
方法說明
返回一個新向量,其所有分量都是絕對值,即正值。
返回一個新向量,所有的分量都是向上四捨五入(正無窮大方向)。
Vector4 clamp(min: Vector4, max: Vector4) const 🔗
返回一個新向量,每個分量都使用 @GlobalScope.clamp() 限制在 min 和 max 之間。
Vector4 clampf(min: float, max: float) const 🔗
Returns a new vector with all components clamped between min and max, by running @GlobalScope.clamp() on each component.
Vector4 cubic_interpolate(b: Vector4, pre_a: Vector4, post_b: Vector4, weight: float) const 🔗
返回該向量和 b 之間進行三次插值 weight 處的結果,使用 pre_a 和 post_b 作為控制柄。weight 在 0.0 到 1.0 的範圍內,代表插值的量。
Vector4 cubic_interpolate_in_time(b: Vector4, pre_a: Vector4, post_b: Vector4, weight: float, b_t: float, pre_a_t: float, post_b_t: float) const 🔗
Performs a cubic interpolation between this vector and b using pre_a and post_b as handles, and returns the result at position weight. weight is on the range of 0.0 to 1.0, representing the amount of interpolation.
It can perform smoother interpolation than cubic_interpolate() by the time values.
Vector4 direction_to(to: Vector4) const 🔗
返回從該向量指向 to 的正規化向量。相當於使用 (b - a).normalized()。
float distance_squared_to(to: Vector4) const 🔗
Returns the squared Euclidean distance between this vector and to.
This method runs faster than distance_to(), so prefer it if you need to compare vectors or need the squared distance for some formula.
float distance_to(to: Vector4) const 🔗
Returns the Euclidean distance between this vector and to.
float dot(with: Vector4) const 🔗
返回該向量與 with 的點積。
返回一個新的向量,所有的向量都被四捨五入,向負無窮大。
返回該向量的逆向量。與 Vector4(1.0 / v.x, 1.0 / v.y, 1.0 / v.z, 1.0 / v.w) 相同。
bool is_equal_approx(to: Vector4) const 🔗
如果這個向量與 to 大致相等,則返回 true,判斷方法是對每個分量執行 @GlobalScope.is_equal_approx()。
如果該向量無窮,則返回 true,判斷方法是對每個分量呼叫 @GlobalScope.is_finite()。
如果該向量是正規化的,即長度約等於 1,則返回 true。
如果該向量的值大約為零,則返回 true,判斷方法是對每個分量運作 @GlobalScope.is_zero_approx()。
該方法比使用 is_equal_approx() 和零向量比較要快。
返回這個向量的長度,即大小。
float length_squared() const 🔗
返回這個向量的平方長度,即平方大小。
這個方法比 length() 運作得更快,所以如果你需要比較向量或需要一些公式的平方距離時,更喜歡用它。
Vector4 lerp(to: Vector4, weight: float) const 🔗
返回此向量和 to 之間,按數量 weight 線性插值結果。weight 在 0.0 到 1.0 的範圍內,代表插值的量。
Vector4 max(with: Vector4) const 🔗
Returns the component-wise maximum of this and with, equivalent to Vector4(maxf(x, with.x), maxf(y, with.y), maxf(z, with.z), maxf(w, with.w)).
返回該向量中最大值的軸。見 AXIS_* 常數。如果所有分量相等,則該方法返回 AXIS_X。
Vector4 maxf(with: float) const 🔗
Returns the component-wise maximum of this and with, equivalent to Vector4(maxf(x, with), maxf(y, with), maxf(z, with), maxf(w, with)).
Vector4 min(with: Vector4) const 🔗
Returns the component-wise minimum of this and with, equivalent to Vector4(minf(x, with.x), minf(y, with.y), minf(z, with.z), minf(w, with.w)).
返回該向量中最小值的軸。見 AXIS_* 常數。如果所有分量相等,則該方法返回 AXIS_W。
Vector4 minf(with: float) const 🔗
Returns the component-wise minimum of this and with, equivalent to Vector4(minf(x, with), minf(y, with), minf(z, with), minf(w, with)).
Returns the result of scaling the vector to unit length. Equivalent to v / v.length(). Returns (0, 0, 0, 0) if v.length() == 0. See also is_normalized().
Note: This function may return incorrect values if the input vector length is near zero.
Vector4 posmod(mod: float) const 🔗
返回由該向量的分量與 mod 執行 @GlobalScope.fposmod() 運算後組成的向量。
Vector4 posmodv(modv: Vector4) const 🔗
返回由該向量的分量與 modv 的分量執行 @GlobalScope.fposmod() 運算後組成的向量。
返回所有分量都被四捨五入為最接近的整數的向量,中間情況向遠離零的方向四捨五入。
返回新的向量,分量如果為正則設為 1.0,如果為負則設為 -1.0,如果為零則設為 0.0。結果與對每個分量呼叫 @GlobalScope.sign() 一致。
Vector4 snapped(step: Vector4) const 🔗
返回新的向量,每個分量都吸附到了與 step 中對應分量最接近的倍數。也可以用於將分量四捨五入至小數點後的任意位置。
Vector4 snappedf(step: float) const 🔗
Returns a new vector with each component snapped to the nearest multiple of step. This can also be used to round the components to an arbitrary number of decimals.
運算子說明
bool operator !=(right: Vector4) 🔗
如果向量不相等,則返回 true。
注意:由於浮點數精度誤差,請考慮改用 is_equal_approx(),會更可靠。
注意:包含 @GDScript.NAN 元素的向量的行為與其他向量不同。因此,如果包含 NaN,則這個方法的結果可能不準確。
Vector4 operator *(right: Projection) 🔗
Transforms (multiplies) the Vector4 by the transpose of the given Projection matrix.
For transforming by inverse of a projection projection.inverse() * vector can be used instead. See Projection.inverse().
Vector4 operator *(right: Vector4) 🔗
Multiplies each component of the Vector4 by the components of the given Vector4.
print(Vector4(10, 20, 30, 40) * Vector4(3, 4, 5, 6)) # Prints (30.0, 80.0, 150.0, 240.0)
Vector4 operator *(right: float) 🔗
Multiplies each component of the Vector4 by the given float.
print(Vector4(10, 20, 30, 40) * 2) # Prints (20.0, 40.0, 60.0, 80.0)
Vector4 operator *(right: int) 🔗
將該 Vector4 的每個分量乘以給定的 int。
Vector4 operator +(right: Vector4) 🔗
Adds each component of the Vector4 by the components of the given Vector4.
print(Vector4(10, 20, 30, 40) + Vector4(3, 4, 5, 6)) # Prints (13.0, 24.0, 35.0, 46.0)
Vector4 operator -(right: Vector4) 🔗
Subtracts each component of the Vector4 by the components of the given Vector4.
print(Vector4(10, 20, 30, 40) - Vector4(3, 4, 5, 6)) # Prints (7.0, 16.0, 25.0, 34.0)
Vector4 operator /(right: Vector4) 🔗
Divides each component of the Vector4 by the components of the given Vector4.
print(Vector4(10, 20, 30, 40) / Vector4(2, 5, 3, 4)) # Prints (5.0, 4.0, 10.0, 10.0)
Vector4 operator /(right: float) 🔗
Divides each component of the Vector4 by the given float.
print(Vector4(10, 20, 30, 40) / 2) # Prints (5.0, 10.0, 15.0, 20.0)
Vector4 operator /(right: int) 🔗
將該 Vector4 的每個分量除以給定的 int。
bool operator <(right: Vector4) 🔗
比較兩個 Vector4 向量,首先檢查左向量的 X 值是否小於 right 向量的 X 值。如果 X 值完全相等,則用相同的方法檢查兩個向量的 Y 值、Z 值、W 值。該運算符可用於向量排序。
注意:包含 @GDScript.NAN 元素的向量的行為與其他向量不同。因此,如果包含 NaN,則這個方法的結果可能不準確。
bool operator <=(right: Vector4) 🔗
比較兩個 Vector4 向量,首先檢查左向量的 X 值是否小於等於 right 向量的 X 值。如果 X 值完全相等,則用相同的方法檢查兩個向量的 Y 值、Z 值、W 值。該運算子可用於向量排序。
注意:包含 @GDScript.NAN 元素的向量的行為與其他向量不同。因此,如果包含 NaN,則這個方法的結果可能不準確。
bool operator ==(right: Vector4) 🔗
如果向量完全相等,則返回 true。
注意:由於浮點數精度誤差,請考慮改用 is_equal_approx(),會更可靠。
注意:包含 @GDScript.NAN 元素的向量的行為與其他向量不同。因此,如果包含 NaN,則這個方法的結果可能不準確。
bool operator >(right: Vector4) 🔗
比較兩個 Vector4 向量,首先檢查左向量的 X 值是否大於 right 向量的 X 值。如果 X 值完全相等,則用相同的方法檢查兩個向量的 Y 值、Z 值、W 值。該運算符可用於向量排序。
注意:包含 @GDScript.NAN 元素的向量的行為與其他向量不同。因此,如果包含 NaN,則這個方法的結果可能不準確。
bool operator >=(right: Vector4) 🔗
比較兩個 Vector4 向量,首先檢查左向量的 X 值是否大於等於 right 向量的 X 值。如果 X 值完全相等,則用相同的方法檢查兩個向量的 Y 值、Z 值、W 值。該運算子可用於向量排序。
注意:包含 @GDScript.NAN 元素的向量的行為與其他向量不同。因此,如果包含 NaN,則這個方法的結果可能不準確。
float operator [](index: int) 🔗
使用向量分量的 index 來存取向量分量。v[0] 等價於 v.x,v[1] 等價於 v.y,v[2] 等價於 v.z,v[3] 等價於 v.w。
返回與 + 不存在時相同的值。單目 + 沒有作用,但有時可以使你的程式碼更具可讀性。
返回該 Vector4 的負值。和寫 Vector4(-v.x, -v.y, -v.z, -v.w) 是一樣的。該操作在保持相同幅度的同時,翻轉向量的方向。對於浮點數,零也有正負兩種。