1 #include <osg/Fog>
2 
3 #include <simgear/scene/util/RenderConstants.hxx>
4 #include "GroundLightManager.hxx"
5 
6 
7 
8 using namespace osg;
9 
10 namespace
11 {
makeLightSS()12 StateSet* makeLightSS()
13 {
14     StateSet* ss = new StateSet;
15     Fog* fog = new Fog;
16     fog->setMode(Fog::EXP2);
17     ss->setAttribute(fog);
18     ss->setDataVariance(Object::DYNAMIC);
19     return ss;
20 }
21 }
22 
23 namespace simgear
24 {
GroundLightManager()25 GroundLightManager::GroundLightManager()
26 {
27     runwayLightSS = makeLightSS();
28     taxiLightSS = makeLightSS();
29     groundLightSS = makeLightSS();
30 }
31 
update(const SGUpdateVisitor * updateVisitor)32 void GroundLightManager::update(const SGUpdateVisitor* updateVisitor)
33 {
34     osg::Fog* fog;
35     SGVec4f fogColor = updateVisitor->getFogColor();
36     fog = static_cast<osg::Fog*>(runwayLightSS
37                                  ->getAttribute(StateAttribute::FOG));
38     fog->setColor(toOsg(fogColor));
39     fog->setDensity(updateVisitor->getRunwayFogExp2Density());
40     fog = static_cast<osg::Fog*>(taxiLightSS
41                                  ->getAttribute(StateAttribute::FOG));
42     fog->setColor(toOsg(fogColor));
43     fog->setDensity(updateVisitor->getTaxiFogExp2Density());
44     fog = static_cast<osg::Fog*>(groundLightSS
45                                  ->getAttribute(StateAttribute::FOG));
46     fog->setColor(toOsg(fogColor));
47     fog->setDensity(updateVisitor->getGroundLightsFogExp2Density());
48 }
49 
getLightNodeMask(const SGUpdateVisitor * updateVisitor)50 unsigned GroundLightManager::getLightNodeMask(const SGUpdateVisitor* updateVisitor)
51 {
52     unsigned mask = 0;
53     // The current sun angle in degree
54     float sun_angle = updateVisitor->getSunAngleDeg();
55     if (sun_angle > 85 || updateVisitor->getVisibility() < 5000)
56         mask |= RUNWAYLIGHTS_BIT;
57     // ground lights
58     if ( sun_angle > 95 )
59         mask |= GROUNDLIGHTS2_BIT;
60     if ( sun_angle > 92 )
61         mask |= GROUNDLIGHTS1_BIT;
62     if ( sun_angle > 89 )
63         mask |= GROUNDLIGHTS0_BIT;
64     return mask;
65 }
66 }
67