1 总览
在之前的编程练习中,我们实现了基础的光线追踪算法,具体而言是光线传输、光线与三角形求交。我们采用了这样的方法寻找光线与场景的交点:遍历场景中的所有物体,判断光线是否与它相交。在场景中的物体数量不大时,该做法可以取得良好的结果,但当物体数量增多、模型变得更加复杂,该做法将会变得非常低效。因此,我们需要加速结构来加速求交过程。在本次练习中,我们重点关注物体划分算法 Bounding Volume Hierarchy (BVH)。本练习要求你实现 Ray-BoundingVolume 求交与 BVH 查找。
首先,你需要从上一次编程练习中引用以下函数:
Render()
inRenderer.cpp
: 将你的光线生成过程粘贴到此处,并且按照新框
架更新相应调用的格式。Triangle::getIntersection
inTriangle.hpp
: 将你的光线-三角形相交函数粘贴到此处,并且按照新框架更新相应相交信息的格式。
在本次编程练习中,你需要实现以下函数:
IntersectP(const Ray& ray, const Vector3f& invDir, const std::array<int, 3>& dirIsNeg)
inBounds3.hpp
: 这个函数的作用是判断包围盒 BoundingBox 与光线是否相交,你需要按照课程介绍的算法实现求交过程。getIntersection(BVHBuildNode* node, const Ray ray)
inBVH.cpp
: 建立 BVH 之后,我们可以用它加速求交过程。该过程递归进行,你将在其中调用你实现的Bounds3::IntersectP
.
2. 实现
Render()的实现
光线生成,这里的eye_pos被移动到了(-1,5,10),表示的是相机的位置,和作业5不一样,揣测代码的意思eye_pos已经是世界坐标了,而scene默认的fov是90,所以,这说明相机平面中心坐标其实等价于移动到了(-1,5,9)的位置(回想作业5相机的位置是(0,0,0),而相机平面中心的坐标是(0,0,-1))。和作业5不同,这里的ray的起点应该是eye_pos。
void Renderer::Render(const Scene& scene)
{
std::vector<Vector3f> framebuffer(scene.width * scene.height);
float scale = tan(deg2rad(scene.fov * 0.5));
float imageAspectRatio = scene.width / (float)scene.height;
Vector3f eye_pos(-1, 5, 10);
int m = 0;
for (uint32_t j = 0; j < scene.height; ++j) {
for (uint32_t i = 0; i < scene.width; ++i) {
// generate primary ray direction
float x = (2 * (i + 0.5) / (float)scene.width - 1) *
imageAspectRatio * scale;
float y = (1 - 2 * (j + 0.5) / (float)scene.height) * scale;
// TODO: Find the x and y positions of the current pixel to get the
// direction
// vector that passes through it.
// Also, don't forget to multiply both of them with the variable
// *scale*, and x (horizontal) variable with the *imageAspectRatio*
Vector3f dir = normalize(Vector3f(x, y, -1)); // Don't forget to normalize this direction!
Ray ray(eye_pos, dir);
framebuffer[m++] = scene.castRay(ray, 0);
// Don't forget to normalize this direction!
}
UpdateProgress(j / (float)scene.height);
}
UpdateProgress(1.f);
// save framebuffer to file
FILE* fp = fopen("binary.ppm", "wb");
(void)fprintf(fp, "P6\n%d %d\n255\n", scene.width, scene.height);
for (auto i = 0; i < scene.height * scene.width; ++i) {
static unsigned char color[3];
color[0] = (unsigned char)(255 * clamp(0, 1, framebuffer[i].x));
color[1] = (unsigned char)(255 * clamp(0, 1, framebuffer[i].y));
color[2] = (unsigned char)(255 * clamp(0, 1, framebuffer[i].z));
fwrite(color, 1, 3, fp);
}
fclose(fp);
}
Triangle::getIntersection()的实现
inline Intersection Triangle::getIntersection(Ray ray)
{
Intersection inter;
if (dotProduct(ray.direction, normal) > 0)
return inter;
double u, v, t_tmp = 0;
Vector3f pvec = crossProduct(ray.direction, e2);
double det = dotProduct(e1, pvec);
if (fabs(det) < EPSILON)
return inter;
double det_inv = 1. / det;
Vector3f tvec = ray.origin - v0;
u = dotProduct(tvec, pvec) * det_inv;
if (u < 0 || u > 1)
return inter;
Vector3f qvec = crossProduct(tvec, e1);
v = dotProduct(ray.direction, qvec) * det_inv;
if (v < 0 || u + v > 1)
return inter;
t_tmp = dotProduct(e2, qvec) * det_inv;
if (t_tmp < 0)
return inter;
// TODO find ray triangle intersection
inter.happened = true;
inter.coords = ray.origin + t_tmp * ray.direction;
inter.normal = this->normal;
inter.distance = t_tmp;
inter.obj = this;
inter.m = this->m;
return inter;
}
TODO前面已经写好了我们在作业5写的Möller-Trumbore算法,不过我这里多加了一步判断,防止光线是反向的也计算出交点:
if (t_tmp < 0)
return inter;
既然我们已经得到了交点,现在就是给交点的属性赋值了,如上面的代码所示:
happened: 是否发生相交
coords: 交点的世界坐标
normal: 交点的法向量
distance: 交点和相机的距离
obj: 物体
m: 材料属性
Bounds3::IntersectP()的实现
基本的思路是按照下面这张图来得到t_enter和t_exit
代码里使用了invDir因为乘法比除法更快,而dirIsNeg根据提示是说光线方向的三个分量是否大于零,例如对包围盒的x平面而言,包围盒有两个x平面
x
=
p
M
i
n
.
x
x=pMin.x
x=pMin.x和
x
=
p
M
a
x
.
x
x=pMax.x
x=pMax.x,如果光线的x方向分量大于0,说明先进入
x
=
p
M
i
n
.
x
x=pMin.x
x=pMin.x这个平面,而从
x
=
p
M
a
x
.
x
x=pMax.x
x=pMax.x离开,反之如果光线的x方向分量小于0,说明先进入了
x
=
p
M
a
x
.
x
x=pMax.x
x=pMax.x这个平面,而从
x
=
p
M
i
n
.
x
x=pMin.x
x=pMin.x平面离开。所以这里用dirIsNeg判断,如果分量小于0,则交换tEnter和tExit对应的分量。
判断和包围盒有交点的条件是:
t E n t e r < t E x i t t_{Enter} < t_{Exit} tEnter<tExit且 t E x i t ≥ 0 t_{Exit} \ge 0 tExit≥0
inline bool Bounds3::IntersectP(const Ray& ray, const Vector3f& invDir,
const std::array<int, 3>& dirIsNeg) const
{
// invDir: ray direction(x,y,z), invDir=(1.0/x,1.0/y,1.0/z), use this because Multiply is faster that Division
// dirIsNeg: ray direction(x,y,z), dirIsNeg=[int(x>0),int(y>0),int(z>0)], use this to simplify your logic
// TODO test if ray bound intersects
Vector3f vec_tEnter = (pMin - ray.origin) * invDir;
Vector3f vec_tExit = (pMax - ray.origin) * invDir;
if (!dirIsNeg[0])
std::swap(vec_tEnter.x, vec_tExit.x);
if (!dirIsNeg[1])
std::swap(vec_tEnter.y, vec_tExit.y);
if (!dirIsNeg[2])
std::swap(vec_tEnter.z, vec_tExit.z);
float tEnter = std::max(vec_tEnter.x, std::max(vec_tEnter.y, vec_tEnter.z));
float tExit = std::min(vec_tExit.x, std::min(vec_tExit.y, vec_tExit.z));
if (tEnter < tExit && tExit >= 0)
return true;
else
return false;
}
BVH.cpp-getIntersection()的实现
基本的实现思路如下图算法所示:
递归二叉树节点,如果发现节点的包围盒没有被光线打中,则返回一个默认的Intersection,如果发现节点遍历到了叶子节点,则返回这个节点的物体的交点的信息,否则用hitLeft记录左子树的交点,用hitRight记录右子树的交点,比较两个子树的交点和光线的距离,返回更小的那一个。
Intersection BVHAccel::getIntersection(BVHBuildNode* node, const Ray& ray) const
{
// TODO Traverse the BVH to find intersection
if (!node->bounds.IntersectP(ray, ray.direction_inv, std::array<int, 3>({ray.direction.x > 0, ray.direction.y > 0, ray.direction.z > 0})))
return Intersection();
if (node->left == nullptr && node->right == nullptr)
return node->object->getIntersection(ray);
Intersection hitLeft = BVHAccel::getIntersection(node->left, ray);
Intersection hitRight = BVHAccel::getIntersection(node->right, ray);
return hitLeft.distance < hitRight.distance ? hitLeft : hitRight;
}
提高部分:SAH的实现
知乎的这篇文章讲得很好:PBRT-E4.3-层次包围体(BVH)(一)
我们计算不同划分下的代价,我们希望代价可以最小,这样包围盒求交也最小,递归计算的消耗也会变小。
一种方法是划分各个桶的方法,在总的节点的包围盒计算每个片体质心所在的桶的序号,然后桶也增加在这个桶里的片体的个数和所有片体的包围盒,这样计算时间也是4s,没什么太大的差别,这里的代码先使用了排序,然后通过寻找最低的cost找到划分的指针和begin指针的差值,用迭代器给leftshapes和rightshapes赋值
BVHBuildNode* BVHAccel::recursiveBuild_SAH(std::vector<Object*> objects)
{
BVHBuildNode* node = new BVHBuildNode();
// Compute bounds of all primitives in BVH node
Bounds3 bounds;
for (int i = 0; i < objects.size(); ++i)
bounds = Union(bounds, objects[i]->getBounds());
if (objects.size() == 1) {
// Create leaf _BVHBuildNode_
node->bounds = objects[0]->getBounds();
node->object = objects[0];
node->left = nullptr;
node->right = nullptr;
return node;
}
else if (objects.size() == 2) {
node->left = recursiveBuild_SAH(std::vector{objects[0]});
node->right = recursiveBuild_SAH(std::vector{objects[1]});
node->bounds = Union(node->left->bounds, node->right->bounds);
return node;
}
else {
Bounds3 centroidBounds;
for (int i = 0; i < objects.size(); ++i)
centroidBounds =
Union(centroidBounds, objects[i]->getBounds().Centroid());
int dim = centroidBounds.maxExtent();
switch (dim) {
case 0:
std::sort(objects.begin(), objects.end(), [](auto f1, auto f2) {
return f1->getBounds().Centroid().x <
f2->getBounds().Centroid().x;
});
break;
case 1:
std::sort(objects.begin(), objects.end(), [](auto f1, auto f2) {
return f1->getBounds().Centroid().y <
f2->getBounds().Centroid().y;
});
break;
case 2:
std::sort(objects.begin(), objects.end(), [](auto f1, auto f2) {
return f1->getBounds().Centroid().z <
f2->getBounds().Centroid().z;
});
break;
}
float boundsArea = bounds.SurfaceArea();
const int bucketNum = 10;
Bucket bucket[bucketNum];
for (int i = 0; i < objects.size(); ++i)
{
int b;
switch (dim)
{
case 0: b = centroidBounds.Offset(objects[i]->getBounds().Centroid()).x * bucketNum;
break;
case 1: b = centroidBounds.Offset(objects[i]->getBounds().Centroid()).y * bucketNum;
break;
case 2: b = centroidBounds.Offset(objects[i]->getBounds().Centroid()).z * bucketNum;
break;
}
if (b == bucketNum)
b = bucketNum - 1;
bucket[b].bounds = Union(bucket[b].bounds, objects[i]->getBounds());
bucket[b].cnt++;
}
float costRes = std::numeric_limits<double>::infinity();
int partitionInd = 0;
int offset = 0;
for (int i = 0; i < bucketNum - 1; ++i)
{
Bounds3 boundsLeft, boundsRight;
int cntLeft = 0, cntRight = 0;
for (int j = 0; j < i + 1; ++j)
{
cntLeft += bucket[j].cnt;
boundsLeft = Union(boundsLeft, bucket[j].bounds);
}
for (int j = i + 1; j < bucketNum; ++j)
{
cntRight += bucket[j].cnt;
boundsRight = Union(boundsRight, bucket[j].bounds);
}
float cost = cntLeft * boundsLeft.SurfaceArea() / boundsArea + cntRight * boundsRight.SurfaceArea() / boundsArea + 0.125f;
if (cost < costRes)
{
partitionInd = i;
costRes = cost;
offset = cntLeft;
}
}
auto beginning = objects.begin();
auto midding = objects.begin() + offset;
auto ending = objects.end();
auto leftshapes = std::vector<Object*>(beginning, midding);
auto rightshapes = std::vector<Object*>(midding, ending);
node->left = recursiveBuild_SAH(leftshapes);
node->right = recursiveBuild_SAH(rightshapes);
node->bounds = Union(node->left->bounds, node->right->bounds);
}
return node;
}
我们需要定义结构体Bucket来放置桶,这里在BVH.hpp里进行了定义。
BVH.hpp
struct Bucket
{
int cnt = 0;
Bounds3 bounds;
};
上面的写法每次计算leftBound和rightBount都要重新计算一遍,进行了很多重复计算,如果能保存中间结果呢可以减少重复计算,说不定提高计算效率,这里和力扣的238.除自身以外数组的乘积的思路很像
这里举个例子,比如bucket每个区间里各放有0,1,2,3四个片元,leftBound就放bucket左区间的片元的包围盒,rightBound放bucket右区间的片元的包围盒:
以bucket[1]为界(bucket[1]包含在左包围盒里),0,1包含在左包围盒,对应的是leftBound[1],2,3包含在右包围盒,对应的是rightBound[1]
相邻的包围盒我们可以推得有递推公式,思路是包含前一个小区间的大包围盒和当前小区间的包围盒合并就可以得到包含当前小区间的大包围盒:
l
e
f
t
B
o
u
n
d
[
i
]
=
U
n
i
o
n
(
b
u
c
k
e
t
[
i
]
.
g
e
t
B
o
u
n
d
(
)
,
l
e
f
t
B
o
u
n
d
[
i
−
1
]
)
leftBound[i] = Union(bucket[i].getBound(), leftBound[i-1])
leftBound[i]=Union(bucket[i].getBound(),leftBound[i−1])
r
i
g
h
t
B
o
u
n
d
[
i
]
=
U
n
i
o
n
(
b
u
c
k
e
t
[
i
+
1
]
.
g
e
t
B
o
u
n
d
(
)
,
r
i
g
h
t
B
o
u
n
d
[
i
+
1
]
)
rightBound[i] = Union(bucket[i+1].getBound(), rightBound[i+1])
rightBound[i]=Union(bucket[i+1].getBound(),rightBound[i+1])
另外排序是不是也消耗了一点时间,下面的代码把排序给去掉了:
BVHBuildNode* BVHAccel::recursiveBuild_SAH(std::vector<Object*> objects)
{
BVHBuildNode* node = new BVHBuildNode();
// Compute bounds of all primitives in BVH node
Bounds3 bounds;
for (int i = 0; i < objects.size(); ++i)
bounds = Union(bounds, objects[i]->getBounds());
if (objects.size() == 1) {
// Create leaf _BVHBuildNode_
node->bounds = objects[0]->getBounds();
node->object = objects[0];
node->left = nullptr;
node->right = nullptr;
return node;
}
else if (objects.size() == 2) {
node->left = recursiveBuild_SAH(std::vector{objects[0]});
node->right = recursiveBuild_SAH(std::vector{objects[1]});
node->bounds = Union(node->left->bounds, node->right->bounds);
return node;
}
else {
Bounds3 centroidBounds;
for (int i = 0; i < objects.size(); ++i)
centroidBounds =
Union(centroidBounds, objects[i]->getBounds().Centroid());
int dim = centroidBounds.maxExtent();
float boundsArea = bounds.SurfaceArea();
const int bucketNum = 10;
Bucket bucket[bucketNum];
for (auto& object: objects)
{
int b;
switch (dim)
{
case 0: b = centroidBounds.Offset(object->getBounds().Centroid()).x * bucketNum;
break;
case 1: b = centroidBounds.Offset(object->getBounds().Centroid()).y * bucketNum;
break;
case 2: b = centroidBounds.Offset(object->getBounds().Centroid()).z * bucketNum;
break;
}
if (b == bucketNum)
b = bucketNum - 1;
bucket[b].bounds = Union(bucket[b].bounds, object->getBounds());
bucket[b].cnt++;
}
std::vector<Bounds3> leftBound(bucketNum - 1);
std::vector<Bounds3> rightBound(bucketNum - 1);
leftBound[0] = bucket[0].bounds;
rightBound[bucketNum - 2] = bucket[bucketNum - 1].bounds;
for (int i = 1; i < bucketNum - 1; ++i)
{
leftBound[i] = Union(leftBound[i - 1], bucket[i].bounds);
}
for (int i = bucketNum - 3; i >= 0; --i)
{
rightBound[i] = Union(rightBound[i + 1], bucket[i + 1].bounds);
}
int cntLeft = 0;
int cntRight = objects.size();
float costRes = std::numeric_limits<double>::infinity();
int partitionInd = 0;
for (int i = 0; i < bucketNum - 1; ++i)
{
cntLeft = cntLeft + bucket[i].cnt;
cntRight = cntRight - bucket[i].cnt;
if (cntLeft && cntRight)
{
float cost = cntLeft * leftBound[i].SurfaceArea() / boundsArea + cntRight * rightBound[i].SurfaceArea() / boundsArea + 0.125f;
if (cost < costRes)
{
partitionInd = i;
costRes = cost;
}
}
}
auto leftshapes = std::vector<Object*>();
auto rightshapes = std::vector<Object*>();
for (auto& object: objects)
{
int b;
switch (dim)
{
case 0: b = centroidBounds.Offset(object->getBounds().Centroid()).x * bucketNum;
break;
case 1: b = centroidBounds.Offset(object->getBounds().Centroid()).y * bucketNum;
break;
case 2: b = centroidBounds.Offset(object->getBounds().Centroid()).z * bucketNum;
break;
}
if (b == bucketNum)
b = bucketNum - 1;
if (b <= partitionInd)
leftshapes.push_back(object);
else
rightshapes.push_back(object);
}
node->left = recursiveBuild_SAH(leftshapes);
node->right = recursiveBuild_SAH(rightshapes);
node->bounds = Union(node->left->bounds, node->right->bounds);
}
return node;
}
结果还是一样花了4秒渲染完。
另一种写法是将所有图元按照数量均匀划分成了B个部分,然后计算代价,这样划分比较快,但是好像没有用到桶的划分。
BVHBuildNode* BVHAccel::recursiveBuild_SAH(std::vector<Object*> objects)
{
BVHBuildNode* node = new BVHBuildNode();
// Compute bounds of all primitives in BVH node
Bounds3 bounds;
for (int i = 0; i < objects.size(); ++i)
bounds = Union(bounds, objects[i]->getBounds());
if (objects.size() == 1) {
// Create leaf _SAHBuildNode_
node->bounds = objects[0]->getBounds();
node->object = objects[0];
node->left = nullptr;
node->right = nullptr;
return node;
}
else if (objects.size() == 2) {
node->left = recursiveBuild_SAH(std::vector{objects[0]});
node->right = recursiveBuild_SAH(std::vector{objects[1]});
node->bounds = Union(node->left->bounds, node->right->bounds);
return node;
}
else {
Bounds3 centroidBounds;
for (int i = 0; i < objects.size(); ++i)
centroidBounds =
Union(centroidBounds, objects[i]->getBounds().Centroid());
int dim = centroidBounds.maxExtent();
switch (dim) {
case 0:
std::sort(objects.begin(), objects.end(), [](auto f1, auto f2) {
return f1->getBounds().Centroid().x <
f2->getBounds().Centroid().x;
});
break;
case 1:
std::sort(objects.begin(), objects.end(), [](auto f1, auto f2) {
return f1->getBounds().Centroid().y <
f2->getBounds().Centroid().y;
});
break;
case 2:
std::sort(objects.begin(), objects.end(), [](auto f1, auto f2) {
return f1->getBounds().Centroid().z <
f2->getBounds().Centroid().z;
});
break;
}
auto beginning = objects.begin();
auto ending = objects.end();
float midIdx = 1;
int bucketNum = 10;
float costRes = std::numeric_limits<double>::infinity();
float nodeArea = bounds.SurfaceArea();
for (int i = 1; i < bucketNum; ++i)
{
auto mid_temp = objects.begin() + std::max(1, (int)(objects.size() * (float)i / bucketNum));
auto leftshapes = std::vector<Object*>(beginning, mid_temp);
auto rightshapes = std::vector<Object*>(mid_temp, ending);
assert(objects.size() == (leftshapes.size() + rightshapes.size()));
Bounds3 leftBounds, rightBounds;
for (int j = 0; j < leftshapes.size(); ++j)
leftBounds = Union(leftBounds, leftshapes[j]->getBounds());
for (int j = 0; j < rightshapes.size(); ++j)
rightBounds = Union(rightBounds, rightshapes[j]->getBounds());
float leftArea = leftBounds.SurfaceArea();
float rightArea = rightBounds.SurfaceArea();
float cost = leftArea / nodeArea * leftshapes.size() + rightArea / nodeArea * rightshapes.size() + 0.125f;
if (cost < costRes)
{
midIdx = i;
costRes = cost;
}
}
auto middling = objects.begin() + std::max(1, (int)(objects.size() * (float)midIdx / bucketNum));
auto leftshapes = std::vector<Object*>(beginning, middling);
auto rightshapes = std::vector<Object*>(middling, ending);
assert(objects.size() == (leftshapes.size() + rightshapes.size()));
node->left = recursiveBuild_SAH(leftshapes);
node->right = recursiveBuild_SAH(rightshapes);
node->bounds = Union(node->left->bounds, node->right->bounds);
}
return node;
}
时间上也是4s。
3. 其他代码批注
BVHAccel::recursiveBuild()
这个函数的作用是递归的建立BVH的数,最后返回根节点,首先先把所有物体的包围盒得到,然后如果物体的个数为1,创建叶子节点,如果物体的个数是2,两个物体分别作为左右子树,如果物体的个数大于2,那么找当前节点内每个物体的包围盒质心的总和(Union),并且用maxExtent函数找这个包围盒最长的轴,沿最长的轴对物体进行排序,然后按排序的结果划分左子树和右子树。
BVHBuildNode* BVHAccel::recursiveBuild(std::vector<Object*> objects)
{
BVHBuildNode* node = new BVHBuildNode();
// Compute bounds of all primitives in BVH node
Bounds3 bounds;
for (int i = 0; i < objects.size(); ++i)
bounds = Union(bounds, objects[i]->getBounds());
if (objects.size() == 1) {
// Create leaf _BVHBuildNode_
node->bounds = objects[0]->getBounds();
node->object = objects[0];
node->left = nullptr;
node->right = nullptr;
return node;
}
else if (objects.size() == 2) {
node->left = recursiveBuild(std::vector{objects[0]});
node->right = recursiveBuild(std::vector{objects[1]});
node->bounds = Union(node->left->bounds, node->right->bounds);
return node;
}
else {
Bounds3 centroidBounds;
for (int i = 0; i < objects.size(); ++i)
centroidBounds =
Union(centroidBounds, objects[i]->getBounds().Centroid());
int dim = centroidBounds.maxExtent();
switch (dim) {
case 0:
std::sort(objects.begin(), objects.end(), [](auto f1, auto f2) {
return f1->getBounds().Centroid().x <
f2->getBounds().Centroid().x;
});
break;
case 1:
std::sort(objects.begin(), objects.end(), [](auto f1, auto f2) {
return f1->getBounds().Centroid().y <
f2->getBounds().Centroid().y;
});
break;
case 2:
std::sort(objects.begin(), objects.end(), [](auto f1, auto f2) {
return f1->getBounds().Centroid().z <
f2->getBounds().Centroid().z;
});
break;
}
auto beginning = objects.begin();
auto middling = objects.begin() + (objects.size() / 2);
auto ending = objects.end();
auto leftshapes = std::vector<Object*>(beginning, middling);
auto rightshapes = std::vector<Object*>(middling, ending);
assert(objects.size() == (leftshapes.size() + rightshapes.size()));
node->left = recursiveBuild(leftshapes);
node->right = recursiveBuild(rightshapes);
node->bounds = Union(node->left->bounds, node->right->bounds);
}
return node;
}
maxExtent的实现,用来获取最长的轴,0,1,2,分别对应x轴,y轴和z轴:
int Bounds::maxExtent() const
{
Vector3f d = Diagonal();
if (d.x > d.y && d.x > d.z)
return 0;
else if (d.y > d.z)
return 1;
else
return 2;
}
Bounds3
这个建立的是一个三维的包围盒,对于一个长方体我们只需要两个角点就可以把包围盒的信息记录下来,两个角点分别是最靠近原点和最远离原点的,看下代码中的pMin和pMax的定义就知道了
Vector3f Diagonal()
:获得包围盒长宽高的矢量double SurfaceArea()
: 获得包围盒的表面积Vector3f Centroid()
:获得包围盒的中心Bounds3 Intersect(const Bounds3& b)
:和另一个包围盒相交后的新的包围盒Vector3f Offset(const Vector3f& p)
:p在包围盒各维度长度的占比bool Overlaps(const Bounds3& b1, const Bounds3& b2)
:两个包围盒是不是有重叠bool Inside(const Vector3f& p, const Bounds3& b)
:点p是不是在包围盒b内Bounds3 Union(const Bounds3& b1, const Bounds3& b2)
:两个包围盒合并为一个更大的包围盒Bounds3 Union(const Bounds3& b, const Vector3f& p)
:添加点p以后的新的包围盒