From 3f6fd615a96a3cf347557f6f82b5daee767039a0 Mon Sep 17 00:00:00 2001 From: David Doan Date: Tue, 12 Dec 2023 22:29:39 -0500 Subject: isHit --- src/intersect/intersect.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'src/intersect/intersect.cpp') 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; } -- cgit v1.2.3-70-g09d2