This commit is contained in:
Georg Hagen
2025-01-06 15:27:42 +01:00
parent 8caf546cad
commit 46c1d1f18f
2 changed files with 20 additions and 9 deletions

View File

@@ -170,31 +170,34 @@ namespace OpenVulkano::Scene
if (roots == 0) return 0;
SortPair(x1, x2);
bool calcP2 = false;
if (roots == 1)
{
if (x1 < 0) return 0; // ray intersects sphere behind the origin
p2 = p1;
}
else
{
if (x1 < 0 && x2 < 0) return 0; // ray intersects sphere behind the origin
if (x1 >= 0 && x2 >= 0)
{
p2.point = m_origin + x2 * m_dir;
p2.distance2 = distance2(m_origin, p2.point);
p2.normal = normalize(p2.point - center);
calcP2 = true;
}
else
{
--roots;
if (x1 < 0) x1 = x2;
p2 = p1;
}
}
p1.point = m_origin + x1 * m_dir;
p1.distance2 = distance2(m_origin, p1.point);
p1.normal = normalize(p1.point - center);
if (calcP2)
{
p2.point = m_origin + x2 * m_dir;
p2.distance2 = distance2(m_origin, p2.point);
p2.normal = normalize(p2.point - center);
}
else p2 = p1;
return roots;
}