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...
Vector4i
使用整數座標的 4D 向量。
說明
A 4-element structure that can be used to represent 4D grid coordinates or any other quadruplet of integers.
It uses integer coordinates and is therefore preferable to Vector4 when exact precision is required. Note that the values are limited to 32 bits, and unlike Vector4 this cannot be configured with an engine build option. Use int or PackedInt64Array if 64-bit values are needed.
Note: In a boolean context, a Vector4i will evaluate to false if it's equal to Vector4i(0, 0, 0, 0). Otherwise, a Vector4i will always evaluate to true.
屬性
|
||
|
||
|
||
|
建構子
Vector4i() |
|
方法
abs() const |
|
distance_squared_to(to: Vector4i) const |
|
distance_to(to: Vector4i) const |
|
length() const |
|
length_squared() const |
|
max_axis_index() const |
|
min_axis_index() const |
|
sign() const |
|
運算子
operator !=(right: Vector4i) |
|
operator %(right: Vector4i) |
|
operator %(right: int) |
|
operator *(right: Vector4i) |
|
operator *(right: float) |
|
operator *(right: int) |
|
operator +(right: Vector4i) |
|
operator -(right: Vector4i) |
|
operator /(right: Vector4i) |
|
operator /(right: float) |
|
operator /(right: int) |
|
operator <(right: Vector4i) |
|
operator <=(right: Vector4i) |
|
operator ==(right: Vector4i) |
|
operator >(right: Vector4i) |
|
operator >=(right: Vector4i) |
|
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 = Vector4i(0, 0, 0, 0) 🔗
零向量,所有分量都設定為 0 的向量。
ONE = Vector4i(1, 1, 1, 1) 🔗
一向量,所有分量都設定為 1 的向量。
MIN = Vector4i(-2147483648, -2147483648, -2147483648, -2147483648) 🔗
最小向量,所有分量等於 INT32_MIN 的向量。可用作 Vector4.INF 的負整數等價物。
MAX = Vector4i(2147483647, 2147483647, 2147483647, 2147483647) 🔗
最大向量,所有分量等於 INT32_MAX 的向量。可用作 Vector4.INF 的整數等價物。
屬性說明
該向量的 W 分量。也可以通過使用索引位置 [3] 存取。
向量的 X 分量。也可以通過使用索引位置 [0] 存取。
向量的 Y 分量。也可以通過使用索引位置 [1] 存取。
向量的 Z 分量。也可以通過使用索引位置 [2] 存取。
建構子說明
建構預設初始化的 Vector4i,所有分量都為 0。
Vector4i Vector4i(from: Vector4i)
建構給定 Vector4i 的副本。
Vector4i Vector4i(from: Vector4)
根據給定的 Vector4 建構 Vector4i,會將各個分量的小數部分截斷(向 0 取整)。要使用不同的行為,請考慮改為傳入 Vector4.ceil()、Vector4.floor() 或 Vector4.round() 的結果。
Vector4i Vector4i(x: int, y: int, z: int, w: int)
返回具有給定分量的 Vector4i。
方法說明
返回一個新向量,其所有分量都是絕對值,即正值。
Vector4i clamp(min: Vector4i, max: Vector4i) const 🔗
返回一個新向量,每個分量都使用 @GlobalScope.clamp() 限制在 min 和 max 之間。
Vector4i clampi(min: int, max: int) const 🔗
Returns a new vector with all components clamped between min and max, by running @GlobalScope.clamp() on each component.
int distance_squared_to(to: Vector4i) 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: Vector4i) const 🔗
Returns the Euclidean distance between this vector and to.
返回這個向量的長度,即大小。
返回這個向量的平方長度,即平方大小。
這個方法比 length() 運作得更快,所以如果你需要比較向量或需要一些公式的平方距離時,更喜歡用它。
Vector4i max(with: Vector4i) const 🔗
Returns the component-wise maximum of this and with, equivalent to Vector4i(maxi(x, with.x), maxi(y, with.y), maxi(z, with.z), maxi(w, with.w)).
返回該向量中最大值的軸。見 AXIS_* 常數。如果所有分量相等,則該方法返回 AXIS_X。
Vector4i maxi(with: int) const 🔗
Returns the component-wise maximum of this and with, equivalent to Vector4i(maxi(x, with), maxi(y, with), maxi(z, with), maxi(w, with)).
Vector4i min(with: Vector4i) const 🔗
Returns the component-wise minimum of this and with, equivalent to Vector4i(mini(x, with.x), mini(y, with.y), mini(z, with.z), mini(w, with.w)).
返回該向量中最小值的軸。見 AXIS_* 常數。如果所有分量相等,則該方法返回 AXIS_W。
Vector4i mini(with: int) const 🔗
Returns the component-wise minimum of this and with, equivalent to Vector4i(mini(x, with), mini(y, with), mini(z, with), mini(w, with)).
返回一個新的向量,如果是正數,每個分量被設定為1 ,如果是負數,-1 ,如果是零,0 。其結果與對每個分量呼叫@GlobalScope.sign()相同。
Vector4i snapped(step: Vector4i) const 🔗
返回新的向量,每個分量都吸附到了與 step 中對應分量最接近的倍數。
Vector4i snappedi(step: int) const 🔗
Returns a new vector with each component snapped to the closest multiple of step.
運算子說明
bool operator !=(right: Vector4i) 🔗
如果向量不相等,則返回 true。
Vector4i operator %(right: Vector4i) 🔗
Gets the remainder of each component of the Vector4i with the components of the given Vector4i. This operation uses truncated division, which is often not desired as it does not work well with negative numbers. Consider using @GlobalScope.posmod() instead if you want to handle negative numbers.
print(Vector4i(10, -20, 30, -40) % Vector4i(7, 8, 9, 10)) # Prints (3, -4, 3, 0)
Vector4i operator %(right: int) 🔗
Gets the remainder of each component of the Vector4i with the given int. This operation uses truncated division, which is often not desired as it does not work well with negative numbers. Consider using @GlobalScope.posmod() instead if you want to handle negative numbers.
print(Vector4i(10, -20, 30, -40) % 7) # Prints (3, -6, 2, -5)
Vector4i operator *(right: Vector4i) 🔗
Multiplies each component of the Vector4i by the components of the given Vector4i.
print(Vector4i(10, 20, 30, 40) * Vector4i(3, 4, 5, 6)) # Prints (30, 80, 150, 240)
Vector4 operator *(right: float) 🔗
Multiplies each component of the Vector4i by the given float.
Returns a Vector4 value due to floating-point operations.
print(Vector4i(10, 20, 30, 40) * 2) # Prints (20.0, 40.0, 60.0, 80.0)
Vector4i operator *(right: int) 🔗
將該 Vector4i 的每個分量乘以給定的 int。
Vector4i operator +(right: Vector4i) 🔗
Adds each component of the Vector4i by the components of the given Vector4i.
print(Vector4i(10, 20, 30, 40) + Vector4i(3, 4, 5, 6)) # Prints (13, 24, 35, 46)
Vector4i operator -(right: Vector4i) 🔗
Subtracts each component of the Vector4i by the components of the given Vector4i.
print(Vector4i(10, 20, 30, 40) - Vector4i(3, 4, 5, 6)) # Prints (7, 16, 25, 34)
Vector4i operator /(right: Vector4i) 🔗
Divides each component of the Vector4i by the components of the given Vector4i.
print(Vector4i(10, 20, 30, 40) / Vector4i(2, 5, 3, 4)) # Prints (5, 4, 10, 10)
Vector4 operator /(right: float) 🔗
Divides each component of the Vector4i by the given float.
Returns a Vector4 value due to floating-point operations.
print(Vector4i(1, 2, 3, 4) / 2.5) # Prints (0.4, 0.8, 1.2, 1.6)
Vector4i operator /(right: int) 🔗
bool operator <(right: Vector4i) 🔗
比較兩個 Vector4i 向量,首先檢查左向量的 X 值是否小於 right 向量的 X 值。如果 X 值完全相等,則用相同的方法檢查兩個向量的 Y 值、Z 值、W 值。該運算符可用於向量排序。
bool operator <=(right: Vector4i) 🔗
比較兩個 Vector4i 向量,首先檢查左向量的 X 值是否小於等於 right 向量的 X 值。如果 X 值完全相等,則用相同的方法檢查兩個向量的 Y 值、Z 值、W 值。該運算子可用於向量排序。
bool operator ==(right: Vector4i) 🔗
如果向量完全相等,則返回 true。
bool operator >(right: Vector4i) 🔗
比較兩個 Vector4i 向量,首先檢查左向量的 X 值是否大於 right 向量的 X 值。如果 X 值完全相等,則用相同的方法檢查兩個向量的 Y 值、Z 值、W 值。該運算符可用於向量排序。
bool operator >=(right: Vector4i) 🔗
比較兩個 Vector4i 向量,首先檢查左向量的 X 值是否大於等於 right 向量的 X 值。如果 X 值完全相等,則用相同的方法檢查兩個向量的 Y 值、Z 值、W 值。該運算子可用於向量排序。
使用向量分量的 index 來存取向量分量。v[0] 等價於 v.x,v[1] 等價於 v.y,v[2] 等價於 v.z,v[3] 等價於 v.w。
返回與 + 不存在時相同的值。單目 + 沒有作用,但有時可以使你的程式碼更具可讀性。
返回該 Vector4i 的負值。和寫 Vector4i(-v.x, -v.y, -v.z, -v.w) 是一樣的。這個運算會翻轉向量方向,同時保持長度不變。