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...
Projection
用於 3D 投影變換的 4×4 矩陣。
說明
A 4×4 matrix used for 3D projective transformations. It can represent transformations such as translation, rotation, scaling, shearing, and perspective division. It consists of four Vector4 columns.
For purely linear transformations (translation, rotation, and scale), it is recommended to use Transform3D, as it is more performant and requires less memory.
Used internally as Camera3D's projection matrix.
Note: In a boolean context, a projection will evaluate to false if it's equal to IDENTITY. Otherwise, a projection will always evaluate to true.
備註
使用 C# 操作此 API 時有顯著差異,詳見 C# API 與 GDScript 的不同。
屬性
|
||
|
||
|
||
|
建構子
Projection(from: Projection) |
|
Projection(from: Transform3D) |
|
Projection(x_axis: Vector4, y_axis: Vector4, z_axis: Vector4, w_axis: Vector4) |
方法
create_depth_correction(flip_y: bool) static |
|
create_fit_aabb(aabb: AABB) static |
|
create_for_hmd(eye: int, aspect: float, intraocular_dist: float, display_width: float, display_to_lens: float, oversample: float, z_near: float, z_far: float) static |
|
create_frustum(left: float, right: float, bottom: float, top: float, z_near: float, z_far: float) static |
|
create_frustum_aspect(size: float, aspect: float, offset: Vector2, z_near: float, z_far: float, flip_fov: bool = false) static |
|
create_light_atlas_rect(rect: Rect2) static |
|
create_orthogonal(left: float, right: float, bottom: float, top: float, z_near: float, z_far: float) static |
|
create_orthogonal_aspect(size: float, aspect: float, z_near: float, z_far: float, flip_fov: bool = false) static |
|
create_perspective(fovy: float, aspect: float, z_near: float, z_far: float, flip_fov: bool = false) static |
|
create_perspective_hmd(fovy: float, aspect: float, z_near: float, z_far: float, flip_fov: bool, eye: int, intraocular_dist: float, convergence_dist: float) static |
|
determinant() const |
|
flipped_y() const |
|
get_aspect() const |
|
get_far_plane_half_extents() const |
|
get_fov() const |
|
get_lod_multiplier() const |
|
get_pixels_per_meter(for_pixel_width: int) const |
|
get_projection_plane(plane: int) const |
|
get_viewport_half_extents() const |
|
get_z_far() const |
|
get_z_near() const |
|
inverse() const |
|
is_orthogonal() const |
|
jitter_offseted(offset: Vector2) const |
|
perspective_znear_adjusted(new_znear: float) const |
運算子
operator !=(right: Projection) |
|
operator *(right: Projection) |
|
operator *(right: Vector4) |
|
operator ==(right: Projection) |
|
operator [](index: int) |
列舉
enum Planes: 🔗
Planes PLANE_NEAR = 0
該投影的近裁剪平面的索引值。
Planes PLANE_FAR = 1
該投影的遠裁剪平面的索引值。
Planes PLANE_LEFT = 2
該投影的左裁剪平面的索引值。
Planes PLANE_TOP = 3
該投影的上裁剪平面的索引值。
Planes PLANE_RIGHT = 4
該投影的右裁剪平面的索引值。
Planes PLANE_BOTTOM = 5
該投影的下裁剪平面的索引值。
常數
IDENTITY = Projection(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1) 🔗
未定義變換的 Projection。對其他資料結構使用時,不會進行任何變換。
ZERO = Projection(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) 🔗
所有值都初始化為 0 的 Projection。對其他資料結構使用時,會進行清零操作。
屬性說明
Vector4 w = Vector4(0, 0, 0, 1) 🔗
投影矩陣的 W 向量(第 3 列)。相當於陣列索引 3。
Vector4 x = Vector4(1, 0, 0, 0) 🔗
投影矩陣的 X 向量(第 0 列)。相當於陣列索引 0。
Vector4 y = Vector4(0, 1, 0, 0) 🔗
投影矩陣的 Y 向量(第 1 列)。相當於陣列索引 1。
Vector4 z = Vector4(0, 0, 1, 0) 🔗
投影矩陣的 Z 向量(第 2 列)。相當於陣列索引 2。
建構子說明
Projection Projection() 🔗
Constructs a default-initialized Projection identical to IDENTITY.
Note: In C#, this constructs a Projection identical to ZERO.
Projection Projection(from: Projection)
建構給定 Projection 的副本。
Projection Projection(from: Transform3D)
將 Projection 作為給定 Transform3D 的副本進行建構。
Projection Projection(x_axis: Vector4, y_axis: Vector4, z_axis: Vector4, w_axis: Vector4)
從四個 Vector4 值(矩陣列)建構 Projection。
方法說明
Projection create_depth_correction(flip_y: bool) static 🔗
建立新的 Projection,將位置從深度 -1 到 1 的範圍投影到 0 到 1 的範圍,並將投影後的位置根據 flip_y 垂直翻轉。
Projection create_fit_aabb(aabb: AABB) static 🔗
建立新的 Projection,將給定的投影進行縮放,從而適應投影空間中的給定 AABB。
Projection create_for_hmd(eye: int, aspect: float, intraocular_dist: float, display_width: float, display_to_lens: float, oversample: float, z_near: float, z_far: float) static 🔗
建立新的 Projection,將位置投影至頭戴顯示器中,使用給定的 X:Y 縱橫比、雙眼間距、顯示器寬度、到鏡頭的距離、過取樣係數以及深度裁剪平面。
eye 設為 1 時建立的是左眼投影,設為 2 時則為右眼。
Projection create_frustum(left: float, right: float, bottom: float, top: float, z_near: float, z_far: float) static 🔗
建立新的 Projection,將位置投影至平截頭台中,平截頭台由給定的裁剪平面指定。
Projection create_frustum_aspect(size: float, aspect: float, offset: Vector2, z_near: float, z_far: float, flip_fov: bool = false) static 🔗
建立新的 Projection,將位置投影至平截頭台中,平截頭台由給定的大小、X:Y 縱橫比、偏移量以及裁剪平面指定。
flip_fov 決定投影視野是否按對角線翻轉。
Projection create_light_atlas_rect(rect: Rect2) static 🔗
建立新的 Projection,將位置投影至給定的 Rect2。
Projection create_orthogonal(left: float, right: float, bottom: float, top: float, z_near: float, z_far: float) static 🔗
建立新的 Projection,使用給定裁剪平面的正交投影對位置進行投影。
Projection create_orthogonal_aspect(size: float, aspect: float, z_near: float, z_far: float, flip_fov: bool = false) static 🔗
建立新的 Projection,使用正交投影對位置進行投影,正交投影由給定的大小、X:Y 縱橫比以及裁剪平面指定。
flip_fov 決定投影視野是否按對角線翻轉。
Projection create_perspective(fovy: float, aspect: float, z_near: float, z_far: float, flip_fov: bool = false) static 🔗
建立新的 Projection,使用透視投影對位置進行投影,透視投影由給定的 Y 軸視野(單位為度)、X:Y 縱橫比以及裁剪平面指定。
flip_fov 決定投影視野是否按對角線翻轉。
Projection create_perspective_hmd(fovy: float, aspect: float, z_near: float, z_far: float, flip_fov: bool, eye: int, intraocular_dist: float, convergence_dist: float) static 🔗
建立新的 Projection,使用透視投影對位置進行投影,透視投影由給定的 Y 軸視野(單位為度)、X:Y 縱橫比以及裁剪平面指定。投影會針對頭戴顯示器進行調整,使用給定的雙眼間距以及與能夠聚焦的點的距離。
eye 設為 1 時建立的是左眼投影,設為 2 時則為右眼。
flip_fov 決定投影視野是否按對角線翻轉。
返回一個標量值,該標量值是區域被該矩陣縮放的有符號係數。如果符號是負的,則矩陣翻轉該區域的方向。
行列式可用於計算矩陣的可逆性或求解涉及矩陣的線性方程組,以及其他套用。
Projection flipped_y() const 🔗
返回這個 Projection 的副本,Y 列中數值的符號都進行了翻轉。
返回該 Projection 視口的 X:Y 縱橫比。
Vector2 get_far_plane_half_extents() const 🔗
返回投影遠裁剪平面的尺寸除以二。
返回該投影的水平視野(單位為度)。
float get_fovy(fovx: float, aspect: float) static 🔗
Returns the vertical field of view of the projection (in degrees) associated with the given horizontal field of view (in degrees) and aspect ratio.
Note: Unlike most methods of Projection, aspect is expected to be 1 divided by the X:Y aspect ratio.
float get_lod_multiplier() const 🔗
返回這個 Projection 對可見細節級別的縮放係數。
int get_pixels_per_meter(for_pixel_width: int) const 🔗
Returns for_pixel_width divided by the viewport's width measured in meters on the near plane, after this Projection is applied.
Plane get_projection_plane(plane: int) const 🔗
返回這個 Projection 的裁剪平面,索引由 plane 給定。
plane 應該等於 PLANE_NEAR、PLANE_FAR、PLANE_LEFT、PLANE_TOP、PLANE_RIGHT 或 PLANE_BOTTOM。
Vector2 get_viewport_half_extents() const 🔗
返回視口平面的尺寸除以二,這個 Projection 會把位置投影至該平面。
返回該 Projection 中的距離,超過這個距離的位置會被裁剪。
返回該 Projection 中的距離,未達到這個距離的位置會被裁剪。
Projection inverse() const 🔗
返回執行這個 Projection 的逆投影變換的 Projection。
如果該 Projection 進行的是正交投影,則返回 true。
Projection jitter_offseted(offset: Vector2) const 🔗
返回一個 Projection,X 和 Y 的取值由給定的 Vector2 和最後一列中對應的第一個和第二個值相加而來。
Projection perspective_znear_adjusted(new_znear: float) const 🔗
返回一個 Projection,將其近裁剪距離調整為 new_znear。
注意:原始的 Projection 必須為透視投影。
運算子說明
bool operator !=(right: Projection) 🔗
如果投影不相等,則返回 true。
注意:由於浮點精度誤差,即使投影實際上相等,也可能會返回 true 。可能會在 Godot 的未來版本中新增 is_equal_approx 方法。
Projection operator *(right: Projection) 🔗
返回一個 Projection,套用了這個 Projection 和 right 的組合變換。
Vector4 operator *(right: Vector4) 🔗
使用這個 Projection 矩陣將給定的 Vector4 進行投影(相乘)。
bool operator ==(right: Projection) 🔗
如果投影相等,則返回 true。
注意:由於浮點精度錯誤,即使投影實際上相等,也可能會返回 false。可能會在 Godot 的未來版本中新增 is_equal_approx 方法。
Vector4 operator [](index: int) 🔗
返回具有給定索引的 Projection 的列。
索引按以下順序排列:x、y、z、w。