bool Scene::IsLightObscured(const Point& obj_pos, const Point& light_pos, double obj_radius, Point* impact_point) const { Point dir = light_pos - obj_pos; double len = dir.Normalize(); Scene* pThis = (Scene*) this; // cast-away const Graphic* g = 0; bool obscured = false; ListIter<Graphic> g_iter = pThis->graphics; while (++g_iter && !obscured) { g = g_iter.value(); if (g->CastsShadow() && !g->Hidden() && !g->IsInfinite()) { double gdist = (g->Location() - obj_pos).length(); if (gdist > 0.1 && // different than object being obscured g->Radius() > obj_radius && // larger than object being obscured (g->Radius()*400)/gdist > 10) { // projects to a resonable size Point delta = (g->Location() - light_pos); if (delta.length() > g->Radius() / 100) { // not the object that is emitting the light Point impact; obscured = g->CheckRayIntersection(obj_pos, dir, len, impact, false) ? true : false; if (impact_point) *impact_point = impact; } } else if (obj_radius < 0 && gdist < 0.1) { // special case for camera (needed for cockpits) Point delta = (g->Location() - light_pos); if (delta.length() > g->Radius() / 100) { // not the object that is emitting the light Point impact; obscured = g->CheckRayIntersection(obj_pos, dir, len, impact, false) ? true : false; } } } } g_iter.attach(pThis->foreground); while (++g_iter && !obscured) { g = g_iter.value(); if (g->CastsShadow() && !g->Hidden()) { double gdist = (g->Location() - obj_pos).length(); if (gdist > 0.1 && // different than object being obscured g->Radius() > obj_radius && // larger than object being obscured (g->Radius()*400)/gdist > 10) { // projects to a resonable size Point delta = (g->Location() - light_pos); if (delta.length() > g->Radius() / 100) { // not the object that is emitting the light Point impact; obscured = g->CheckRayIntersection(obj_pos, dir, len, impact, false) ? true : false; if (impact_point) *impact_point = impact; } } else if (obj_radius < 0 && gdist < 0.1) { // special case for camera (needed for cockpits) Point delta = (g->Location() - light_pos); if (delta.length() > g->Radius() / 100) { // not the object that is emitting the light Point impact; obscured = g->CheckRayIntersection(obj_pos, dir, len, impact, false) ? true : false; } } } } return obscured; }