CRayCollisionTester: Tidy up code a little
This commit is contained in:
parent
40f0fbca4c
commit
b02b507675
|
@ -6,14 +6,11 @@ CRayCollisionTester::CRayCollisionTester(const CRay& rkRay)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CRayCollisionTester::~CRayCollisionTester()
|
CRayCollisionTester::~CRayCollisionTester() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CRayCollisionTester::AddNode(CSceneNode *pNode, uint32 ComponentIndex, float Distance)
|
void CRayCollisionTester::AddNode(CSceneNode *pNode, uint32 ComponentIndex, float Distance)
|
||||||
{
|
{
|
||||||
mBoxIntersectList.emplace_back(SRayIntersection());
|
SRayIntersection& rIntersection = mBoxIntersectList.emplace_back();
|
||||||
SRayIntersection& rIntersection = mBoxIntersectList.back();
|
|
||||||
rIntersection.pNode = pNode;
|
rIntersection.pNode = pNode;
|
||||||
rIntersection.ComponentIndex = ComponentIndex;
|
rIntersection.ComponentIndex = ComponentIndex;
|
||||||
rIntersection.Distance = Distance;
|
rIntersection.Distance = Distance;
|
||||||
|
@ -34,36 +31,34 @@ void CRayCollisionTester::AddNodeModel(CSceneNode *pNode, CBasicModel *pModel)
|
||||||
SRayIntersection CRayCollisionTester::TestNodes(const SViewInfo& rkViewInfo)
|
SRayIntersection CRayCollisionTester::TestNodes(const SViewInfo& rkViewInfo)
|
||||||
{
|
{
|
||||||
// Sort nodes by distance from ray
|
// Sort nodes by distance from ray
|
||||||
mBoxIntersectList.sort(
|
mBoxIntersectList.sort([](const auto& rkLeft, const auto& rkRight) {
|
||||||
[](const SRayIntersection& rkLeft, const SRayIntersection& rkRight) -> bool
|
return rkLeft.Distance < rkRight.Distance;
|
||||||
{
|
|
||||||
return (rkLeft.Distance < rkRight.Distance);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Now do more precise intersection tests on geometry
|
// Now do more precise intersection tests on geometry
|
||||||
SRayIntersection Result;
|
SRayIntersection Result;
|
||||||
Result.Hit = false;
|
Result.Hit = false;
|
||||||
|
|
||||||
for (auto iNode = mBoxIntersectList.begin(); iNode != mBoxIntersectList.end(); iNode++)
|
for (const auto& rIntersection : mBoxIntersectList)
|
||||||
{
|
{
|
||||||
SRayIntersection& rIntersection = *iNode;
|
|
||||||
|
|
||||||
// If we have a result, and the distance for the bounding box hit is further than the current result distance
|
// If we have a result, and the distance for the bounding box hit is further than the current result distance
|
||||||
// then we know that every remaining node is further away and there is no chance of finding a closer hit.
|
// then we know that every remaining node is further away and there is no chance of finding a closer hit.
|
||||||
if ((Result.Hit) && (Result.Distance < rIntersection.Distance))
|
if (Result.Hit && Result.Distance < rIntersection.Distance)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Otherwise, more intersection tests...
|
// Otherwise, more intersection tests...
|
||||||
CSceneNode *pNode = rIntersection.pNode;
|
CSceneNode *pNode = rIntersection.pNode;
|
||||||
SRayIntersection MidResult = pNode->RayNodeIntersectTest(mRay, rIntersection.ComponentIndex, rkViewInfo);
|
const SRayIntersection MidResult = pNode->RayNodeIntersectTest(mRay, rIntersection.ComponentIndex, rkViewInfo);
|
||||||
|
|
||||||
if (MidResult.Hit)
|
if (MidResult.Hit)
|
||||||
{
|
{
|
||||||
if ((!Result.Hit) || (MidResult.Distance <= Result.Distance))
|
if (!Result.Hit || MidResult.Distance <= Result.Distance)
|
||||||
Result = MidResult;
|
Result = MidResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Result.Hit) Result.HitPoint = mRay.PointOnRay(Result.Distance);
|
if (Result.Hit)
|
||||||
|
Result.HitPoint = mRay.PointOnRay(Result.Distance);
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue