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 
101  private: class ProjectorFrameListener : public Ogre::FrameListener
102  {
103  public: ProjectorFrameListener();
104  public: virtual ~ProjectorFrameListener();
105  public: void Init(VisualPtr _visual,
106  const std::string &_textureName,
107  double _near = 0.5,
108  double _far = 10,
109  double _fov = 0.785398163);
110 
111  public: bool frameStarted(const Ogre::FrameEvent &_evt);
112 
113  public: void SetTexture(const std::string &_textureName);
114 
115  public: void SetEnabled(bool _enabled);
116  public: void SetUsingShaders(bool _usingShaders);
117 
118  public: void SetPose(const math::Pose &_pose);
119 
120  private: void SetSceneNode();
121 
122  private: void SetFrustumClipDistance(double _near, double _far);
123  private: void SetFrustumFOV(double _fov);
124  private: void AddPassToAllMaterials();
125  private: void AddPassToVisibleMaterials();
126  private: void AddPassToMaterials(std::list<std::string> &_matList);
127  private: void AddPassToMaterial(const std::string &_matName);
128  private: void RemovePassFromMaterials();
129  private: void RemovePassFromMaterial(const std::string &_matName);
130 
131  public: bool enabled;
132  public: bool initialized;
133  private: bool usingShaders;
134 
135  private: std::string nodeName;
136  private: std::string filterNodeName;
137 
138  private: std::string textureName;
139 
140  private: Ogre::Frustum *frustum;
141  private: Ogre::Frustum *filterFrustum;
142  private: Ogre::PlaneBoundedVolumeListSceneQuery *projectorQuery;
143 
144  private: VisualPtr visual;
145 
146  private: Ogre::SceneNode *node;
147  private: Ogre::SceneNode *filterNode;
148  private: Ogre::SceneManager *sceneMgr;
149  private: std::map<std::string, Ogre::Pass*> projectorTargets;
150  };
151 
152  private: ProjectorFrameListener projector;
153  };
155  }
156 }
157 #endif