bool CSGTree::intersect(const ray& r, isect& i) const{ if (!root)return false; Segments inters = root->intersectLocal(r); SegmentPoint sp; if(!inters.firstPositive(sp))return false; i.t = sp.t; if (sp.isRight){//right - out if (sp.normal*r.getDirection() > RAY_EPSILON)i.N = sp.normal; else i.N = -sp.normal; } else {//left - in if (sp.normal*r.getDirection() > RAY_EPSILON)i.N = -sp.normal; else i.N = sp.normal; } return true; }