MovableText.hh
00001 /*
00002  * Copyright 2011 Nate Koenig & Andrew Howard
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  *
00016 */
00017 /* Desc: Middleman between OGRE and Gazebo
00018  * Author: indepedentCreations@gmail.com
00019  * Date: 13 Feb 2006
00020  */
00021 
00022 #ifndef MOVABLETEXT_HH
00023 #define MOVABLETEXT_HH
00024 
00025 // TODO: remove this line
00026 #include <OGRE/OgreMovableObject.h>
00027 #include <OGRE/OgreRenderable.h>
00028 
00029 #include <string>
00030 
00031 #include "common/CommonTypes.hh"
00032 #include "common/Color.hh"
00033 #include "math/MathTypes.hh"
00034 
00035 namespace boost
00036 {
00037   class recursive_mutex;
00038 }
00039 
00040 namespace gazebo
00041 {
00042     namespace rendering
00043   {
00046  
00048     class MovableText : public Ogre::MovableObject, public Ogre::Renderable
00049     {
00051       public: enum HorizAlign {H_LEFT, H_CENTER};
00052     
00054       public: enum VertAlign  {V_BELOW, V_ABOVE};
00055     
00057       public: MovableText();
00058     
00060       public: virtual ~MovableText();
00061     
00063       public: void Load(const std::string &_name, 
00064                         const std::string &_text, 
00065                         const std::string &_fontName = "Arial", 
00066                         float _charHeight = 1.0,
00067                         const common::Color &_color = common::Color::White);
00068     
00070       public: void SetFontName(const std::string &font);
00071               
00073       public: const std::string &GetFont() const;
00074     
00076       public: void SetText(const std::string & caption);
00077     
00079       public: const std::string &GetText() const;
00080     
00082       public: void SetColor(const common::Color &_color);
00083     
00085       public: const common::Color &GetColor() const; 
00086     
00088       public: void SetCharHeight(float height);
00089     
00091       public: float GetCharHeight() const;
00092     
00094       public:void SetSpaceWidth(float width);
00095     
00097       public: float GetSpaceWidth() const;
00098     
00100       public: void SetTextAlignment(const HorizAlign &hAlign, 
00101                                     const VertAlign &vAlign); 
00102     
00104       public: void SetBaseline(float height);
00105     
00107       public: float GetBaseline() const;
00108     
00110       public: void SetShowOnTop(bool show);
00111     
00113       public: bool GetShowOnTop() const;
00114     
00116       public: math::Box GetAABB();
00117    
00119       public: void Update();
00120 
00122       //         Renderable instances
00123       public: virtual void visitRenderables(Ogre::Renderable::Visitor* visitor,
00124                   bool debug = false );
00125   
00127       protected: void _setupGeometry();
00128     
00130       protected: void _updateColors();
00131     
00133       protected: void getWorldTransforms(Ogre::Matrix4 *xform) const;
00134     
00136       protected: float getBoundingRadius() const;
00137     
00139       protected: float getSquaredViewDepth(const Ogre::Camera *cam) const;
00140     
00141       private: std::string fontName;
00142       private: std::string text;
00143     
00144       private: common::Color color;
00145       private: Ogre::RenderOperation renderOp;
00146       private: Ogre::AxisAlignedBox *aabb;
00147       private: Ogre::LightList lightList;
00148     
00149       private: float charHeight;
00150     
00151       private: bool needUpdate;
00152     
00153       private: float radius;
00154     
00155       private: Ogre::Camera *camera;
00156       private: Ogre::RenderWindow *renderWindow;
00157       private: Ogre::Font *font;
00158       private: Ogre::MaterialPtr material;
00159       private: Ogre::MaterialPtr backgroundMaterial;
00160  
00161       private: float viewportAspectCoef;
00162       private: float spaceWidth;
00163       private: bool updateColors;
00164       private: VertAlign vertAlign;
00165       private: HorizAlign horizAlign;
00166       private: bool onTop;
00167       private: float baseline;
00168    
00169       private: const Ogre::Quaternion &getWorldOrientation(void) const;
00170       private: const Ogre::Vector3 &getWorldPosition(void) const;
00171       private: const Ogre::AxisAlignedBox &getBoundingBox(void) const;
00172       private: const Ogre::String &getMovableType() const;
00173     
00174       private: void _notifyCurrentCamera(Ogre::Camera *cam);
00175       private: void _updateRenderQueue(Ogre::RenderQueue* queue);
00176     
00178       protected: void getRenderOperation(Ogre::RenderOperation &op);
00179     
00181       protected: const Ogre::MaterialPtr &getMaterial(void) const;
00182     
00184       protected: const Ogre::LightList &getLights(void) const; 
00185 
00186       private: bool dirty;
00187   
00188       private: boost::recursive_mutex *mutex;
00189       private: Ogre::SimpleRenderable *renderable;
00190     };
00192   }
00193 
00194 }
00195 #endif