CloudyDay
 All Classes Functions Variables Enumerations
ReflectionCamera.h
1 #pragma once
2 #include "Scene.h"
3 #include <osg/FrameBufferObject>
4 #include <osg/TextureCubeMap>
5 
6 namespace osgCloudyDay
7 {
11  class ViewerLightCallbackTest : public osg::NodeCallback
12  {
13  public:
18  {
19 
20  }
21 
25  virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
26  {
27  osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
28  osg::ref_ptr<osg::Geode> geometry = dynamic_cast<osg::Geode*> (node);
29 
30  if(geometry && cv)
31  {
32  osg::Matrixd view(cv->getCurrentCamera()->getViewMatrix());
33  osg::Matrixd invViewMatrix = osg::Matrixd::inverse(view);
34  osg::Matrixd model(*cv->getModelViewMatrix());
35  model = model*invViewMatrix;
36  osg::Matrixd proj(cv->getCurrentCamera()->getProjectionMatrix());
37 
38  geometry->getOrCreateStateSet()->getUniform("ModelMatrix")->set(model);
39  geometry->getOrCreateStateSet()->getUniform("ViewMatrix")->set(view);
40  geometry->getOrCreateStateSet()->getUniform("ProjectionMatrix")->set(proj);
41 
42  geometry->getOrCreateStateSet()->addUniform(new osg::Uniform("v3LightPos", osgCloudyDay::Scene::m_skydome->GetLightPosition()));
43  osgCloudyDay::Scene::m_skydome->SetupUniform(geometry.get()->getOrCreateStateSet());
44  geometry->getOrCreateStateSet()->addUniform(new osg::Uniform("color_tex", 0));
45 
46  #ifdef SHADOW_MAPPING
47  geometry->getOrCreateStateSet()->getUniform("light_proj_matrix")->set(osgCloudyDay::Scene::GetProjectionMatrix_Light());
48  geometry->getOrCreateStateSet()->getUniform("light_mv_matrix")->set(osgCloudyDay::Scene::GetLightCamera()->getViewMatrix());
49  #endif
50  }
51  traverse(node, nv);
52  }
53  };
54 
55 
60  {
61  public:
65  ReflectionCamera(void);
69  ~ReflectionCamera(void);
70 
74  void Initialize();
79  void AddObject(osg::ref_ptr<osg::Geode> geo);
80 
81  osg::ref_ptr<osg::TextureCubeMap> fbo_plane_cube;
82  osg::ref_ptr<osg::TextureCubeMap> fbo_plane_cube_depth;
83 
88  osg::Camera**& GetCamera();
89 
90  protected:
91  osg::Camera** camera_plane_cubemap;
92  };
93 }