有没有人知道如何在C++中检索演员的世界空间包围框8分。我正在阅读正式文档,但它有点模糊,因为它从未指定边界对象(FBox、FBoxShpereBounds)是否是局部空间、世界空间、轴对齐等。
我的想法如下,但我不确定这是否正确
UStaticMeshComponent* pMesh = Cast<UStaticMeshComponent>(actor->GetComponentByClass(UStaticMeshComponent::StaticClass()));
if (pMesh)
{
UStaticMesh* pStaticMesh = pMesh->GetStaticMesh();
if (pStaticMesh && pStaticMesh->GetRenderData())
{
FStaticMeshRenderData* pRenderData = pStaticMesh->GetRenderData();
if (pRenderData)
FBoxSphereBounds bounds = pRenderData->Bounds;
bounds.TransformBy(actor>GetActorTransform());
}
}
发布于 2022-11-27 23:07:48
虚幻认为它的边界为轴线对齐(AABB)。这通常在游戏引擎中进行,以提高物理/碰撞子系统的效率。要为一个参与者获得一个AABB,您可以使用以下函数--这在本质上等同于您使用pRenderData->Bounds
所做的工作,但与参与者实现无关。
FBox GetActorAABB(const AActor& Actor)
{
FVector ActorOrigin;
FVector BoxExtent;
// First argument is bOnlyCollidingComponents - if you want to get the bounds for components that don't have collision enabled then set to false
// Last argument is bIncludeFromChildActors. Usually this won't do anything but if we've child-ed an actor - like a gun child-ed to a character then we wouldn't want the gun to be part of the bounds so set to false
Actor.GetActorBounds(true, ActorOrigin, BoxExtent, false);
return FBox::BuildAABB(ActorOrigin, BoxExtent);
}
从上面的代码看,您需要一个定向有界框(OBB),因为您要将转换应用到它。麻烦的是,AABB不真实的维护将是“适合”世界空间轴和你所做的本质上只是旋转的AABB的中心点,这将不会给予一个“紧密配合”的旋转角度远离世界轴。以下两个UE论坛文章提供了一些关于如何做到这一点的见解:
https://forums.unrealengine.com/t/oriented-bounding-box-from-getlocalbounds/241396 https://forums.unrealengine.com/t/object-oriented-bounding-box-from-either-aactor-or-mesh/326571/4
如果您想要一个真正的OBB,那么FOrientedBox
就是您所需要的,但是引擎缺少文档化的实用程序来执行与此结构的交叉或重叠测试,这取决于您要做什么,但是引擎中确实存在这些东西,但是您必须通过源代码搜索才能找到它们。一般情况下,分离轴定理(SAT)可以用来寻找两个凸包形状之间的碰撞,而OBB就是这样定义的。
https://stackoverflow.com/questions/73711191
复制相似问题