All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Projector.hh
Go to the documentation of this file.
1 /*
2  * Gazebo - Outdoor Multi-Robot Simulator
3  * Copyright (C) 2003
4  * Nate Koenig
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 /*
22  * Desc: Projector
23  * Author: Jared Duke, (some maintainence by John Hsu)
24  */
25 
26 #ifndef _PROJECTOR_HH_
27 #define _PROJECTOR_HH_
28 
29 #include <string>
30 #include <map>
31 #include <list>
32 
33 #include "rendering/ogre_gazebo.h"
34 
35 #include "msgs/msgs.hh"
36 #include "sdf/sdf.hh"
37 #include "transport/transport.hh"
38 #include "rendering/RenderTypes.hh"
39 
40 namespace gazebo
41 {
42  namespace rendering
43  {
46 
49  class Projector
50  {
53  public: Projector(VisualPtr _parent);
54 
56  public: virtual ~Projector();
57 
60  public: void Load(sdf::ElementPtr _sdf);
61 
64  public: void Load(const msgs::Projector &_msg);
65 
73  public: void Load(const std::string &_name,
74  const math::Pose &_pose = math::Pose(0, 0, 0, 0, 0, 0),
75  const std::string &_textureName = "",
76  double _nearClip = 0.25,
77  double _farClip = 15.0,
78  double _fov = M_PI * 0.25);
79 
82  public: void SetTexture(const std::string &_textureName);
83 
85  public: void Toggle();
86 
89  public: VisualPtr GetParent();
90 
93  public: void SetEnabled(bool _enabled);
94 
95  private: void OnMsg(ConstProjectorPtr &_msg);
96 
97  private: VisualPtr visual;
98  private: transport::NodePtr node;
99  private: transport::SubscriberPtr controlSub;
100 
105  private: class ProjectorFrameListener : public Ogre::FrameListener
106  {
108  public: ProjectorFrameListener();
109 
111  public: virtual ~ProjectorFrameListener();
112 
113  public: void Init(VisualPtr _visual,
114  const std::string &_textureName,
115  double _near = 0.5,
116  double _far = 10,
117  double _fov = 0.785398163);
118 
119  public: virtual bool frameStarted(const Ogre::FrameEvent &_evt);
120 
121  public: void SetTexture(const std::string &_textureName);
122 
123  public: void SetEnabled(bool _enabled);
124  public: void SetUsingShaders(bool _usingShaders);
125 
126  public: void SetPose(const math::Pose &_pose);
127 
128  private: void SetSceneNode();
129 
130  private: void SetFrustumClipDistance(double _near, double _far);
131  private: void SetFrustumFOV(double _fov);
132  private: void AddPassToAllMaterials();
133  private: void AddPassToVisibleMaterials();
134  private: void AddPassToMaterials(std::list<std::string> &_matList);
135  private: void AddPassToMaterial(const std::string &_matName);
136  private: void RemovePassFromMaterials();
137  private: void RemovePassFromMaterial(const std::string &_matName);
138 
139  public: bool enabled;
140  public: bool initialized;
141  private: bool usingShaders;
142 
143  private: std::string nodeName;
144  private: std::string filterNodeName;
145 
146  private: std::string textureName;
147 
148  private: Ogre::Frustum *frustum;
149  private: Ogre::Frustum *filterFrustum;
150  private: Ogre::PlaneBoundedVolumeListSceneQuery *projectorQuery;
151 
152  private: VisualPtr visual;
153 
154  private: Ogre::SceneNode *node;
155  private: Ogre::SceneNode *filterNode;
156  private: Ogre::SceneManager *sceneMgr;
157  private: std::map<std::string, Ogre::Pass*> projectorTargets;
158  };
160 
162  private: ProjectorFrameListener projector;
163  };
165  }
166 }
167 #endif