00001 /* 00002 * Copyright (c) 2008, Willow Garage, Inc. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of the Willow Garage, Inc. nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 // Adapted from: http://www.ogre3d.org/wiki/index.php/MovableText 00031 // Original authors: 00032 /* 00033 * File: MovableText.h 00034 * 00035 * description: This create create a billboarding object that display a text. 00036 * 00037 * @author 2003 by cTh see gavocanov@rambler.ru 00038 * @update 2006 by barraq see nospam@barraquand.com 00039 */ 00040 00041 #ifndef OGRE_TOOLS_MOVABLE_TEXT_H 00042 #define OGRE_TOOLS_MOVABLE_TEXT_H 00043 00044 #include <OgreMovableObject.h> 00045 #include <OgreRenderable.h> 00046 #include <OgreVector3.h> 00047 #include <OgreQuaternion.h> 00048 #include <OgreSharedPtr.h> 00049 00050 00051 namespace Ogre 00052 { 00053 class RenderQueue; 00054 class Camera; 00055 class Font; 00056 } 00057 00058 namespace rviz 00059 { 00060 00061 class MovableText : public Ogre::MovableObject, public Ogre::Renderable 00062 { 00063 /******************************** MovableText data ****************************/ 00064 public: 00065 enum HorizontalAlignment 00066 { 00067 H_LEFT, H_CENTER 00068 }; 00069 enum VerticalAlignment 00070 { 00071 V_BELOW, V_ABOVE, V_CENTER 00072 }; 00073 00074 protected: 00075 Ogre::String mFontName; 00076 Ogre::String mType; 00077 Ogre::String mName; 00078 Ogre::String mCaption; 00079 HorizontalAlignment mHorizontalAlignment; 00080 VerticalAlignment mVerticalAlignment; 00081 00082 Ogre::ColourValue mColor; 00083 Ogre::RenderOperation mRenderOp; 00084 Ogre::AxisAlignedBox mAABB; 00085 Ogre::LightList mLList; 00086 00087 Ogre::Real mCharHeight; 00088 Ogre::Real mLineSpacing; 00089 Ogre::Real mSpaceWidth; 00090 00091 bool mNeedUpdate; 00092 bool mUpdateColors; 00093 bool mOnTop; 00094 00095 Ogre::Real mTimeUntilNextToggle; 00096 Ogre::Real mRadius; 00097 00098 Ogre::Vector3 mGlobalTranslation; 00099 Ogre::Vector3 mLocalTranslation; 00100 00101 Ogre::Camera *mpCam; 00102 Ogre::RenderWindow *mpWin; 00103 Ogre::Font *mpFont; 00104 Ogre::MaterialPtr mpMaterial; 00105 Ogre::MaterialPtr mpBackgroundMaterial; 00106 00107 /******************************** public methods ******************************/ 00108 public: 00109 MovableText(const Ogre::String &caption, const Ogre::String &fontName = "Arial", Ogre::Real charHeight = 1.0, 00110 const Ogre::ColourValue &color = Ogre::ColourValue::White); 00111 virtual ~MovableText(); 00112 00113 #if (OGRE_VERSION_MAJOR >= 1 && OGRE_VERSION_MINOR >= 6) 00114 virtual void visitRenderables(Ogre::Renderable::Visitor* visitor, bool debugRenderables = false); 00115 #endif 00116 00117 // Set settings 00118 void setFontName(const Ogre::String &fontName); 00119 void setCaption(const Ogre::String &caption); 00120 void setColor(const Ogre::ColourValue &color); 00121 void setCharacterHeight(Ogre::Real height); 00122 void setLineSpacing(Ogre::Real height); 00123 void setSpaceWidth(Ogre::Real width); 00124 void setTextAlignment(const HorizontalAlignment& horizontalAlignment, 00125 const VerticalAlignment& verticalAlignment); 00126 void setGlobalTranslation(Ogre::Vector3 trans); 00127 void setLocalTranslation(Ogre::Vector3 trans); 00128 void showOnTop(bool show = true); 00129 00130 // Get settings 00131 const Ogre::String &getFontName() const 00132 { 00133 return mFontName; 00134 } 00135 const Ogre::String &getCaption() const 00136 { 00137 return mCaption; 00138 } 00139 const Ogre::ColourValue &getColor() const 00140 { 00141 return mColor; 00142 } 00143 00144 Ogre::Real getCharacterHeight() const 00145 { 00146 return mCharHeight; 00147 } 00148 Ogre::Real getSpaceWidth() const 00149 { 00150 return mSpaceWidth; 00151 } 00152 Ogre::Vector3 getGlobalTranslation() const 00153 { 00154 return mGlobalTranslation; 00155 } 00156 Ogre::Vector3 getLocalTranslation() const 00157 { 00158 return mLocalTranslation; 00159 } 00160 bool getShowOnTop() const 00161 { 00162 return mOnTop; 00163 } 00164 Ogre::AxisAlignedBox GetAABB(void) 00165 { 00166 return mAABB; 00167 } 00168 00169 const Ogre::MaterialPtr &getMaterial(void) const 00170 { 00171 assert(!mpMaterial.isNull()); 00172 return mpMaterial; 00173 } 00174 ; 00175 00176 00177 /******************************** protected methods and overload **************/ 00178 protected: 00179 00180 // from MovableText, create the object 00181 void _setupGeometry(); 00182 void _updateColors(); 00183 00184 // from Ogre::MovableObject 00185 void getWorldTransforms(Ogre::Matrix4 *xform) const; 00186 Ogre::Real getBoundingRadius(void) const 00187 { 00188 return mRadius; 00189 } 00190 ; 00191 Ogre::Real getSquaredViewDepth(const Ogre::Camera *cam) const 00192 { 00193 return 0; 00194 } 00195 ; 00196 const Ogre::Quaternion &getWorldOrientation(void) const; 00197 const Ogre::Vector3 &getWorldPosition(void) const; 00198 const Ogre::AxisAlignedBox &getBoundingBox(void) const 00199 { 00200 return mAABB; 00201 } 00202 ; 00203 const Ogre::String &getName(void) const 00204 { 00205 return mName; 00206 } 00207 ; 00208 const Ogre::String &getMovableType(void) const 00209 { 00210 static Ogre::String movType = "MovableText"; 00211 return movType; 00212 } 00213 ; 00214 00215 void _notifyCurrentCamera(Ogre::Camera *cam); 00216 void _updateRenderQueue(Ogre::RenderQueue* queue); 00217 00218 // from renderable 00219 void getRenderOperation(Ogre::RenderOperation &op); 00220 const Ogre::LightList &getLights(void) const 00221 { 00222 return mLList; 00223 } 00224 ; 00225 }; 00226 00227 } 00228 00229 #endif