Unity Bounds 边界框(包围盒)
作者:互联网
Represents an axis aligned bounding box.
表示一个轴对齐的边界框。
An axis-aligned bounding box, or AABB for short, is a box aligned with coordinate axes and fully enclosing some object. Because the box is never rotated with respect to the axes, it can be defined by just its center and extents, or alternatively by min and max points.
一个轴对齐边界框,或AABB的简称,是一个坐标对齐的框(盒子)并且完全封闭一些对象。由于这个框(盒子)不会相对轴进行旋转,它只能通过center(中心)和extents(范围)进行定义,或者选择min(小)和 max(大)点。
Bounds is used by Collider.bounds, Mesh.bounds, Renderer.bounds.
边界框被用于Collider.bounds, Mesh.bounds, Renderer.bounds。
Variables 变量
center 中心 | The center of the bounding box. 边界框(包围盒子)的中心 |
size 尺寸 | The total size of the box. This is always twice as large as the extents. 盒子的总尺寸。这(尺寸size)总是extents(范围)的两倍大 |
extents 范围 | The extents of the box. This is always half of the size. 边框(盒子)的范围。这(范围extents)总是size(尺寸)的一半 |
min 最小值 | The minimal point of the box. This is always equal to center-extents. 框(盒子)的最小点,这总是等于center-extents(中心减范围) |
max 最大值 | The maximal point of the box. This is always equal to center extents. 框(盒子)的最大点,这总是等于center extents(中心加范围) |
Constructors 构造函数
Bounds 边界框(包围盒子) | Creates new Bounds with a given center and total size. Bound extents will be half the given size. 使用给定中心和总尺寸来创建新边界框。边界框范围将为给定尺寸的一半。 |
Functions 函数
SetMinMax 设置最小最大 | Sets the bounds to the min and max value of the box. 设置边界框的最小和最大值 |
Encapsulate 封装 | Grows the Bounds to include the point. 增大边界框来包含这个点 |
Expand 扩大 | Expand the bounds by increasing its size by amount along each side. 通过增加总数的大小(尺寸)延长每条边的长度来扩大 |
Intersects 相交 | Does another bounding box intersect with this bounding box? 另一个边界框是否与这个边界框相交? |
Contains 包含 | Is point contained in the bounding box? 这个点是否被包含在边界框内? |
SqrDistance 平方距离 | The smallest squared distance between the point and this bounding box. 这个点和边界框之间的最小平方距离。 |
IntersectRay 相交射线 | Does ray intersect this bounding box? 射线可以与这个边界框相交么? |
ToString 转换为“字符串” | Returns a nicely formatted string for the bounds. 返回边界框已经格式化好的字符串。 |
于飞 unity
Bounds.Bounds 边框
static function Bounds (center : Vector3, size : Vector3) : Bounds
Description 描述
Creates new Bounds with a given center and total size. Bound extents will be half the given size.
创建新边界和给定center(中心)大小的总和(尺寸和)。边界框范围将是给定尺寸的一半。
JS:
// Create pillar bounding box centered at the origin
//在框内中央的原点创建支点建筑
var bounds = Bounds (Vector3.zero, Vector3 (1, 2, 1));
于飞 unity
C#::
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public Bounds bounds = new Bounds(Vector3.zero, new Vector3(1, 2, 1));
}
Bounds.IntersectRay 相交射线
function IntersectRay (ray : Ray) : boolean
Description 描述
Does ray intersect this bounding box?
射线是否与这个边界框相交?
于飞 unity
JS:
// Creates a ray that points from the origin to the infinity among the z Axis.
//创建一个射线沿着Z轴从原点到无穷(远)
// And prints if the transform touched the ray.
//如果transform(转换)遇到射线,就输出
var ra : Ray = new Ray (Vector3.zero, Vector3.forward);;
function Update () {
// Color ra in the scene editor.
//在场景编辑器中赋予射线颜色
Debug.DrawRay (Vector3.zero, Vector3.forward * 999, Color.green);
var bounds : Bounds = transform.collider.bounds;
if (bounds.IntersectRay (ra))
Debug.Log("Touched the ray");
}
C#:
using UnityEngine;
using System.Collections;
于飞 unity
public class example : MonoBehaviour {
public Ray ra = new Ray(Vector3.zero, Vector3.forward);
void Update() {
Debug.DrawRay(Vector3.zero, Vector3.forward * 999, Color.green);
Bounds bounds = transform.collider.bounds;
if (bounds.IntersectRay(ra))
Debug.Log("Touched the ray");
}
}
function IntersectRay (ray : Ray, out distance : float) : boolean
Description 描述
Does ray intersect this bounding box?
射线是否与这个边界框相交?
When IntersectRay returns true distance will be the distance to the ray's origin.
当IntersectRay(相交线)返回为真时, distance(距离)为射线到原点的距离。
于飞 unity
JS:
// Creates a ray that points from the origin to 10 units among the z Axis.
//创建一个射线,沿着Z轴,从原点到10个单位的距离
// And prints if the transform touched the ray.
//如果transform(转换)遇到射线就输出。
var ra : Ray = new Ray (Vector3.zero, Vector3.forward);;
var t : float = 10.0;
function Update () {
// Color ra in the scene editor.
//在场景编辑器中赋予射线颜色
Debug.DrawRay (Vector3.zero, Vector3.forward * 10, Color.green);
var bounds : Bounds = transform.collider.bounds;
if (bounds.IntersectRay (ra, t))
Debug.Log("Touched the ray");
}
于飞 unity
C#:
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public Ray ra = new Ray(Vector3.zero, Vector3.forward);
public float t = 10.0F;
void Update() {
Debug.DrawRay(Vector3.zero, Vector3.forward * 10, Color.green);
Bounds bounds = transform.collider.bounds;
if (bounds.IntersectRay(ra, out t))
Debug.Log("Touched the ray");
}
}
于飞 unity
Bounds.SetMinMax 设置最小最大
function SetMinMax (min : Vector3, max : Vector3) : void
Description 描述
Sets the bounds to the min and max value of the box.
设置边界框的最小最大值
Using this function is faster than assigning min and max separately.
使用这个函数比单独分配最小最大值要快。
标签:box,extents,边界,Vector3,bounds,Bounds,Unity,ray 来源: https://blog.csdn.net/qq_37524903/article/details/113625126