Visual.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: Ogre Visual Class
00018  * Author: Nate Koenig
00019  * Date: 14 Dec 2007
00020  */
00021 
00022 #ifndef VISUAL_HH
00023 #define VISUAL_HH
00024 
00025 #include <boost/enable_shared_from_this.hpp>
00026 #include <string>
00027 
00028 #include "common/Event.hh"
00029 #include "math/Box.hh"
00030 #include "math/Pose.hh"
00031 #include "math/Quaternion.hh"
00032 #include "math/Vector3.hh"
00033 #include "math/Vector2d.hh"
00034 
00035 #include "sdf/sdf.h"
00036 #include "msgs/msgs.h"
00037 #include "rendering/RenderTypes.hh"
00038 #include "common/CommonTypes.hh"
00039 
00040 namespace Ogre
00041 {
00042   class MovableObject;
00043   class SceneNode;
00044   class StaticGeometry;
00045   class RibbonTrail;
00046   class AxisAlignedBox;
00047   class AnimationState;
00048 }
00049 
00050 namespace gazebo
00051 {
00052     namespace rendering
00053   { 
00056 
00058     class Visual : public boost::enable_shared_from_this<Visual>
00059     {
00061       public: Visual (const std::string &name, VisualPtr _parent);
00062   
00064       public: Visual (const std::string &name, Scene *scene);
00065   
00067       public: virtual ~Visual();
00068   
00070       public: void Init();
00071       public: void Fini();
00072   
00074       public: void LoadFromMsg(const boost::shared_ptr< msgs::Visual const> &msg);
00075   
00077       public: void Load( sdf::ElementPtr &sdf );
00078 
00080       public: void Load();
00081   
00083       public: void Update();
00084 
00086       public: void SetName( const std::string &name );
00087 
00089       public: std::string GetName() const;
00090   
00092       public: void AttachVisual(VisualPtr _vis);
00093              
00095       public: void DetachVisual(VisualPtr _vis);
00096       public: void DetachVisual(const std::string &_name);
00097   
00099       public: void AttachObject(Ogre::MovableObject *obj);
00100   
00102       public: void DetachObjects();
00103   
00105       public: unsigned int GetChildCount();
00106   
00108       public: VisualPtr GetChild(unsigned int _num);
00109   
00111       public: void AttachMesh( const std::string &meshName );
00112   
00114       public: void SetScale( const math::Vector3 &scale );
00115   
00117       public: math::Vector3 GetScale();
00118   
00120       public: void SetMaterial(const std::string &materialName);
00121 
00123       public: void SetAmbient(const common::Color &_color);
00124 
00126       public: void SetDiffuse(const common::Color &_color);
00127 
00129       public: void SetSpecular(const common::Color &_color);
00130 
00131       public: void AttachAxes();
00132   
00134       public: void SetTransparency( float trans );
00135   
00137       public: float GetTransparency();
00138 
00140       public: void SetEmissive( const common::Color &_color );
00141 
00143       public: void SetCastShadows(const bool &shadows);
00144   
00148       public: void SetVisible(bool visible, bool cascade=true);
00149   
00151       public: void ToggleVisible();
00152   
00154       public: bool GetVisible() const;
00155   
00157       public: void SetPosition( const math::Vector3 &pos);
00158   
00160       public: void SetRotation( const math::Quaternion &rot);
00161   
00163       public: void SetPose( const math::Pose &pose);
00164   
00166       public: math::Vector3 GetPosition() const;
00167   
00169       public: math::Quaternion GetRotation() const;
00170   
00172       public: math::Pose GetPose() const;
00173   
00175       public: math::Pose GetWorldPose() const;
00176  
00178       public: void SetWorldPose(const math::Pose _pose);
00179       public: void SetWorldPosition(const math::Vector3 &_pos);
00180       public: void SetWorldRotation(const math::Quaternion &_q);
00181 
00183       public: Ogre::SceneNode *GetSceneNode() const;
00184   
00186       public: void MakeStatic();
00187   
00189       public: bool IsStatic() const;
00190   
00192       public: void EnableTrackVisual( Visual *vis );
00193   
00195       public: void DisableTrackVisual();
00196   
00198       public: std::string GetNormalMap() const;
00199   
00201       public: void SetNormalMap(const std::string &nmap);
00202   
00204       public: void SetRibbonTrail(bool value);
00205   
00207       public: math::Box GetBoundingBox() const;
00208   
00210       public: DynamicLines *CreateDynamicLine(
00211                   RenderOpType type=RENDERING_LINE_STRIP);
00212   
00214       public: void DeleteDynamicLine(DynamicLines *line);
00215 
00217       public: void AttachLineVertex( DynamicLines *_line, 
00218                                      unsigned int _index );
00219   
00221       public: std::string GetMaterialName() const;
00222   
00223  
00225       public: static void InsertMesh( const common::Mesh *mesh);
00226   
00228       public: void UpdateFromMsg(const boost::shared_ptr< msgs::Visual const> &msg);
00229 
00231       public: bool IsPlane() const;
00232 
00234       public: VisualPtr GetParent() const;
00235 
00237       public: std::string GetShaderType() const;
00238 
00240       public: void SetShaderType( const std::string &_type );
00241 
00242       public: void MoveToPosition( const math::Vector3 &_end, 
00243                                    double _pitch, double _yaw, double _time);
00244 
00245       public: void ShowBoundingBox();
00246       public: void ShowCollision(bool _show);
00247 
00248       public: void SetScene(Scene *_scene);
00249       public: Scene *GetScene() const;
00250 
00251       private: void GetBoundsHelper(Ogre::SceneNode *node,
00252                                     math::Box &box) const;
00253 
00254       private: std::string GetMeshName() const;
00255   
00256       public: void ClearParent();
00257 
00258       private: void DestroyAllAttachedMovableObjects(
00259                    Ogre::SceneNode* i_pSceneNode);
00260 
00261       private: sdf::ElementPtr sdf;
00262 
00263       private: std::string myMaterialName;
00264       private: std::string origMaterialName;
00265   
00266       protected: Ogre::SceneNode *sceneNode;
00267   
00268       private: float transparency;
00269   
00270       private: static unsigned int visualCounter;
00271   
00272       private: bool isStatic;
00273       private: Ogre::StaticGeometry *staticGeom;
00274       private: bool visible;
00275   
00276       private: static SelectionObj *selectionObj;
00277   
00278       private: Ogre::RibbonTrail *ribbonTrail;
00279   
00280       private: event::ConnectionPtr preRenderConnection;
00281   
00282       // List of all the lines created
00283       private: std::list<DynamicLines*> lines;
00284 
00285       private: std::list< std::pair<DynamicLines*, unsigned int> > lineVertices;
00286 
00287       private: std::string name;
00288       private: std::string physicsEntityName;
00289       public: VisualPtr parent;
00290       public: std::vector<VisualPtr> children;
00291 
00293       protected: std::vector<common::Param*> parameters;
00294 
00295       private: Ogre::AnimationState *animState;
00296       protected: Scene *scene;
00297     };
00299   }
00300 
00301 }
00302 #endif