CloudyDay
 All Classes Functions Variables Enumerations
Create2DCloud.h
1 #pragma once
2 #include "Cloud2DState.h"
3 #include "ObjectModel.h"
4 #include "Ground.h"
5 #include "HUD.h"
6 #include "PostProcess.h"
7 #include "AtmosphereMie.h"
8 #include "AtmosphereHimmel.h"
9 #include "TerrainMIE.h"
10 #include "TerrainHimmel.h"
11 #include "TerrainGeometry.h"
12 #include "ReflectionCamera.h"
13 #include "CloudCreator.h"
14 #include "Atmosphereprecompute.h"
15 
16 #include <osg/PolygonMode>
17 #include <osg/ShapeDrawable>
18 #include <osg/Depth>
19 #include <osg/Program>
20 #include <osg/Shader>
21 #include <osg/Uniform>
22 
23 namespace osgCloudyDay
24 {
28  class PerlinNoiseCallback : public osg::NodeCallback
29  {
30  public:
35  {
36 
37  }
38 
42  virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
43  {
44  osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
45  osg::ref_ptr<osg::Geode> geometry = dynamic_cast<osg::Geode*> (node);
46 
47  if(geometry && cv)
48  {
49  osg::RefMatrixd* m = cv->getModelViewMatrix();
50  osg::Matrixd viewMatrix = cv->getCurrentCamera()->getViewMatrix();
51  osg::Matrixd invViewMatrix = osg::Matrixd::inverse(viewMatrix);
52  osg::Matrixd worldmat = invViewMatrix * (*m);
53  osg::Matrixd invWorldMatrix = osg::Matrixd::inverse(worldmat);
54 
55  geometry->getOrCreateStateSet()->getUniform("ProjectionMatrix")->set(cv->getCurrentCamera()->getProjectionMatrix());
56  geometry->getOrCreateStateSet()->getUniform("ViewMatrix")->set(cv->getCurrentCamera()->getViewMatrix());
57  geometry->getOrCreateStateSet()->getUniform("ModelMatrix")->set(worldmat);
58  geometry->getOrCreateStateSet()->getUniform("NormalMatrix")->set(invWorldMatrix);
59  geometry->getOrCreateStateSet()->getUniform("LightMatrix")->set(Scene::GetLightCamera()->getViewMatrix());
60  }
61  traverse(node, nv);
62  }
63  };
64 
69  {
70  public:
74  Create2DCloud(void);
78  ~Create2DCloud(void);
79 
84  void Initialize(std::vector<Cloud2DState> cloud2dstates);
89  osg::Node* GetNode();
94  osg::Node* GetNodeLight();
100  osg::Node* GetReflectionCamera(int at);
101 
102  protected:
103  std::vector<osg::ref_ptr<osg::Geode>> m_geodes;
104  std::vector<osg::ref_ptr<osg::Geode>> m_light_geodes;
105 
106  osg::Group* m_node_scene;
107  osg::Group* m_node_light;
108  osg::Group** m_reflection;
109  };
110 }