ADD: BVH Selection triangle

This commit is contained in:
2025-11-19 23:33:05 +09:00
parent ac35de6104
commit 0fe7c0f975
10 changed files with 116 additions and 84 deletions

View File

@@ -89,15 +89,21 @@ namespace
return false;
}
float tHit = (tMin >= 0.0f) ? tMin : tMax;
glm::vec3 localHit = localOrigin + tHit * localDir;
glm::vec3 worldHit = glm::vec3(worldTransform * glm::vec4(localHit, 1.0f));
if (glm::dot(worldHit - rayOrigin, rayDir) <= 0.0f)
// Choose the closest intersection in front of the ray origin.
// If the ray starts inside the box (tMin <= 0), use the exit point tMax.
float tHit = tMin;
if (tHit <= 0.0f)
{
tHit = tMax;
}
if (tHit <= 0.0f)
{
return false;
}
glm::vec3 localHit = localOrigin + tHit * localDir;
glm::vec3 worldHit = glm::vec3(worldTransform * glm::vec4(localHit, 1.0f));
outWorldHit = worldHit;
return true;
}