CloudyDay
 All Classes Functions Variables Enumerations
Atmosphere.h
1 #pragma once
2 #include "Scene.h"
3 #include "Fog.h"
4 #include <osg/PolygonMode>
5 #include <osg/ShapeDrawable>
6 
7 namespace osgCloudyDay
8 {
12  class AthmosphereCallback : public osg::NodeCallback
13  {
14  public:
19  {
20 
21  }
22 
26  virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
27  {
28  osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
29  osg::ref_ptr<osg::Geode> geometry = dynamic_cast<osg::Geode*> (node);
30 
31  if(geometry && cv)
32  {
33  osg::Matrixd view(cv->getCurrentCamera()->getViewMatrix());
34  osg::Matrixd invViewMatrix = osg::Matrixd::inverse(view);
35  osg::Matrixd modelview(*cv->getModelViewMatrix());
36  osg::Matrixd model = modelview*invViewMatrix;
37  osg::Matrixd proj(cv->getCurrentCamera()->getProjectionMatrix());
38 
39  geometry->getOrCreateStateSet()->getUniform("ModelMatrix")->set(model);
40  geometry->getOrCreateStateSet()->getUniform("ViewMatrix")->set(view);
41  geometry->getOrCreateStateSet()->getUniform("ProjectionMatrix")->set(proj);
42 
43  geometry->getOrCreateStateSet()->getUniform("light_mv_matrix")->set(Scene::GetLightCamera()->getViewMatrix());
44  }
45  traverse(node, nv);
46  }
47  };
48 
52  class Atmosphere
53  {
54  public:
58  Atmosphere(void);
62  virtual ~Atmosphere(void)=0;
63 
67  virtual void Initialize() = 0;
68 
73  osg::ref_ptr<osg::Geode> GetNode();
74 
79  void SetFog(Fog* fog);
80 
81  protected:
82  Fog* m_fog;
83 
84  osg::ref_ptr<osg::StateSet> nodessSkydome;
85  osg::ref_ptr<osg::Geode> athmosphere;
86  };
87 }