vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Mirror.h
Go to the documentation of this file.
1 #include <vrecko/Ability.h>
2 
3 #include <osg/MatrixTransform>
4 #include <osg/Geode>
5 #include <osg/Geometry>
6 #include <osgUtil/UpdateVisitor>
7 #include <osg/Texture2D>
8 
9 #include <osg/Node>
10 
11 #include <osgUtil/TransformCallback>
12 #include <osgUtil/RenderStage>
13 #include <osgUtil/SmoothingVisitor>
14 #include <osgUtil/CullVisitor>
15 
16 
17 using namespace vrecko;
18 
19 namespace behindO {
20 
21 class MyUpdateCallback : public osg::NodeCallback
22 {
23 public:
24 
25  MyUpdateCallback(osg::Node* subgraph):
26  _subgraph(subgraph) {}
27 
28  virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
29  {
30  // traverse the subgraph to update any nodes.
31  if (_subgraph.valid()) _subgraph->accept(*nv);
32 
33  // must traverse the Node's subgraph
34  traverse(node,nv);
35  }
36 
37  osg::ref_ptr<osg::Node> _subgraph;
38 };
39 
40 class MyCullCallback : public osg::NodeCallback
41 {
42 public:
43 
44  MyCullCallback(osg::Node* subgraph,osg::Texture2D* texture):
45  _subgraph(subgraph),
46  _texture(texture),
47  _localState(new osg::StateSet),
48  frame(true),
49  dir(true) {}
50 
51  MyCullCallback(osg::Node* subgraph,osg::Image* image):
52  _subgraph(subgraph),
53  _image(image),
54  _localState(new osg::StateSet),
55  frame(true),
56  dir(true) {}
57 
58  virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
59  {
60  if (frame) {
61  osgUtil::CullVisitor* cullVisitor = dynamic_cast<osgUtil::CullVisitor*>(nv);
62  if (cullVisitor && (_texture.valid()|| _image.valid()) && _subgraph.valid()) {
63  doPreRender(*node,*cullVisitor);
64 
65  // must traverse the subgraph
66  traverse(node,nv);
67  } else {
68  // must traverse the subgraph
69  traverse(node,nv);
70  }
71  }
72 
73  frame = !frame;
74  }
75 
76  void doPreRender(osg::Node& node, osgUtil::CullVisitor& cv);
77 
78  osg::ref_ptr<osg::Node> _subgraph;
79  osg::ref_ptr<osg::Texture2D> _texture;
80  osg::ref_ptr<osg::Image> _image;
81  osg::ref_ptr<osg::StateSet> _localState;
82  bool frame;
83 
84  osg::Vec3 camera_position, camera_direction, camera_center, old_camera_direction;
85  osg::Vec3 up_vector;
87  bool dir;
88 };
89 
90 
91 
92 class Mirror: public Ability {
93  public:
94  Mirror();
95  ~Mirror() {};
96 
97  void preInitialize(void);
98  void update(void);
99 
100  protected:
101  osg::Geode *_geode;
102  osg::Geometry *_geom;
103  osgUtil::UpdateVisitor *_updateVisitor;
104  osg::Texture2D* _texture;
105  osg::MatrixTransform *_parent, *mirror_plane_transf;
106 
107  osg::Vec3 _mirror_normal, _eye_position, _center_position;
108 
109  bool _first;
110 
111  osg::Vec3Array* mirror_plane_vertices;
113 
114 // osg::Light* light;
115 
116 };
117 
118 }
119 
120 //$Id: Mirror.h 189 2011-07-12 08:31:31Z xchmeli1 $