00001 #include <osg/Fog>
00002
00003 #include <simgear/scene/util/RenderConstants.hxx>
00004 #include "GroundLightManager.hxx"
00005
00006
00007
00008 using namespace osg;
00009
00010 namespace
00011 {
00012 StateSet* makeLightSS()
00013 {
00014 StateSet* ss = new StateSet;
00015 Fog* fog = new Fog;
00016 fog->setMode(Fog::EXP2);
00017 ss->setAttribute(fog);
00018 ss->setDataVariance(Object::DYNAMIC);
00019 return ss;
00020 }
00021 }
00022
00023 namespace simgear
00024 {
00025 GroundLightManager::GroundLightManager()
00026 {
00027 runwayLightSS = makeLightSS();
00028 taxiLightSS = makeLightSS();
00029 groundLightSS = makeLightSS();
00030 }
00031
00032 void GroundLightManager::update(const SGUpdateVisitor* updateVisitor)
00033 {
00034 osg::Fog* fog;
00035 SGVec4f fogColor = updateVisitor->getFogColor();
00036 fog = static_cast<osg::Fog*>(runwayLightSS
00037 ->getAttribute(StateAttribute::FOG));
00038 fog->setColor(toOsg(fogColor));
00039 fog->setDensity(updateVisitor->getRunwayFogExp2Density());
00040 fog = static_cast<osg::Fog*>(taxiLightSS
00041 ->getAttribute(StateAttribute::FOG));
00042 fog->setColor(toOsg(fogColor));
00043 fog->setDensity(updateVisitor->getTaxiFogExp2Density());
00044 fog = static_cast<osg::Fog*>(groundLightSS
00045 ->getAttribute(StateAttribute::FOG));
00046 fog->setColor(toOsg(fogColor));
00047 fog->setDensity(updateVisitor->getGroundLightsFogExp2Density());
00048 }
00049
00050 unsigned GroundLightManager::getLightNodeMask(const SGUpdateVisitor* updateVisitor)
00051 {
00052 unsigned mask = 0;
00053
00054 float sun_angle = updateVisitor->getSunAngleDeg();
00055 if (sun_angle > 85 || updateVisitor->getVisibility() < 5000)
00056 mask |= RUNWAYLIGHTS_BIT;
00057
00058 if ( sun_angle > 95 )
00059 mask |= GROUNDLIGHTS2_BIT;
00060 if ( sun_angle > 92 )
00061 mask |= GROUNDLIGHTS1_BIT;
00062 if ( sun_angle > 89 )
00063 mask |= GROUNDLIGHTS0_BIT;
00064 return mask;
00065 }
00066 }