From 22a96dce295358aa9b2415c855ed85e4bca08e4a Mon Sep 17 00:00:00 2001 From: vonhyou Date: Tue, 20 Feb 2024 20:45:20 -0500 Subject: [PATCH] sync: try to impl intersection detection for rectangles --- src/Geometry.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Geometry.cc b/src/Geometry.cc index 5eaab26..56ffa65 100644 --- a/src/Geometry.cc +++ b/src/Geometry.cc @@ -13,4 +13,16 @@ bool Sphere::intersect(const Ray &r) const { return b * b - 4 * a * c >= 0; } -bool Rectangle::intersect(const Ray &r) const { return false; } +bool Rectangle::intersect(const Ray &r) const { + Vector3f p1p2 = corners.col(1) - corners.col(0); + Vector3f p2p3 = corners.col(2) - corners.col(1); + Vector3f p3p1 = corners.col(0) - corners.col(2); + Vector3f p1p4 = corners.col(3) - corners.col(0); + Vector3f p4p3 = corners.col(2) - corners.col(3); + + Vector3f n = -p1p2.cross(p2p3) / p1p2.cross(p2p3).norm(); + + if (n.dot(r.getOrigin() + r.getDirection()) == 0) { + } + return false; +}