aboutsummaryrefslogtreecommitdiff
path: root/src/intersect/intersect.cpp
diff options
context:
space:
mode:
authorDavid Doan <daviddoan@Davids-MacBook-Pro-100.local>2023-12-12 22:29:39 -0500
committerDavid Doan <daviddoan@Davids-MacBook-Pro-100.local>2023-12-12 22:29:39 -0500
commit3f6fd615a96a3cf347557f6f82b5daee767039a0 (patch)
treef8b23b4ca16669c4cd4b3c7348e07e674cc34f6e /src/intersect/intersect.cpp
parent018c2504879f3a585a3f6f0921c9aba22f6a9b76 (diff)
isHit
Diffstat (limited to 'src/intersect/intersect.cpp')
-rw-r--r--src/intersect/intersect.cpp30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/intersect/intersect.cpp b/src/intersect/intersect.cpp
index 2addca4..353508e 100644
--- a/src/intersect/intersect.cpp
+++ b/src/intersect/intersect.cpp
@@ -51,8 +51,10 @@ glm::vec4 intersectCircle(
glm::vec4 intersectCone(
glm::vec4 p,
glm::vec4 d,
- const RenderShapeData& shape)
+ const RenderShapeData& shape,
+ bool &isHit)
{
+ isHit = false;
float t = FINF;
// updated to 4d
// x^2 + y^2 - z^2 - w^2= 0, conic top
@@ -110,14 +112,22 @@ glm::vec4 intersectCone(
t = std::min(t, tyBase);
}
- return t == FINF ? glm::vec4(0.f) : p + t*d;
+ if (t == FINF)
+ {
+ return glm::vec4(0.f);
+ } else {
+ isHit = true;
+ return p + t*d;
+ }
}
glm::vec4 intersectCylinder(
glm::vec4 p,
glm::vec4 d,
- const RenderShapeData& shape)
+ const RenderShapeData& shape,
+ bool &isHit)
{
+ isHit = false;
float t = FINF;
// implicit: x^2 + z^2 = r^2, y + w between -.5, .5 rectuangular side
@@ -179,14 +189,22 @@ glm::vec4 intersectCylinder(
t = std::min(t, tBase);
}
- return t == FINF ? glm::vec4(0.f) : p + t*d;
+ if (t == FINF)
+ {
+ return glm::vec4(0.f);
+ } else {
+ isHit = true;
+ return p + t*d;
+ }
}
glm::vec4 intersectCube (
glm::vec4 p,
glm::vec4 d,
- const RenderShapeData& shape)
+ const RenderShapeData& shape,
+ bool &isHit)
{
+ isHit = false;
// float t = FINF;
float apothem = .5f;
@@ -274,9 +292,11 @@ glm::vec4 intersectCube (
return glm::vec4(0.f);
} else if (tmin > 0) // tmin in front of camera
{
+ isHit = true;
return p + tmin*d;
} else if (tmin <= 0) // tmax in front of camera
{
+ isHit = true;
return p + tmax*d;
}