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...
Vector3i
使用整數座標的 3D 向量。
說明
包含三個元素的結構體,可用於代表 3D 座標或任何整數的三元組。
使用整數座標,因此需要絕對精確時應比 Vector3 優先使用。請注意,取值範圍有 32 位的限制,與 Vector3 不同,這個型別的精度無法使用引擎的建構參數進行配置。如果需要 64 位元的值,請使用 int 或 PackedInt64Array。
注意:在布林語境中,如果 Vector3i 等於 Vector3i(0, 0, 0) 則求值結果為 false。否則 Vector3i 的求值結果始終為 true。
教學
屬性
|
||
|
||
|
建構子
Vector3i() |
|
方法
abs() const |
|
distance_squared_to(to: Vector3i) const |
|
distance_to(to: Vector3i) const |
|
length() const |
|
length_squared() const |
|
max_axis_index() const |
|
min_axis_index() const |
|
sign() const |
|
運算子
operator !=(right: Vector3i) |
|
operator %(right: Vector3i) |
|
operator %(right: int) |
|
operator *(right: Vector3i) |
|
operator *(right: float) |
|
operator *(right: int) |
|
operator +(right: Vector3i) |
|
operator -(right: Vector3i) |
|
operator /(right: Vector3i) |
|
operator /(right: float) |
|
operator /(right: int) |
|
operator <(right: Vector3i) |
|
operator <=(right: Vector3i) |
|
operator ==(right: Vector3i) |
|
operator >(right: Vector3i) |
|
operator >=(right: Vector3i) |
|
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() 返回。
常數
ZERO = Vector3i(0, 0, 0) 🔗
零向量,所有分量都設定為 0 的向量。
ONE = Vector3i(1, 1, 1) 🔗
一向量,所有分量都設定為 1 的向量。
MIN = Vector3i(-2147483648, -2147483648, -2147483648) 🔗
最小向量,所有分量等於 INT32_MIN 的向量。可用作 Vector3.INF 的負整數等價物。
MAX = Vector3i(2147483647, 2147483647, 2147483647) 🔗
最大向量,所有分量等於 INT32_MAX 的向量。可用作 Vector3.INF 的整數等價物。
LEFT = Vector3i(-1, 0, 0) 🔗
左單位向量。代表局部的左方向,全域的西方向。
RIGHT = Vector3i(1, 0, 0) 🔗
右單位向量。代表局部的右方向,全域的東方向。
UP = Vector3i(0, 1, 0) 🔗
上單位向量。
DOWN = Vector3i(0, -1, 0) 🔗
下單位向量。
FORWARD = Vector3i(0, 0, -1) 🔗
前單位向量。代表局部的前方向,全域的北方向。
BACK = Vector3i(0, 0, 1) 🔗
向後的單位向量。代表局部的後方,全域的南方。
屬性說明
向量的 X 分量。也可以通過使用索引位置 [0] 存取。
向量的 Y 分量。也可以通過使用索引位置 [1] 存取。
向量的 Z 分量。也可以通過使用索引位置 [2] 存取。
建構子說明
建構預設初始化的 Vector3i,所有分量都為 0。
Vector3i Vector3i(from: Vector3i)
建構給定 Vector3i 的副本。
Vector3i Vector3i(from: Vector3)
根據給定的 Vector3 建構 Vector3i,會將各個分量的小數部分截斷(向 0 取整)。要使用不同的行為,請考慮改為傳入 Vector3.ceil()、Vector3.floor() 或 Vector3.round() 的結果。
Vector3i Vector3i(x: int, y: int, z: int)
返回具有給定分量的 Vector3i。
方法說明
返回一個新向量,其所有分量都是絕對值,即正值。
Vector3i clamp(min: Vector3i, max: Vector3i) const 🔗
返回一個新向量,每個分量都使用 @GlobalScope.clamp() 限制在 min 和 max 之間。
Vector3i 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: Vector3i) 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: Vector3i) const 🔗
Returns the Euclidean distance between this vector and to.
返回這個向量的長度,即大小。
返回這個向量的平方長度,即平方大小。
這個方法比 length() 運作得更快,所以如果你需要比較向量或需要一些公式的平方距離時,更喜歡用它。
Vector3i max(with: Vector3i) const 🔗
Returns the component-wise maximum of this and with, equivalent to Vector3i(maxi(x, with.x), maxi(y, with.y), maxi(z, with.z)).
返回該向量中最大值的軸。見 AXIS_* 常數。如果所有分量相等,則該方法返回 AXIS_X。
Vector3i maxi(with: int) const 🔗
Returns the component-wise maximum of this and with, equivalent to Vector3i(maxi(x, with), maxi(y, with), maxi(z, with)).
Vector3i min(with: Vector3i) const 🔗
Returns the component-wise minimum of this and with, equivalent to Vector3i(mini(x, with.x), mini(y, with.y), mini(z, with.z)).
返回該向量中最小值的軸。見 AXIS_* 常數。如果所有分量相等,則該方法返回 AXIS_Z。
Vector3i mini(with: int) const 🔗
Returns the component-wise minimum of this and with, equivalent to Vector3i(mini(x, with), mini(y, with), mini(z, with)).
返回一個新的向量,如果是正數,每個分量被設定為1 ,如果是負數,-1 ,如果是零,0 。其結果與對每個分量呼叫@GlobalScope.sign()相同。
Vector3i snapped(step: Vector3i) const 🔗
返回新的向量,每個分量都吸附到了與 step 中對應分量最接近的倍數。
Vector3i snappedi(step: int) const 🔗
Returns a new vector with each component snapped to the closest multiple of step.
運算子說明
bool operator !=(right: Vector3i) 🔗
如果向量不相等,則返回 true。
Vector3i operator %(right: Vector3i) 🔗
Gets the remainder of each component of the Vector3i with the components of the given Vector3i. 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(Vector3i(10, -20, 30) % Vector3i(7, 8, 9)) # Prints (3, -4, 3)
Vector3i operator %(right: int) 🔗
Gets the remainder of each component of the Vector3i 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(Vector3i(10, -20, 30) % 7) # Prints (3, -6, 2)
Vector3i operator *(right: Vector3i) 🔗
Multiplies each component of the Vector3i by the components of the given Vector3i.
print(Vector3i(10, 20, 30) * Vector3i(3, 4, 5)) # Prints (30, 80, 150)
Vector3 operator *(right: float) 🔗
Multiplies each component of the Vector3i by the given float. Returns a Vector3.
print(Vector3i(10, 15, 20) * 0.9) # Prints (9.0, 13.5, 18.0)
Vector3i operator *(right: int) 🔗
將該 Vector3i 的每個分量乘以給定的 int。
Vector3i operator +(right: Vector3i) 🔗
Adds each component of the Vector3i by the components of the given Vector3i.
print(Vector3i(10, 20, 30) + Vector3i(3, 4, 5)) # Prints (13, 24, 35)
Vector3i operator -(right: Vector3i) 🔗
Subtracts each component of the Vector3i by the components of the given Vector3i.
print(Vector3i(10, 20, 30) - Vector3i(3, 4, 5)) # Prints (7, 16, 25)
Vector3i operator /(right: Vector3i) 🔗
Divides each component of the Vector3i by the components of the given Vector3i.
print(Vector3i(10, 20, 30) / Vector3i(2, 5, 3)) # Prints (5, 4, 10)
Vector3 operator /(right: float) 🔗
Divides each component of the Vector3i by the given float. Returns a Vector3.
print(Vector3i(1, 2, 3) / 2.5) # Prints (0.4, 0.8, 1.2)
Vector3i operator /(right: int) 🔗
將該 Vector3i 的每個分量除以給定的 int。
bool operator <(right: Vector3i) 🔗
比較兩個 Vector3i 向量,首先檢查左向量的 X 值是否小於 right 向量的 X 值。如果 X 值完全相等,則用相同的方法檢查兩個向量的 Y 值、Z 值。該運算子可用於向量排序。
bool operator <=(right: Vector3i) 🔗
比較兩個 Vector3i 向量,首先檢查左向量的 X 值是否小於等於 right 向量的 X 值。如果 X 值完全相等,則用相同的方法檢查兩個向量的 Y 值、Z 值。該運算符可用於向量排序。
bool operator ==(right: Vector3i) 🔗
如果向量相等,則返回 true。
bool operator >(right: Vector3i) 🔗
比較兩個 Vector3i 向量,首先檢查左向量的 X 值是否大於 right 向量的 X 值。如果 X 值完全相等,則用相同的方法檢查兩個向量的 Y 值、Z 值。該運算子可用於向量排序。
bool operator >=(right: Vector3i) 🔗
比較兩個 Vector3i 向量,首先檢查左向量的 X 值是否大於等於 right 向量的 X 值。如果 X 值完全相等,則用相同的方法檢查兩個向量的 Y 值、Z 值。該運算符可用於向量排序。
使用向量分量的 index 來存取向量分量。v[0] 等價於 v.x,v[1] 等價於 v.y,v[2] 等價於 v.z。
返回與 + 不存在時相同的值。單目 + 沒有作用,但有時可以使你的程式碼更具可讀性。
返回該 Vector3i 的負值。和寫 Vector3i(-v.x, -v.y, -v.z) 是一樣的。該操作在保持相同幅度的同時,翻轉向量的方向。