virtual bool intersect(Ray const & ray, Hitpoint & hit) const { //we want to find the farthest entrace and closest exit to the box //if the exit is closer than the entrance, there is no hit const size_t vecDim = 3; float entrance = 0.0f; float exit = hit.getParameter(); Vector3 normal = Vector3(0,0,0); for(int i=0; i exit; if(tooClose || tooFar) return false; bool foundNewEntrance = closestHit > entrance; entrance = foundNewEntrance ? closestHit : entrance; bool foundNewExit = farthestHit < exit; exit = foundNewExit ? farthestHit : exit; if(foundNewEntrance) { normal = Vector3(0,0,0); normal[i] = ray.getDirection()[i] * -1; normal.normalize(); } } hit.setMaterialId( this->getMaterialId() ); hit.setNormal(normal); hit.setParameter(entrance); return true; }