From 1510de3b36aba1e6f42e382ee5a341ab28c7dd9a Mon Sep 17 00:00:00 2001 From: Godzil Date: Mon, 9 Mar 2020 13:45:57 +0000 Subject: [PATCH] Change CSG to derive the intersect function and do the calculation there instead of the local one. Also use the bounding box to reject ray that don't it that CSG element. --- source/shapes/csg.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/source/shapes/csg.cpp b/source/shapes/csg.cpp index fac6852..dcea4c5 100644 --- a/source/shapes/csg.cpp +++ b/source/shapes/csg.cpp @@ -26,23 +26,29 @@ CSG::CSG(OperationType operation, Shape *left, Shape *right) : Shape(SHAPE_CSG), Intersect CSG::localIntersect(Ray r) { - int i; - Intersect leftxs = this->left->intersect(r); - Intersect rightxs = this->right->intersect(r); - - for(i = 0; i < rightxs.count(); i++) - { - leftxs.add(rightxs[i]); - } - - Intersect ret = this->filterIntersections(leftxs); - - return ret; + return this->intersect(r); } + Intersect CSG::intersect(Ray r) { - return localIntersect(r); + int i; + Intersect ret = Intersect(); + + if (this->bounds.intesectMe(r)) + { + Intersect leftxs = this->left->intersect(r); + Intersect rightxs = this->right->intersect(r); + + for (i = 0 ; i < rightxs.count() ; i++) + { + leftxs.add(rightxs[i]); + } + + this->filterIntersections(leftxs, ret); + } + + return ret; } Tuple CSG::localNormalAt(Tuple point, Intersection *hit)