From b02b507675f97633ced02d6fb1c53d56d5545036 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 19 Jun 2020 18:39:21 -0400 Subject: [PATCH] CRayCollisionTester: Tidy up code a little --- src/Core/CRayCollisionTester.cpp | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/Core/CRayCollisionTester.cpp b/src/Core/CRayCollisionTester.cpp index d84edbb3..1757f611 100644 --- a/src/Core/CRayCollisionTester.cpp +++ b/src/Core/CRayCollisionTester.cpp @@ -6,14 +6,11 @@ CRayCollisionTester::CRayCollisionTester(const CRay& rkRay) { } -CRayCollisionTester::~CRayCollisionTester() -{ -} +CRayCollisionTester::~CRayCollisionTester() = default; void CRayCollisionTester::AddNode(CSceneNode *pNode, uint32 ComponentIndex, float Distance) { - mBoxIntersectList.emplace_back(SRayIntersection()); - SRayIntersection& rIntersection = mBoxIntersectList.back(); + SRayIntersection& rIntersection = mBoxIntersectList.emplace_back(); rIntersection.pNode = pNode; rIntersection.ComponentIndex = ComponentIndex; rIntersection.Distance = Distance; @@ -34,36 +31,34 @@ void CRayCollisionTester::AddNodeModel(CSceneNode *pNode, CBasicModel *pModel) SRayIntersection CRayCollisionTester::TestNodes(const SViewInfo& rkViewInfo) { // Sort nodes by distance from ray - mBoxIntersectList.sort( - [](const SRayIntersection& rkLeft, const SRayIntersection& rkRight) -> bool - { - return (rkLeft.Distance < rkRight.Distance); + mBoxIntersectList.sort([](const auto& rkLeft, const auto& rkRight) { + return rkLeft.Distance < rkRight.Distance; }); // Now do more precise intersection tests on geometry SRayIntersection Result; 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 // 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; // Otherwise, more intersection tests... 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 ((!Result.Hit) || (MidResult.Distance <= Result.Distance)) + if (!Result.Hit || MidResult.Distance <= Result.Distance) Result = MidResult; } } - if (Result.Hit) Result.HitPoint = mRay.PointOnRay(Result.Distance); + if (Result.Hit) + Result.HitPoint = mRay.PointOnRay(Result.Distance); + return Result; }