]> git.mxchange.org Git - simgear.git/blob - simgear/scene/tgdb/GroundLightManager.cxx
Merge branch 'maint' into next
[simgear.git] / simgear / scene / tgdb / GroundLightManager.cxx
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 {
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 {
25 GroundLightManager::GroundLightManager()
26 {
27     osg::Fog* fog;
28     runwayLightSS = makeLightSS();
29     taxiLightSS = makeLightSS();
30     groundLightSS = makeLightSS();
31 }
32
33 void GroundLightManager::update(const SGUpdateVisitor* updateVisitor)
34 {
35     osg::Fog* fog;
36     SGVec4f fogColor = updateVisitor->getFogColor();
37     fog = static_cast<osg::Fog*>(runwayLightSS
38                                  ->getAttribute(StateAttribute::FOG));
39     fog->setColor(fogColor.osg());
40     fog->setDensity(updateVisitor->getRunwayFogExp2Density());
41     fog = static_cast<osg::Fog*>(taxiLightSS
42                                  ->getAttribute(StateAttribute::FOG));
43     fog->setColor(fogColor.osg());
44     fog->setDensity(updateVisitor->getTaxiFogExp2Density());
45     fog = static_cast<osg::Fog*>(groundLightSS
46                                  ->getAttribute(StateAttribute::FOG));
47     fog->setColor(fogColor.osg());
48     fog->setDensity(updateVisitor->getGroundLightsFogExp2Density());
49 }
50
51 unsigned GroundLightManager::getLightNodeMask(const SGUpdateVisitor* updateVisitor)
52 {
53     unsigned mask = 0;
54     // The current sun angle in degree
55     float sun_angle = updateVisitor->getSunAngleDeg();
56     if (sun_angle > 85 || updateVisitor->getVisibility() < 5000)
57         mask |= RUNWAYLIGHTS_BIT;
58     // ground lights
59     if ( sun_angle > 95 )
60         mask |= GROUNDLIGHTS2_BIT;
61     if ( sun_angle > 92 )
62         mask |= GROUNDLIGHTS1_BIT;
63     if ( sun_angle > 89 )
64         mask |= GROUNDLIGHTS0_BIT;
65     return mask;
66 }
67 }