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.

Projection

用于 3D 投影变换的 4×4 矩阵。

描述

用于 3D 投影变换的 4×4 矩阵,可以表示平移、旋转、缩放、剪切和透视分割等变换,由四个 Vector4 列组成。

对于纯粹的线性变换(平移、旋转和缩放),建议使用 Transform3D,因为它的性能更强,内存占用更少。

在内部作为 Camera3D 的投影矩阵使用。

备注

通过 C# 使用这个 API 时有显著的不同。详见 C# API 与 GDScript 的差异

属性

Vector4

w

Vector4(0, 0, 0, 1)

Vector4

x

Vector4(1, 0, 0, 0)

Vector4

y

Vector4(0, 1, 0, 0)

Vector4

z

Vector4(0, 0, 1, 0)

构造函数

Projection

Projection ( )

Projection

Projection ( Projection from )

Projection

Projection ( Transform3D from )

Projection

Projection ( Vector4 x_axis, Vector4 y_axis, Vector4 z_axis, Vector4 w_axis )

方法

Projection

create_depth_correction ( bool flip_y ) static

Projection

create_fit_aabb ( AABB aabb ) static

Projection

create_for_hmd ( int eye, float aspect, float intraocular_dist, float display_width, float display_to_lens, float oversample, float z_near, float z_far ) static

Projection

create_frustum ( float left, float right, float bottom, float top, float z_near, float z_far ) static

Projection

create_frustum_aspect ( float size, float aspect, Vector2 offset, float z_near, float z_far, bool flip_fov=false ) static

Projection

create_light_atlas_rect ( Rect2 rect ) static

Projection

create_orthogonal ( float left, float right, float bottom, float top, float z_near, float z_far ) static

Projection

create_orthogonal_aspect ( float size, float aspect, float z_near, float z_far, bool flip_fov=false ) static

Projection

create_perspective ( float fovy, float aspect, float z_near, float z_far, bool flip_fov=false ) static

Projection

create_perspective_hmd ( float fovy, float aspect, float z_near, float z_far, bool flip_fov, int eye, float intraocular_dist, float convergence_dist ) static

float

determinant ( ) const

Projection

flipped_y ( ) const

float

get_aspect ( ) const

Vector2

get_far_plane_half_extents ( ) const

float

get_fov ( ) const

float

get_fovy ( float fovx, float aspect ) static

float

get_lod_multiplier ( ) const

int

get_pixels_per_meter ( int for_pixel_width ) const

Plane

get_projection_plane ( int plane ) const

Vector2

get_viewport_half_extents ( ) const

float

get_z_far ( ) const

float

get_z_near ( ) const

Projection

inverse ( ) const

bool

is_orthogonal ( ) const

Projection

jitter_offseted ( Vector2 offset ) const

Projection

perspective_znear_adjusted ( float new_znear ) const

操作符

bool

operator != ( Projection right )

Projection

operator * ( Projection right )

Vector4

operator * ( Vector4 right )

bool

operator == ( Projection right )

Vector4

operator [] ( int index )


常量

PLANE_NEAR = 0

该投影的近裁剪平面的索引值。

PLANE_FAR = 1

该投影的远裁剪平面的索引值。

PLANE_LEFT = 2

该投影的左裁剪平面的索引值。

PLANE_TOP = 3

该投影的上裁剪平面的索引值。

PLANE_RIGHT = 4

该投影的右裁剪平面的索引值。

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 ( )

构造默认初始化为 IDENTITYProjection


Projection Projection ( Projection from )

构造给定 Projection 的副本。


Projection Projection ( Transform3D from )

将 Projection 作为给定 Transform3D 的副本进行构造。


Projection Projection ( Vector4 x_axis, Vector4 y_axis, Vector4 z_axis, Vector4 w_axis )

从四个 Vector4 值(矩阵列)构造 Projection。


方法说明

Projection create_depth_correction ( bool flip_y ) static

创建新的 Projection,将位置从深度 -11 的范围投影到 01 的范围,并将投影后的位置根据 flip_y 垂直翻转。


Projection create_fit_aabb ( AABB aabb ) static

创建新的 Projection,将给定的投影进行缩放,从而适应投影空间中的给定 AABB


Projection create_for_hmd ( int eye, float aspect, float intraocular_dist, float display_width, float display_to_lens, float oversample, float z_near, float z_far ) static

创建新的 Projection,将位置投影至头戴显示器中,使用给定的 X:Y 纵横比、双眼间距、显示器宽度、到镜头的距离、过采样系数以及深度裁剪平面。

eye 设为 1 时创建的是左眼投影,设为 2 时则为右眼。


Projection create_frustum ( float left, float right, float bottom, float top, float z_near, float z_far ) static

创建新的 Projection,将位置投影至平截头台中,平截头台由给定的裁剪平面指定。


Projection create_frustum_aspect ( float size, float aspect, Vector2 offset, float z_near, float z_far, bool flip_fov=false ) static

创建新的 Projection,将位置投影至平截头台中,平截头台由给定的大小、X:Y 纵横比、偏移量以及裁剪平面指定。

flip_fov 决定投影视野是否按对角线翻转。


Projection create_light_atlas_rect ( Rect2 rect ) static

创建新的 Projection,将位置投影至给定的 Rect2


Projection create_orthogonal ( float left, float right, float bottom, float top, float z_near, float z_far ) static

创建新的 Projection,使用给定裁剪平面的正交投影对位置进行投影。


Projection create_orthogonal_aspect ( float size, float aspect, float z_near, float z_far, bool flip_fov=false ) static

创建新的 Projection,使用正交投影对位置进行投影,正交投影由给定的大小、X:Y 纵横比以及裁剪平面指定。

flip_fov 决定投影视野是否按对角线翻转。


Projection create_perspective ( float fovy, float aspect, float z_near, float z_far, bool flip_fov=false ) static

创建新的 Projection,使用透视投影对位置进行投影,透视投影由给定的 Y 轴视野(单位为度)、X:Y 纵横比以及裁剪平面指定。

flip_fov 决定投影视野是否按对角线翻转。


Projection create_perspective_hmd ( float fovy, float aspect, float z_near, float z_far, bool flip_fov, int eye, float intraocular_dist, float convergence_dist ) static

创建新的 Projection,使用透视投影对位置进行投影,透视投影由给定的 Y 轴视野(单位为度)、X:Y 纵横比以及裁剪平面指定。投影会针对头戴显示器进行调整,使用给定的双眼间距以及与能够聚焦的点的距离。

eye 设为 1 时创建的是左眼投影,设为 2 时则为右眼。

flip_fov 决定投影视野是否按对角线翻转。


float determinant ( ) const

返回一个标量值,该标量值是区域被该矩阵缩放的有符号系数。如果符号是负的,则矩阵翻转该区域的方向。

行列式可用于计算矩阵的可逆性或求解涉及矩阵的线性方程组,以及其他应用。


Projection flipped_y ( ) const

返回这个 Projection 的副本,Y 列中数值的符号都进行了翻转。


float get_aspect ( ) const

返回该 Projection 视口的 X:Y 纵横比。


Vector2 get_far_plane_half_extents ( ) const

返回投影远裁剪平面的尺寸除以二。


float get_fov ( ) const

返回该投影的水平视野(单位为度)。


float get_fovy ( float fovx, float aspect ) static

返回与给定水平视场(以度为单位)和长宽比相关联的投影的垂直视场(以度为单位)。


float get_lod_multiplier ( ) const

返回这个 Projection 对可见细节级别的缩放系数。


int get_pixels_per_meter ( int for_pixel_width ) const

在该 Projection 被应用后,返回每米显示的具有给定像素宽度的像素数。


Plane get_projection_plane ( int plane ) const

返回这个 Projection 的裁剪平面,索引由 plane 给定。

plane 应该等于 PLANE_NEARPLANE_FARPLANE_LEFTPLANE_TOPPLANE_RIGHTPLANE_BOTTOM


Vector2 get_viewport_half_extents ( ) const

返回视口平面的尺寸除以二,这个 Projection 会把位置投影至该平面。


float get_z_far ( ) const

返回该 Projection 中的距离,超过这个距离的位置会被裁剪。


float get_z_near ( ) const

返回该 Projection 中的距离,未达到这个距离的位置会被裁剪。


Projection inverse ( ) const

返回执行这个 Projection 的逆投影变换的 Projection


bool is_orthogonal ( ) const

如果该 Projection 进行的是正交投影,则返回 true


Projection jitter_offseted ( Vector2 offset ) const

返回一个 Projection,X 和 Y 的取值由给定的 Vector2 和最后一列中对应的第一个和第二个值相加而来。


Projection perspective_znear_adjusted ( float new_znear ) const

返回一个 Projection,将其近裁剪距离调整为 new_znear

注意:原始的 Projection 必须为透视投影。


操作符说明

bool operator != ( Projection right )

如果投影不相等,则返回 true

注意:由于浮点精度误差,即使投影实际上相等,也可能会返回 true 。可能会在 Godot 的未来版本中添加 is_equal_approx 方法。


Projection operator * ( Projection right )

返回一个 Projection,应用了这个 Projectionright 的组合变换。


Vector4 operator * ( Vector4 right )

使用这个 Projection 矩阵将给定的 Vector4 进行投影(相乘)。


bool operator == ( Projection right )

如果投影相等,则返回 true

注意:由于浮点精度错误,即使投影实际上相等,也可能会返回 false。可能会在 Godot 的未来版本中添加 is_equal_approx 方法。


Vector4 operator [] ( int index )

返回具有给定索引的 Projection 的列。

索引按以下顺序排列:x、y、z、w。