even more boilerplate
This commit is contained in:
+18
-2
@@ -58,6 +58,22 @@ void BVH::generate()
|
|||||||
|
|
||||||
std::optional<IntersectionInfo> BVH::traceRay(Ray ray)
|
std::optional<IntersectionInfo> BVH::traceRay(Ray ray)
|
||||||
{
|
{
|
||||||
|
auto results = generateIntersections(hierarchy, ray);
|
||||||
|
float closestT = std::numeric_limits<float>::max();
|
||||||
|
IntersectionInfo info;
|
||||||
|
for (uint32_t i = 0; i < results.size(); ++i)
|
||||||
|
{
|
||||||
|
if (results[i].t < closestT)
|
||||||
|
{
|
||||||
|
closestT = results[i].t;
|
||||||
|
info = results[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (closestT < std::numeric_limits<float>::max())
|
||||||
|
{
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<IntersectionInfo> BVH::generateIntersections(PNode& currentNode, Ray ray)
|
std::vector<IntersectionInfo> BVH::generateIntersections(PNode& currentNode, Ray ray)
|
||||||
@@ -81,9 +97,9 @@ std::vector<IntersectionInfo> BVH::generateIntersections(PNode& currentNode, Ray
|
|||||||
auto leftResults = generateIntersections(currentNode->left, ray);
|
auto leftResults = generateIntersections(currentNode->left, ray);
|
||||||
auto rightResults = generateIntersections(currentNode->right, ray);
|
auto rightResults = generateIntersections(currentNode->right, ray);
|
||||||
|
|
||||||
for(auto it : rightResults)
|
for (auto& it : rightResults)
|
||||||
{
|
{
|
||||||
leftResults.push_back(it);
|
leftResults.push_back(std::move(it));
|
||||||
}
|
}
|
||||||
return leftResults;
|
return leftResults;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user