Revision: 8420 http://playerstage.svn.sourceforge.net/playerstage/?rev=8420&view=rev Author: natepak Date: 2009-11-18 21:52:40 +0000 (Wed, 18 Nov 2009)
Log Message: ----------- Added in the ability to track a model with a user camera Modified Paths: -------------- code/gazebo/trunk/server/Entity.cc code/gazebo/trunk/server/World.cc code/gazebo/trunk/server/World.hh code/gazebo/trunk/server/gui/GLFrame.cc code/gazebo/trunk/server/gui/GLFrame.hh code/gazebo/trunk/server/rendering/OgreCamera.cc code/gazebo/trunk/server/rendering/OgreCamera.hh code/gazebo/trunk/server/rendering/OgreVisual.cc code/gazebo/trunk/server/rendering/OgreVisual.hh Modified: code/gazebo/trunk/server/Entity.cc =================================================================== --- code/gazebo/trunk/server/Entity.cc 2009-11-18 20:14:57 UTC (rev 8419) +++ code/gazebo/trunk/server/Entity.cc 2009-11-18 21:52:40 UTC (rev 8420) @@ -321,7 +321,7 @@ // Handle a change of pose void Entity::PoseChange(bool notify) { - if (Simulator::Instance()->GetState() == Simulator::RUN) + if (Simulator::Instance()->GetState() == Simulator::RUN || !this->IsStatic()) this->visualNode->SetDirty(true, this->relativePose); else this->visualNode->SetPose(this->relativePose); Modified: code/gazebo/trunk/server/World.cc =================================================================== --- code/gazebo/trunk/server/World.cc 2009-11-18 20:14:57 UTC (rev 8419) +++ code/gazebo/trunk/server/World.cc 2009-11-18 21:52:40 UTC (rev 8420) @@ -421,6 +421,7 @@ if (node->GetNSPrefix() == "model") { model = this->LoadModel(node, parent, removeDuplicate); + this->addEntitySignal(model); } } Modified: code/gazebo/trunk/server/World.hh =================================================================== --- code/gazebo/trunk/server/World.hh 2009-11-18 20:14:57 UTC (rev 8419) +++ code/gazebo/trunk/server/World.hh 2009-11-18 21:52:40 UTC (rev 8420) @@ -30,6 +30,7 @@ #include <iostream> #include <vector> #include <boost/tuple/tuple.hpp> +#include <boost/signal.hpp> #ifdef USE_THREADPOOL #include "boost/threadpool.hpp" @@ -208,6 +209,13 @@ /// \brief Update the simulation iface public: void UpdateSimulationIface(); + /// \brief Connect a boost::slot the the add entity signal + public: template<typename T> + void ConnectAddEntitySignal( T subscriber ) + { + addEntitySignal.connect(subscriber); + } + /// \brif Get the names of interfaces defined in the tree of a model private: void GetInterfaceNames(Entity* m, std::vector<std::string>& list); @@ -250,6 +258,7 @@ private: friend class DestroyerT<World>; private: friend class SingletonT<World>; + private: boost::signal<void (Entity*)> addEntitySignal; }; Modified: code/gazebo/trunk/server/gui/GLFrame.cc =================================================================== --- code/gazebo/trunk/server/gui/GLFrame.cc 2009-11-18 20:14:57 UTC (rev 8419) +++ code/gazebo/trunk/server/gui/GLFrame.cc 2009-11-18 21:52:40 UTC (rev 8420) @@ -26,6 +26,8 @@ #include <boost/bind.hpp> +#include "World.hh" +#include "Model.hh" #include "XMLConfig.hh" #include "CameraManager.hh" #include "Global.hh" @@ -72,6 +74,15 @@ this->splitChoice->value(0); this->splitChoice->color(BG_COLOR); + this->trackChoice = new Fl_Choice( + this->splitChoice->x() + this->splitChoice->w()+2, + this->splitChoice->y(), 150, 26); + this->trackChoice->add("Track Model"); + this->trackChoice->mode(0, FL_MENU_DIVIDER); + this->trackChoice->add("None","", &gazebo::GLFrame::TrackCB, this); + this->trackChoice->value(0); + this->trackChoice->color(BG_COLOR); + this->headerBar->end(); this->headerBar->resizable(NULL); @@ -179,6 +190,8 @@ CameraManager::Instance()->ConnectAddCameraSignal( boost::bind(&GLFrame::CameraAddedSlot, this, _1) ); + World::Instance()->ConnectAddEntitySignal( boost::bind(&GLFrame::EntityAddedSlot, this, _1) ); + // Add all the current cameras for (unsigned int i=0; i < CameraManager::Instance()->GetNumCameras(); i++) { @@ -221,6 +234,14 @@ } //////////////////////////////////////////////////////////////////////////////// +/// Boost slot, called when a new entity is added. +void GLFrame::EntityAddedSlot(Entity *newEntity) +{ + this->trackChoice->add(newEntity->GetName().c_str(), "", &gazebo::GLFrame::TrackCB, this); + this->trackChoice->redraw(); +} + +//////////////////////////////////////////////////////////////////////////////// /// Split the current window void GLFrame::SplitCB(Fl_Widget *widget, void *data) { @@ -272,3 +293,20 @@ { return this->glWindow; } + +//////////////////////////////////////////////////////////////////////////////// +/// Switch view callback +void GLFrame::TrackCB(Fl_Widget *widget, void *data) +{ + GLFrame *frame = reinterpret_cast<GLFrame *>(data); + Fl_Choice *choice = dynamic_cast<Fl_Choice *>(widget); + + if (std::string(choice->text()) == "None" || + std::string(choice->text()) == "Track Model") + frame->glWindow->GetCamera()->TrackModel( NULL ); + else + { + Model *model = World::Instance()->GetModelByName(choice->text() ); + frame->glWindow->GetCamera()->TrackModel( model ); + } +} Modified: code/gazebo/trunk/server/gui/GLFrame.hh =================================================================== --- code/gazebo/trunk/server/gui/GLFrame.hh 2009-11-18 20:14:57 UTC (rev 8419) +++ code/gazebo/trunk/server/gui/GLFrame.hh 2009-11-18 21:52:40 UTC (rev 8420) @@ -41,6 +41,7 @@ class GLWindow; class OgreCamera; class XMLConfigNode; + class Entity; class GLFrame : public Fl_Group { @@ -74,12 +75,18 @@ /// \brief Boost slot, called when a new camera is added. public: void CameraAddedSlot(OgreCamera *newCamera); + /// \brief Boost slot, called when a new entity is added. + public: void EntityAddedSlot(Entity *newEntity); + /// \brief Split frame callback private: static void SplitCB(Fl_Widget *widget, void *data); /// \brief Switch view callback private: static void ViewCB(Fl_Widget *widget, void *data); + /// \brief Switch view callback + private: static void TrackCB(Fl_Widget *widget, void *data); + /// Pointer to the actual render window private: GLWindow *glWindow; @@ -95,6 +102,9 @@ /// Split window chooser private: Fl_Choice *splitChoice; + /// Choose to have the camera track an entity + private: Fl_Choice *trackChoice; + private: Fl_Output *outputXYZ; private: Fl_Output *outputRPY; Modified: code/gazebo/trunk/server/rendering/OgreCamera.cc =================================================================== --- code/gazebo/trunk/server/rendering/OgreCamera.cc 2009-11-18 20:14:57 UTC (rev 8419) +++ code/gazebo/trunk/server/rendering/OgreCamera.cc 2009-11-18 21:52:40 UTC (rev 8420) @@ -37,6 +37,8 @@ #include "OgreCreator.hh" #include "XMLConfig.hh" #include "Simulator.hh" +#include "Model.hh" +#include "Body.hh" #include "OgreAdaptor.hh" #include "CameraManager.hh" @@ -165,6 +167,7 @@ } this->lastUpdate = Simulator::Instance()->GetSimTime(); + } ////////////////////////////////////////////////////////////////////////////// @@ -201,6 +204,8 @@ this->saveCount = 0; OgreAdaptor::Instance()->RegisterCamera(this); + + this->origParentNode = (Ogre::SceneNode*)this->sceneNode->getParent(); } ////////////////////////////////////////////////////////////////////////////// @@ -692,3 +697,20 @@ this->saveCount++; } + +////////////////////////////////////////////////////////////////////////////// +/// Set the camera to track an entity +void OgreCamera::TrackModel( Model *model ) +{ + this->sceneNode->getParent()->removeChild(this->sceneNode); + + if (model) + { + Body *b = model->GetCanonicalBody(); + b->GetVisualNode()->GetSceneNode()->addChild(this->sceneNode); + } + else + { + this->origParentNode->addChild(this->sceneNode); + } +} Modified: code/gazebo/trunk/server/rendering/OgreCamera.hh =================================================================== --- code/gazebo/trunk/server/rendering/OgreCamera.hh 2009-11-18 20:14:57 UTC (rev 8419) +++ code/gazebo/trunk/server/rendering/OgreCamera.hh 2009-11-18 21:52:40 UTC (rev 8420) @@ -47,6 +47,7 @@ namespace gazebo { class XMLConfigNode; + class Model; /// \addtogroup gazebo_rendering /// \brief Basic camera @@ -211,6 +212,9 @@ /// \brief Set the camera's name public: void SetCamName( const std::string &name ); + /// \brief Set the camera to track an entity + public: void TrackModel( Model *model ); + // Save the camera frame protected: virtual void SaveFrame(); @@ -222,6 +226,7 @@ protected: unsigned int textureWidth, textureHeight; protected: Ogre::Camera *camera; + protected: Ogre::SceneNode *origParentNode; protected: Ogre::SceneNode *sceneNode; protected: Ogre::SceneNode *pitchNode; Modified: code/gazebo/trunk/server/rendering/OgreVisual.cc =================================================================== --- code/gazebo/trunk/server/rendering/OgreVisual.cc 2009-11-18 20:14:57 UTC (rev 8419) +++ code/gazebo/trunk/server/rendering/OgreVisual.cc 2009-11-18 21:52:40 UTC (rev 8420) @@ -931,3 +931,16 @@ } +//////////////////////////////////////////////////////////////////////////////// +/// Set one visual to track/follow another +void OgreVisual::EnableTrackVisual( OgreVisual *vis ) +{ + this->sceneNode->setAutoTracking(true, vis->GetSceneNode() ); +} + +//////////////////////////////////////////////////////////////////////////////// +/// Disable tracking of a visual +void OgreVisual::DisableTrackVisual() +{ + this->sceneNode->setAutoTracking(false); +} Modified: code/gazebo/trunk/server/rendering/OgreVisual.hh =================================================================== --- code/gazebo/trunk/server/rendering/OgreVisual.hh 2009-11-18 20:14:57 UTC (rev 8419) +++ code/gazebo/trunk/server/rendering/OgreVisual.hh 2009-11-18 21:52:40 UTC (rev 8420) @@ -154,6 +154,12 @@ /// \brief Return true if the visual is a static geometry public: bool IsStatic() const; + /// \brief Set one visual to track/follow another + public: void EnableTrackVisual( OgreVisual *vis ); + + /// \brief Disable tracking of a visual + public: void DisableTrackVisual(); + private: Ogre::MaterialPtr origMaterial; private: Ogre::MaterialPtr myMaterial; private: Ogre::SceneBlendType sceneBlendType; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Playerstage-commit mailing list Playerstage-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/playerstage-commit