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.
This commit is contained in:
@@ -25,8 +25,18 @@ CSG::CSG(OperationType operation, Shape *left, Shape *right) : Shape(SHAPE_CSG),
|
||||
}
|
||||
|
||||
Intersect CSG::localIntersect(Ray r)
|
||||
{
|
||||
return this->intersect(r);
|
||||
}
|
||||
|
||||
|
||||
Intersect CSG::intersect(Ray r)
|
||||
{
|
||||
int i;
|
||||
Intersect ret = Intersect();
|
||||
|
||||
if (this->bounds.intesectMe(r))
|
||||
{
|
||||
Intersect leftxs = this->left->intersect(r);
|
||||
Intersect rightxs = this->right->intersect(r);
|
||||
|
||||
@@ -35,14 +45,10 @@ Intersect CSG::localIntersect(Ray r)
|
||||
leftxs.add(rightxs[i]);
|
||||
}
|
||||
|
||||
Intersect ret = this->filterIntersections(leftxs);
|
||||
|
||||
return ret;
|
||||
this->filterIntersections(leftxs, ret);
|
||||
}
|
||||
|
||||
Intersect CSG::intersect(Ray r)
|
||||
{
|
||||
return localIntersect(r);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Tuple CSG::localNormalAt(Tuple point, Intersection *hit)
|
||||
|
||||
Reference in New Issue
Block a user