AABB¶
轴对齐包围盒。
描述¶
AABB
consists of a position, a size, and several utility functions. It is typically used for fast overlap tests.
It uses floating-point coordinates. The 2D counterpart to AABB
is Rect2.
Negative values for size are not supported and will not work for most methods. Use abs to get an AABB with a positive size.
Note: Unlike Rect2, AABB
does not have a variant that uses integer coordinates.
教程¶
属性¶
|
||
|
||
|
方法¶
abs ( ) |
|
get_area ( ) |
|
get_center ( ) |
|
get_endpoint ( int idx ) |
|
get_longest_axis ( ) |
|
get_support ( Vector3 dir ) |
|
has_no_area ( ) |
|
has_no_surface ( ) |
|
intersection ( AABB with ) |
|
intersects ( AABB with ) |
|
intersects_plane ( Plane plane ) |
|
intersects_segment ( Vector3 from, Vector3 to ) |
|
is_equal_approx ( AABB aabb ) |
|
属性说明¶
Vector3 end
Default |
|
终点角。通过 position + size
计算而来。设置该值会修改大小。
Vector3 position
Default |
|
起点角。通常比 end 小。
Vector3 size
Default |
|
从position 到 end 的大小。通常所有分量都是正数。
如果大小为负,可以用 abs 修正。
方法说明¶
从一个位置和大小构造 AABB
。
AABB abs ( )
返回等价的 AABB,其原点被修正至最负数的角落,大小被修正为正数。
该 AABB
完全包含另一个时,返回 true
。
返回该 AABB
的副本,该副本扩展至包含给出的点。
例子:
# position (-3, 2, 0), size (1, 1, 1)
var box = AABB(Vector3(-3, 2, 0), Vector3(1, 1, 1))
# position (-3, -1, 0), size (3, 4, 2), 包含原来的 AABB 和 Vector3(0, -1, 2)
var box2 = box.expand(Vector3(0, -1, 2))
float get_area ( )
返回该 AABB
的体积。
Vector3 get_center ( )
Returns the center of the AABB
, which is equal to position + (size / 2).
获取该 AABB
的 8 个端点的位置。
Vector3 get_longest_axis ( )
返回该 AABB
归一化后的最长轴。
int get_longest_axis_index ( )
返回该 AABB
最长轴的索引(根据 Vector3 的 AXIS_*
常量)。
float get_longest_axis_size ( )
返回该 AABB
最长轴的标量长度。
Vector3 get_shortest_axis ( )
返回该 AABB
归一化后的最短轴。
int get_shortest_axis_index ( )
返回该 AABB
最短轴的索引(根据 Vector3 的 AXIS_*
常量)。
float get_shortest_axis_size ( )
返回该 AABB
最短轴的标量长度。
返回指定方向上的支持点。常用于碰撞检测算法。
返回该 AABB
的副本,沿着所有面的方向都增加了指定的大小。
bool has_no_area ( )
该 AABB
为平面或者为空时,返回 true
。
bool has_no_surface ( )
该 AABB
为空时,返回 true
。
该 AABB
包含指定点时,返回 true
。
返回两个 AABB
的交叠区域。失败时返回空的 AABB(大小为 0,0,0)。
该 AABB
与另一个交叠时,返回 true
。
该 AABB
同时位于指定平面的两边时,返回 true
。
该 AABB
与 from
和 to
所构成的线段有交叠时,返回 true
。
该 AABB
与 aabb
近似相等时,返回 true
。通过将各个分量调用 @GDScript.is_equal_approx 确定。
返回同时包含该 AABB
和 with
的更大的 AABB
。