FLAXengine代码剖析

2021SC@SDUSC

Struct BoundingFrustum
定义了一个视锥,可用于视锥裁剪、缩放到区段(缩放适配)操作、(矩阵、视锥体、摄像机)交换和许多种类的交叉测试。

首先我们要知道,这个所谓的视锥是一个游戏引擎中的概念,视锥截取是一个经典的,减轻运算压力的做法。
在这里插入图片描述

通俗地说,就是不渲染视锥以外的实体。
在这里插入图片描述

Properties:
Bottom
获取 BoundingFrustum 的底平面。

返回一个Plane类型值。

结构体 Struct Plane

表示三维空间中的平面。用Single或者vector3构造。

Fields:
D
平面沿其法线到原点的距离。Single类型。

Normal
平面的法向量。Vector3类型。

Properties

Item[Int32]
获取或设置指定索引处的组件。

Methods:
Dot(Plane, Vector4)
计算指定向量和平面的点积。

Dot(ref Plane, ref Vector4, out Single)
计算指定向量和平面的点积。

DotCoordinate(Plane, Vector3)
计算指定向量的点积和平面的法线加上平面的距离值。

DotCoordinate(ref Plane, ref Vector3, out Single)
同上。

DotNormal(Plane, Vector3)
计算指定向量的点积和平面的法线。

DotNormal(ref Plane, ref Vector3, out Single)
同上。

然后就是一大堆重载的方法和重载运算符。

回到BoundingFrustum来。

Far
获取 BoundingFrustum 的远平面。Plane类型。

IsOrthographic
指示当前 BoundingFrustum 是否为正投影。布尔值。

Left
获取 BoundingFrustum 的左平面。平面类型

Matrix
获取或设置描述此边界截锥的矩阵。

Near
获取 BoundingFrustum 的近平面。

Right
获取 BoundingFrustum 的右平面。

Top
获取 BoundingFrustum 的顶平面。

Methods:
Contains(BoundingBox)
确定截锥和边界框之间的交集关系。

Contains(ref BoundingBox)
同上。

Contains(ref BoundingBox, out ContainmentType)
同上

Contains(BoundingFrustum)
同上

下面还有好几个类似的contain方法。

然后是Equals函数,也是稀稀拉拉一大片,作用都是一样的。

FromCamera(Vector3, Vector3, Vector3, Single, Single, Single, Single)

根据透视摄像机参数创建一个新的视锥体

GetCorners()
返回截体的8个角,element0是 Near1(近右下角) ,element1是 Near2(近右上角) ,element2是 Near3(近左上角) ,element3是 Near4(近左下角) ,element4是 Far1(远右下角) ,element5是 Far2(远右上角) ,element6是 Far3(远左上角) ,element7是 Far4(远左下角)

GetHeightAtDepth(Single)
在指定的深度获取截锥的高度。

GetPlane(Int32)
返回与此截锥相关的6个平面中的一个。

GetWidthAtDepth(Single)
在指定的深度获取截锥的宽度。

GetZoomToExtentsShiftDistance(ref BoundingBox)
获得的距离,当添加到相机位置沿观看方向将做的影响缩放范围(缩放适合)操作,使所有通过的点将适合在当前视图。如果返回的值是正值,则相机将朝着观看方向移动(ZoomIn)。如果返回的值是负值,则相机将朝着观察方向(ZoomOut)的相反方向移动。

Intersects(ref BoundingBox)
检查当前 BoundingFrustum 是否与 BoundingBox 相交。

然后是一大堆重载运算符。

String BoundingFrustum::ToString() const
{
return String::Format(TEXT("{}"), *this);
}

重写的toString

void BoundingFrustum::SetMatrix(const Matrix& matrix)

Plane BoundingFrustum::GetPlane(int32 index) const

void BoundingFrustum::GetCorners(Vector3 corners[8]) const
{
corners[0] = Get3PlanesInterPoint(_pNear, _pBottom, _pRight);
corners[1] = Get3PlanesInterPoint(_pNear, _pTop, _pRight);
corners[2] = Get3PlanesInterPoint(_pNear, _pTop, _pLeft);
corners[3] = Get3PlanesInterPoint(_pNear, _pBottom, _pLeft);
corners[4] = Get3PlanesInterPoint(_pFar, _pBottom, _pRight);
corners[5] = Get3PlanesInterPoint(_pFar, _pTop, _pRight);
corners[6] = Get3PlanesInterPoint(_pFar, _pTop, _pLeft);
corners[7] = Get3PlanesInterPoint(_pFar, _pBottom, _pLeft);
}

返回碰撞箱。

void BoundingFrustum::GetBox(BoundingBox& result) const
{
Vector3 corners[8];
GetCorners(corners);
BoundingBox::FromPoints(corners, 8, result);
}

返回Sphere
void BoundingFrustum::GetSphere(BoundingSphere& result) const
{
Vector3 corners[8];
GetCorners(corners);
BoundingSphere::FromPoints(corners, 8, result);
}

float BoundingFrustum::GetWidthAtDepth(float depth) const
{
const float hAngle = PI / 2.0f - Math::Acos(Vector3::Dot(_pNear.Normal, _pLeft.Normal));
return Math::Tan(hAngle) * depth * 2.0f;
}
下面是好几个类似的get方法,差不多。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值