Revision: 7464
http://playerstage.svn.sourceforge.net/playerstage/?rev=7464&view=rev
Author: natepak
Date: 2009-03-12 17:47:22 +0000 (Thu, 12 Mar 2009)
Log Message:
-----------
Added mutexs for thread safety
Modified Paths:
--------------
code/branches/federation/gazebo/server/rendering/MovableText.cc
code/branches/federation/gazebo/server/rendering/MovableText.hh
code/branches/federation/gazebo/server/rendering/OgreAdaptor.cc
code/branches/federation/gazebo/server/rendering/OgreAdaptor.hh
code/branches/federation/gazebo/server/rendering/OgreCreator.cc
code/branches/federation/gazebo/server/rendering/OgreCreator.hh
code/branches/federation/gazebo/server/rendering/OgreDynamicLines.cc
code/branches/federation/gazebo/server/rendering/OgreVisual.cc
code/branches/federation/gazebo/server/rendering/OgreVisual.hh
code/branches/federation/gazebo/server/rendering/SConscript
code/branches/federation/gazebo/server/rendering/UserCamera.cc
code/branches/federation/gazebo/server/rendering/UserCamera.hh
Removed Paths:
-------------
code/branches/federation/gazebo/server/rendering/OgreVisualManager.cc
code/branches/federation/gazebo/server/rendering/OgreVisualManager.hh
Modified: code/branches/federation/gazebo/server/rendering/MovableText.cc
===================================================================
--- code/branches/federation/gazebo/server/rendering/MovableText.cc
2009-03-12 03:18:46 UTC (rev 7463)
+++ code/branches/federation/gazebo/server/rendering/MovableText.cc
2009-03-12 17:47:22 UTC (rev 7464)
@@ -1,5 +1,5 @@
/**
- * File: MovableText.cpp
+ * File: OgreMovableText.cpp
*
* description: This create create a billboarding object that display a text.
*
@@ -8,8 +8,9 @@
* @update 2007 by independentCreations see [email protected]
*/
-#include "MovableText.hh"
+#include "OgreMovableText.hh"
+#include <boost/thread/recursive_mutex.hpp>
#include <OgreFontManager.h>
#include <OgrePrerequisites.h>
@@ -20,7 +21,7 @@
////////////////////////////////////////////////////////////////////////////////
// Constructor
-MovableText::MovableText()
+OgreMovableText::OgreMovableText()
: camera(NULL),
renderWindow(NULL) ,
viewportAspectCoef (0.75),
@@ -33,51 +34,75 @@
baseline(0.0)
{
this->renderOp.vertexData = NULL;
+
+ this->dirty = true;
+ this->mutex = new boost::recursive_mutex();
}
////////////////////////////////////////////////////////////////////////////////
// Destructor
-MovableText::~MovableText()
+OgreMovableText::~OgreMovableText()
{
if (this->renderOp.vertexData)
delete this->renderOp.vertexData;
+
+ delete this->mutex;
}
////////////////////////////////////////////////////////////////////////////////
//Loads the text to display and select the font
-void MovableText::Load(const std::string &name,
+void OgreMovableText::Load(const std::string &name,
const Ogre::UTFString &text,
const std::string &fontName,
float charHeight,
const Ogre::ColourValue &color)
{
- this->text=text;
- this->color=color;
- this->fontName=fontName;
- this->charHeight=charHeight;
- this->mName = name;
+ {
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
- if (this->mName == "")
- throw Ogre::Exception(Ogre::Exception::ERR_INVALIDPARAMS,
- "Trying to create MovableText without name",
- "MovableText::MovableText");
+ this->text=text;
+ this->color=color;
+ this->fontName=fontName;
+ this->charHeight=charHeight;
+ this->mName = name;
- if (this->text == "")
- throw Ogre::Exception(Ogre::Exception::ERR_INVALIDPARAMS,
- "Trying to create MovableText without text",
- "MovableText::MovableText");
+ if (this->mName == "")
+ throw Ogre::Exception(Ogre::Exception::ERR_INVALIDPARAMS,
+ "Trying to create OgreMovableText without name",
+ "OgreMovableText::OgreMovableText");
+ if (this->text == "")
+ throw Ogre::Exception(Ogre::Exception::ERR_INVALIDPARAMS,
+ "Trying to create OgreMovableText without text",
+ "OgreMovableText::OgreMovableText");
+ this->dirty = true;
+ }
+
this->SetFontName(this->fontName);
- this->_setupGeometry();
+
+ // NATE
+ //this->_setupGeometry();
}
+////////////////////////////////////////////////////////////////////////////////
+// Update the text
+void OgreMovableText::Update()
+{
+ if (this->dirty)
+ {
+ this->_setupGeometry();
+ this->dirty = false;
+ }
+}
////////////////////////////////////////////////////////////////////////////////
// Set the font name
-void MovableText::SetFontName(const std::string &newFontName)
+void OgreMovableText::SetFontName(const std::string &newFontName)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
+
if ((Ogre::MaterialManager::getSingletonPtr()->resourceExists(this->mName +
"Material")))
{
Ogre::MaterialManager::getSingleton().remove(this->mName + "Material");
@@ -93,7 +118,7 @@
{
throw Ogre::Exception(Ogre::Exception::ERR_ITEM_NOT_FOUND,
"Could not find font " + fontName,
- "MovableText::setFontName");
+ "OgreMovableText::setFontName");
}
this->font->load();
@@ -120,8 +145,10 @@
////////////////////////////////////////////////////////////////////////////////
// Set the caption
-void MovableText::SetText(const Ogre::UTFString &newText)
+void OgreMovableText::SetText(const Ogre::UTFString &newText)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
+
if (this->text != newText)
{
this->text = newText;
@@ -131,8 +158,10 @@
////////////////////////////////////////////////////////////////////////////////
// Set the color
-void MovableText::SetColor(const Ogre::ColourValue &newColor)
+void OgreMovableText::SetColor(const Ogre::ColourValue &newColor)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
+
if (this->color != newColor)
{
this->color = newColor;
@@ -142,8 +171,10 @@
////////////////////////////////////////////////////////////////////////////////
// Set the character height
-void MovableText::SetCharHeight(float height)
+void OgreMovableText::SetCharHeight(float height)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
+
if (this->charHeight != height)
{
this->charHeight = height;
@@ -153,8 +184,10 @@
////////////////////////////////////////////////////////////////////////////////
// Set the width of the space between characters
-void MovableText::SetSpaceWidth(float width)
+void OgreMovableText::SetSpaceWidth(float width)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
+
if (this->spaceWidth != width)
{
this->spaceWidth = width;
@@ -164,8 +197,9 @@
////////////////////////////////////////////////////////////////////////////////
// Set alignment of the text
-void MovableText::SetTextAlignment(const HorizAlign &h, const VertAlign &v)
+void OgreMovableText::SetTextAlignment(const HorizAlign &h, const VertAlign &v)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
if (this->horizAlign != h)
{
this->horizAlign = h;
@@ -181,8 +215,9 @@
////////////////////////////////////////////////////////////////////////////////
// Set additional height
-void MovableText::SetBaseline( float base )
+void OgreMovableText::SetBaseline( float base )
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
if ( this->baseline != base )
{
this->baseline = base;
@@ -192,8 +227,9 @@
////////////////////////////////////////////////////////////////////////////////
// Set whether the text should be shown on top
-void MovableText::SetShowOnTop(bool show)
+void OgreMovableText::SetShowOnTop(bool show)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
if (this->onTop != show && !this->material.isNull())
{
this->onTop = show;
@@ -206,22 +242,26 @@
////////////////////////////////////////////////////////////////////////////////
// True=text is displayed on top
-bool MovableText::GetShowOnTop() const
+bool OgreMovableText::GetShowOnTop() const
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
return this->onTop;
}
////////////////////////////////////////////////////////////////////////////////
// Get the axis aligned bounding box
-Ogre::AxisAlignedBox MovableText::GetAABB(void)
+Ogre::AxisAlignedBox OgreMovableText::GetAABB(void)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
return this->aabb;
}
////////////////////////////////////////////////////////////////////////////////
// Setup the billboard that renders the text
-void MovableText::_setupGeometry()
+void OgreMovableText::_setupGeometry()
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
+
assert(this->font);
assert(!this->material.isNull());
@@ -306,7 +346,7 @@
if (this->spaceWidth == 0)
this->spaceWidth = this->font->getGlyphAspectRatio('A') * this->charHeight
* 2.0;
- if (this->vertAlign == MovableText::V_ABOVE)
+ if (this->vertAlign == OgreMovableText::V_ABOVE)
{
// Raise the first line of the caption
top += this->charHeight;
@@ -375,7 +415,7 @@
// First tri
//
// Upper left
- if (this->horizAlign == MovableText::H_LEFT)
+ if (this->horizAlign == OgreMovableText::H_LEFT)
*pVert++ = left;
else
*pVert++ = left - (len/2.0);
@@ -386,7 +426,7 @@
*pVert++ = uvRect.top;
// Deal with bounds
- if (this->horizAlign == MovableText::H_LEFT)
+ if (this->horizAlign == OgreMovableText::H_LEFT)
currPos = Ogre::Vector3(left,top,0);
else
currPos = Ogre::Vector3(left - (len/2.0), top, 0);
@@ -407,7 +447,7 @@
top -= this->charHeight * 2.0;
// Bottom left
- if (this->horizAlign == MovableText::H_LEFT)
+ if (this->horizAlign == OgreMovableText::H_LEFT)
*pVert++ = left;
else
*pVert++ = left - (len / 2.0);
@@ -418,7 +458,7 @@
*pVert++ = uvRect.bottom;
// Deal with bounds
- if (this->horizAlign == MovableText::H_LEFT)
+ if (this->horizAlign == OgreMovableText::H_LEFT)
currPos = Ogre::Vector3(left,top,0);
else
currPos = Ogre::Vector3(left - (len/2), top, 0);
@@ -432,7 +472,7 @@
left += horiz_height * this->charHeight * 2.0;
// Top right
- if (this->horizAlign == MovableText::H_LEFT)
+ if (this->horizAlign == OgreMovableText::H_LEFT)
*pVert++ = left;
else
*pVert++ = left - (len/2.0);
@@ -443,7 +483,7 @@
*pVert++ = uvRect.top;
// Deal with bounds
- if (this->horizAlign == MovableText::H_LEFT)
+ if (this->horizAlign == OgreMovableText::H_LEFT)
currPos = Ogre::Vector3(left,top,0);
else
currPos = Ogre::Vector3(left - (len/2), top, 0);
@@ -459,7 +499,7 @@
// Second tri
//
// Top right (again)
- if (this->horizAlign == MovableText::H_LEFT)
+ if (this->horizAlign == OgreMovableText::H_LEFT)
*pVert++ = left;
else
*pVert++ = left - (len/2.0);
@@ -479,7 +519,7 @@
left -= horiz_height * this->charHeight * 2.0;
// Bottom left (again)
- if (this->horizAlign == MovableText::H_LEFT)
+ if (this->horizAlign == OgreMovableText::H_LEFT)
*pVert++ = left;
else
*pVert++ = left - (len/2.0);
@@ -498,7 +538,7 @@
left += horiz_height * this->charHeight * 2.0;
// Bottom right
- if (this->horizAlign == MovableText::H_LEFT)
+ if (this->horizAlign == OgreMovableText::H_LEFT)
*pVert++ = left;
else
*pVert++ = left - (len/2.0);
@@ -546,8 +586,10 @@
////////////////////////////////////////////////////////////////////////////////
// Update the colors
-void MovableText::_updateColors(void)
+void OgreMovableText::_updateColors(void)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
+
Ogre::RGBA color;
Ogre::HardwareVertexBufferSharedPtr vbuf;
Ogre::RGBA *pDest=NULL;
@@ -573,36 +615,41 @@
}
////////////////////////////////////////////////////////////////////////////////
-const Ogre::Quaternion & MovableText::getWorldOrientation(void) const
+const Ogre::Quaternion & OgreMovableText::getWorldOrientation(void) const
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
assert(this->camera);
return const_cast<Ogre::Quaternion&>(this->camera->getDerivedOrientation());
//return mParentNode->_getDerivedOrientation();
}
////////////////////////////////////////////////////////////////////////////////
-const Ogre::Vector3 & MovableText::getWorldPosition(void) const
+const Ogre::Vector3 & OgreMovableText::getWorldPosition(void) const
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
assert(mParentNode);
return mParentNode->_getDerivedPosition();
}
////////////////////////////////////////////////////////////////////////////////
-const Ogre::AxisAlignedBox &MovableText::getBoundingBox(void) const
+const Ogre::AxisAlignedBox &OgreMovableText::getBoundingBox(void) const
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
return this->aabb;
}
////////////////////////////////////////////////////////////////////////////////
-const Ogre::String &MovableText::getMovableType() const
+const Ogre::String &OgreMovableText::getMovableType() const
{
- static Ogre::String movType = "MovableText";
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
+ static Ogre::String movType = "OgreMovableText";
return movType;
}
////////////////////////////////////////////////////////////////////////////////
-void MovableText::getWorldTransforms(Ogre::Matrix4 * xform) const
+void OgreMovableText::getWorldTransforms(Ogre::Matrix4 * xform) const
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
if (this->isVisible() && this->camera)
{
Ogre::Matrix3 rot3x3, scale3x3 = Ogre::Matrix3::IDENTITY;
@@ -628,20 +675,24 @@
}
////////////////////////////////////////////////////////////////////////////////
-float MovableText::getBoundingRadius() const
+float OgreMovableText::getBoundingRadius() const
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
return this->radius;
}
////////////////////////////////////////////////////////////////////////////////
-float MovableText::getSquaredViewDepth(const Ogre::Camera *cam) const
+float OgreMovableText::getSquaredViewDepth(const Ogre::Camera *cam) const
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
return 0;
}
////////////////////////////////////////////////////////////////////////////////
-void MovableText::getRenderOperation(Ogre::RenderOperation & op)
+void OgreMovableText::getRenderOperation(Ogre::RenderOperation & op)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
+
if (this->isVisible())
{
if (this->needUpdate)
@@ -653,28 +704,32 @@
}
////////////////////////////////////////////////////////////////////////////////
-const Ogre::MaterialPtr &MovableText::getMaterial(void) const
+const Ogre::MaterialPtr &OgreMovableText::getMaterial(void) const
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
assert(!this->material.isNull());
return this->material;
}
////////////////////////////////////////////////////////////////////////////////
//
-const Ogre::LightList &MovableText::getLights(void) const
+const Ogre::LightList &OgreMovableText::getLights(void) const
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
return this->lightList;
}
////////////////////////////////////////////////////////////////////////////////
-void MovableText::_notifyCurrentCamera(Ogre::Camera *cam)
+void OgreMovableText::_notifyCurrentCamera(Ogre::Camera *cam)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
this->camera = cam;
}
////////////////////////////////////////////////////////////////////////////////
-void MovableText::_updateRenderQueue(Ogre::RenderQueue* queue)
+void OgreMovableText::_updateRenderQueue(Ogre::RenderQueue* queue)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
if (this->isVisible())
{
if (this->needUpdate)
@@ -689,9 +744,10 @@
////////////////////////////////////////////////////////////////////////////////
/// Method to allow a caller to abstractly iterate over the Renderable
instances
-void MovableText::visitRenderables( Ogre::Renderable::Visitor* /*visitor*/,
+void OgreMovableText::visitRenderables( Ogre::Renderable::Visitor* /*visitor*/,
bool /*debug*/)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
return;
}
Modified: code/branches/federation/gazebo/server/rendering/MovableText.hh
===================================================================
--- code/branches/federation/gazebo/server/rendering/MovableText.hh
2009-03-12 03:18:46 UTC (rev 7463)
+++ code/branches/federation/gazebo/server/rendering/MovableText.hh
2009-03-12 17:47:22 UTC (rev 7464)
@@ -33,10 +33,15 @@
#include <OgreUserDefinedObject.h>
#include <string>
+namespace boost
+{
+ class recursive_mutex;
+}
+
namespace gazebo
{
/// \brief Movable text
- class MovableText : public Ogre::MovableObject, public Ogre::Renderable
+ class OgreMovableText : public Ogre::MovableObject, public Ogre::Renderable
{
/// \brief Horizontal alignment
public: enum HorizAlign {H_LEFT, H_CENTER};
@@ -45,10 +50,10 @@
public: enum VertAlign {V_BELOW, V_ABOVE};
/// \brief Constructor
- public: MovableText();
+ public: OgreMovableText();
/// \brief Destructor
- public: virtual ~MovableText();
+ public: virtual ~OgreMovableText();
/// \brief Loads text and font info
public: void Load(const std::string &name,
@@ -111,6 +116,9 @@
public: virtual void visitRenderables( Ogre::Renderable::Visitor* visitor,
bool debug = false );
+ /// \brief Update the text
+ public: void Update();
+
/// \brief setup the geometry (from MovableText)
protected: void _setupGeometry();
@@ -170,8 +178,10 @@
/// \brief Get the lights
protected: const Ogre::LightList &getLights(void) const; //{return
mLList;};
-
+ private: bool dirty;
+
+ private: boost::recursive_mutex *mutex;
};
- }
+}
#endif
Modified: code/branches/federation/gazebo/server/rendering/OgreAdaptor.cc
===================================================================
--- code/branches/federation/gazebo/server/rendering/OgreAdaptor.cc
2009-03-12 03:18:46 UTC (rev 7463)
+++ code/branches/federation/gazebo/server/rendering/OgreAdaptor.cc
2009-03-12 17:47:22 UTC (rev 7464)
@@ -455,6 +455,25 @@
////////////////////////////////////////////////////////////////////////////////
+// Update the user cameras
+void OgreAdaptor::UpdateCameras()
+{
+ std::vector<UserCamera*>::iterator iter;
+
+ OgreCreator::Instance()->Update();
+
+ this->root->_fireFrameStarted();
+
+ // Draw all the windows
+ for (iter = this->cameras.begin(); iter != this->cameras.end(); iter++)
+ {
+ (*iter)->GetWindow()->update();
+ }
+
+ this->root->_fireFrameEnded();
+}
+
+////////////////////////////////////////////////////////////////////////////////
// Update a window
void OgreAdaptor::UpdateWindow(Ogre::RenderWindow *window, OgreCamera *camera)
{
@@ -517,3 +536,10 @@
{
return **(this->updateRateP);
}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Register a user camera
+void OgreAdaptor::RegisterCamera( UserCamera *cam )
+{
+ this->cameras.push_back( cam );
+}
Modified: code/branches/federation/gazebo/server/rendering/OgreAdaptor.hh
===================================================================
--- code/branches/federation/gazebo/server/rendering/OgreAdaptor.hh
2009-03-12 03:18:46 UTC (rev 7463)
+++ code/branches/federation/gazebo/server/rendering/OgreAdaptor.hh
2009-03-12 17:47:22 UTC (rev 7464)
@@ -95,6 +95,8 @@
/// \brief Get the desired update rate
public: double GetUpdateRate();
+ public: void UpdateCameras();
+
/// \brief Update a window
public: void UpdateWindow(Ogre::RenderWindow *window, OgreCamera *camera);
@@ -102,6 +104,9 @@
/// mouse picking.
public: Entity *GetEntityAt(OgreCamera *camera, Vector2<int> mousePos);
+ /// \brief Register a user camera
+ public: void RegisterCamera( UserCamera *cam );
+
private: void LoadPlugins();
private: void SetupResources();
private: void SetupRenderSystem(bool create);
@@ -157,6 +162,8 @@
private: ParamT<bool> *drawGridP;
private: ParamT<std::string> *skyMaterialP;
private: std::vector<Param*> parameters;
+
+ private: std::vector<UserCamera*> cameras;
};
Modified: code/branches/federation/gazebo/server/rendering/OgreCreator.cc
===================================================================
--- code/branches/federation/gazebo/server/rendering/OgreCreator.cc
2009-03-12 03:18:46 UTC (rev 7463)
+++ code/branches/federation/gazebo/server/rendering/OgreCreator.cc
2009-03-12 17:47:22 UTC (rev 7464)
@@ -32,7 +32,7 @@
#include <FL/Fl.H>
#include <FL/x.H>
-
+#include "Geom.hh"
#include "Global.hh"
#include "Entity.hh"
#include "XMLConfig.hh"
@@ -41,6 +41,7 @@
#include "MovableText.hh"
#include "OgreAdaptor.hh"
#include "OgreVisual.hh"
+#include "OgreDynamicLines.hh"
#include "OgreSimpleShape.hh"
#include "OgreCreator.hh"
@@ -654,3 +655,106 @@
return filename;
}
+
+////////////////////////////////////////////////////////////////////////////////
+// Create a dynamic line
+OgreDynamicLines
*OgreCreator::CreateDynamicLine(OgreDynamicRenderable::OperationType opType)
+{
+ OgreDynamicLines *line = new OgreDynamicLines(opType);
+
+ this->lines.push_back( line );
+
+ return line;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Update all the entities
+void OgreCreator::Update()
+{
+ std::list<OgreDynamicLines*>::iterator iter;
+ std::list<MovableText*>::iterator titer;
+ std::map<std::string, OgreVisual*>::iterator viter;
+ OgreVisual *vis = NULL;
+ Entity *owner = NULL;
+
+ // Update the text
+ for (titer = this->text.begin(); titer != this->text.end(); titer++)
+ {
+ (*titer)->Update();
+ }
+
+ // Update the lines
+ for (iter = this->lines.begin(); iter != this->lines.end(); iter++)
+ {
+ (*iter)->Update();
+ }
+
+ // Update the visuals
+ for (viter = this->visuals.begin(); viter != this->visuals.end(); viter++)
+ {
+ vis = viter->second;
+ owner = vis->GetOwner();
+ if (!owner)
+ continue;
+
+ Geom *geom = dynamic_cast<Geom*>(owner);
+
+ if (geom || !owner->GetParent())
+ vis->SetPose(owner->GetPose());
+ else
+ vis->SetPose(owner->GetPose() - owner->GetParent()->GetPose());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Create a new ogre visual
+OgreVisual *OgreCreator::CreateVisual( const std::string &name,
+ OgreVisual *parent, Entity *owner)
+{
+ OgreVisual *newVis = NULL;
+ std::map<std::string, OgreVisual*>::iterator iter;
+
+ iter = this->visuals.find(name);
+
+ if (iter == this->visuals.end())
+ {
+ newVis = new OgreVisual(parent, owner);
+ newVis->SetName(name);
+ this->visuals[name] = newVis;
+ }
+ else
+ gzthrow(std::string("Name of ogre visual already exists: ") + name);
+
+ return newVis;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Delete a visual
+void OgreCreator::DeleteVisual( OgreVisual *visual )
+{
+ std::map<std::string, OgreVisual*>::iterator iter;
+
+ iter = this->visuals.find(visual->GetName());
+
+ if (iter != this->visuals.end())
+ {
+ delete iter->second;
+ iter->second = NULL;
+ this->visuals.erase(iter);
+ }
+ else
+ {
+ gzerr(0) << "Unknown visual[" << visual->GetName() << "]\n";
+ }
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Create a movable text object
+MovableText *OgreCreator::CreateMovableText()
+{
+ MovableText *newText = new MovableText();
+ this->text.push_back(newText);
+ return newText;
+}
+
Modified: code/branches/federation/gazebo/server/rendering/OgreCreator.hh
===================================================================
--- code/branches/federation/gazebo/server/rendering/OgreCreator.hh
2009-03-12 03:18:46 UTC (rev 7463)
+++ code/branches/federation/gazebo/server/rendering/OgreCreator.hh
2009-03-12 17:47:22 UTC (rev 7464)
@@ -31,6 +31,9 @@
//#include <X11/Xutil.h>
#include <string>
+#include <vector>
+#include "OgreDynamicRenderable.hh"
+#include "SingletonT.hh"
#include "Vector3.hh"
#include "Vector2.hh"
@@ -48,23 +51,25 @@
class XMLConfigNode;
class Entity;
class OgreVisual;
+ class MovableText;
+ class OgreDynamicLines;
/// \addtogroup gazebo_rendering
/// \{
/// \brief Functions that creates Ogre3d objects
- class OgreCreator
+ class OgreCreator : public SingletonT<OgreCreator>
{
/// \brief Constructor
- public: OgreCreator();
+ private: OgreCreator();
/// \brief Destructor
- public: virtual ~OgreCreator();
+ private: virtual ~OgreCreator();
/// \brief Load some simple shapes on the render engine
- public: static void LoadBasicShapes();
+ public: static void LoadBasicShapes();
/// \brief Create a Plane
/// It adds itself to the Visual node parent, it will those change parent
@@ -124,9 +129,47 @@
/// \brief Create a material from a texture file
public: static std::string CreateMaterialFromTexFile(const std::string
&filename);
+ public: OgreDynamicLines
*CreateDynamicLine(OgreDynamicRenderable::OperationType opType);
+
+ /// \brief Create a new ogre visual
+ /// \param name Unique name for the new visual
+ /// \param parent Parent visual
+ /// \param owner The entity that owns the visual
+ /// \return The new ogre visual
+ public: OgreVisual *CreateVisual( const std::string &name,
+ OgreVisual *parent=NULL,
+ Entity *owner = NULL );
+
+ /// \brief Delete a visual
+ public: void DeleteVisual( OgreVisual *visual );
+
+ /// \brief Remove a visual
+ /// \param name Unique name of the visual to remove
+ public: void RemoveVisual( const std::string &name );
+
+
+ /// \brief Create a movable text object
+ /// \return A new movable text object
+ public: MovableText *CreateMovableText();
+
+ /// \brief Update all the entities
+ public: void Update();
+
private: static unsigned int lightCounter;
private: static unsigned int windowCounter;
+ // List of all the lines created
+ private: std::list<OgreDynamicLines*> lines;
+
+ // List of all the movable text
+ private: std::list<MovableText*> text;
+
+ // All the visuals
+ private: std::map<std::string, OgreVisual*> visuals;
+
+ private: friend class DestroyerT<OgreCreator>;
+ private: friend class SingletonT<OgreCreator>;
+
/// \}
};
Modified: code/branches/federation/gazebo/server/rendering/OgreDynamicLines.cc
===================================================================
--- code/branches/federation/gazebo/server/rendering/OgreDynamicLines.cc
2009-03-12 03:18:46 UTC (rev 7463)
+++ code/branches/federation/gazebo/server/rendering/OgreDynamicLines.cc
2009-03-12 17:47:22 UTC (rev 7464)
@@ -121,7 +121,8 @@
Ogre::HardwareVertexBufferSharedPtr vbuf =
this->mRenderOp.vertexData->vertexBufferBinding->getBuffer(0);
- Ogre::Real *prPos =
static_cast<Ogre::Real*>(vbuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));
+ //Ogre::Real *prPos =
static_cast<Ogre::Real*>(vbuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));
+ Ogre::Real *prPos =
static_cast<Ogre::Real*>(vbuf->lock(Ogre::HardwareBuffer::HBL_NORMAL));
{
for (int i = 0; i < size; i++)
{
Modified: code/branches/federation/gazebo/server/rendering/OgreVisual.cc
===================================================================
--- code/branches/federation/gazebo/server/rendering/OgreVisual.cc
2009-03-12 03:18:46 UTC (rev 7463)
+++ code/branches/federation/gazebo/server/rendering/OgreVisual.cc
2009-03-12 17:47:22 UTC (rev 7464)
@@ -24,6 +24,8 @@
* SVN: $Id$
*/
#include <Ogre.h>
+#include <boost/thread/recursive_mutex.hpp>
+
#include "OgreSimpleShape.hh"
#include "Entity.hh"
#include "GazeboMessage.hh"
@@ -42,6 +44,8 @@
OgreVisual::OgreVisual(OgreVisual *node, Entity *_owner)
: Common()
{
+ this->mutex = new boost::recursive_mutex();
+
std::ostringstream stream;
if (!node)
@@ -89,6 +93,7 @@
/// Destructor
OgreVisual::~OgreVisual()
{
+ delete this->mutex;
delete this->xyzP;
delete this->rpyP;
delete this->meshNameP;
@@ -116,6 +121,8 @@
// Load the visual
void OgreVisual::Load(XMLConfigNode *node)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
+
std::ostringstream stream;
Pose3d pose;
Vector3 size;
@@ -211,6 +218,7 @@
// Save the visual in XML format
void OgreVisual::Save(std::string &prefix, std::ostream &stream)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
stream << prefix << "<visual>\n";
stream << prefix << " " << *(this->xyzP) << "\n";
stream << prefix << " " << *(this->rpyP) << "\n";
@@ -225,6 +233,7 @@
/// Attach a renerable object to the visual
void OgreVisual::AttachObject( Ogre::MovableObject *obj)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
this->sceneNode->attachObject(obj);
obj->setUserObject( this );
}
@@ -233,6 +242,7 @@
/// Detach all objects
void OgreVisual::DetachObjects()
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
this->sceneNode->detachAllObjects();
}
@@ -240,6 +250,7 @@
/// Get the number of attached objects
unsigned short OgreVisual::GetNumAttached()
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
return this->sceneNode->numAttachedObjects();
}
@@ -247,6 +258,7 @@
/// Get an attached object
Ogre::MovableObject *OgreVisual::GetAttached(unsigned short num)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
return this->sceneNode->getAttachedObject(num);
}
@@ -254,6 +266,7 @@
// Attach a static object
void OgreVisual::MakeStatic()
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
if (!this->staticGeometry)
this->staticGeometry =
OgreAdaptor::Instance()->sceneMgr->createStaticGeometry(this->sceneNode->getName()
+ "_Static");
@@ -271,6 +284,7 @@
/// Attach a mesh to this visual by name
void OgreVisual::AttachMesh( const std::string &meshName )
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
std::ostringstream stream;
Ogre::MovableObject *obj;
stream << this->sceneNode->getName() << "_ENTITY_" << meshName;
@@ -284,6 +298,7 @@
/// Set the scale
void OgreVisual::SetScale(const Vector3 &scale )
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
Ogre::Vector3 vscale;
vscale.x=scale.x;
vscale.y=scale.y;
@@ -295,6 +310,7 @@
/// Get the scale
Vector3 OgreVisual::GetScale()
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
Ogre::Vector3 vscale;
vscale=this->sceneNode->getScale();
return Vector3(vscale.x, vscale.y, vscale.z);
@@ -305,6 +321,8 @@
// Set the material
void OgreVisual::SetMaterial(const std::string &materialName)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
+
if (materialName.empty())
return;
@@ -379,6 +397,7 @@
/// Set the transparency
void OgreVisual::SetTransparency( float trans )
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
unsigned short i = 0, j=0;
Ogre::ColourValue sc, dc;
Ogre::Technique *t;
@@ -443,6 +462,7 @@
void OgreVisual::SetHighlight(bool highlight)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
/*
#include <OgreParticleSystem.h>
#include <iostream>
@@ -485,6 +505,7 @@
/// Set whether the visual should cast shadows
void OgreVisual::SetCastShadows(const bool &shadows)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
for (int i=0; i < this->sceneNode->numAttachedObjects(); i++)
{
Ogre::MovableObject *obj = this->sceneNode->getAttachedObject(i);
@@ -496,6 +517,7 @@
/// Set whether the visual is visible
void OgreVisual::SetVisible(bool visible, bool cascade)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
this->sceneNode->setVisible( visible, cascade );
}
@@ -504,6 +526,7 @@
// Set the position of the visual
void OgreVisual::SetPosition( const Vector3 &pos)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
this->sceneNode->setPosition(pos.x, pos.y, pos.z);
}
@@ -511,6 +534,7 @@
// Set the rotation of the visual
void OgreVisual::SetRotation( const Quatern &rot)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
this->sceneNode->setOrientation(rot.u, rot.x, rot.y, rot.z);
}
@@ -518,6 +542,7 @@
// Set the pose of the visual
void OgreVisual::SetPose( const Pose3d &pose)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
this->SetPosition( pose.pos );
this->SetRotation( pose.rot);
}
@@ -526,6 +551,7 @@
// Set the position of the visual
Vector3 OgreVisual::GetPosition()
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
Ogre::Vector3 vpos;
Vector3 pos;
vpos=this->sceneNode->getPosition();
@@ -539,6 +565,7 @@
// Get the rotation of the visual
Quatern OgreVisual::GetRotation( )
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
Ogre::Quaternion vquatern;
Quatern quatern;
vquatern=this->sceneNode->getOrientation();
@@ -553,6 +580,7 @@
// Get the pose of the visual
Pose3d OgreVisual::GetPose()
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
Pose3d pos;
pos.pos=this->GetPosition();
pos.rot=this->GetRotation();
@@ -563,6 +591,7 @@
// Get this visual Ogre node
Ogre::SceneNode * OgreVisual::GetSceneNode()
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
return this->sceneNode;
}
@@ -571,6 +600,7 @@
/// Create a bounding box for this visual
void OgreVisual::AttachBoundingBox(const Vector3 &min, const Vector3 &max)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
std::ostringstream nodeName;
nodeName << this->sceneNode->getName()<<"_AABB_NODE";
@@ -611,6 +641,7 @@
/// Get the entity that manages this visual
Entity *OgreVisual::GetOwner() const
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
return this->owner;
}
@@ -618,6 +649,7 @@
/// Set to true to show a white bounding box, used to indicate user selection
void OgreVisual::ShowSelectionBox( bool value )
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
Ogre::SceneNode *node = this->sceneNode;
while (node && node->numAttachedObjects() == 0)
Modified: code/branches/federation/gazebo/server/rendering/OgreVisual.hh
===================================================================
--- code/branches/federation/gazebo/server/rendering/OgreVisual.hh
2009-03-12 03:18:46 UTC (rev 7463)
+++ code/branches/federation/gazebo/server/rendering/OgreVisual.hh
2009-03-12 17:47:22 UTC (rev 7464)
@@ -36,6 +36,11 @@
#include "Common.hh"
#include "Param.hh"
+namespace boost
+{
+ class recursive_mutex;
+}
+
namespace gazebo
{
@@ -153,6 +158,8 @@
private: ParamT<Vector3> *sizeP;
private: ParamT<Vector3> *scaleP;
private: ParamT<Vector2<double> > *meshTileP;
+
+ private: boost::recursive_mutex *mutex;
};
}
Deleted: code/branches/federation/gazebo/server/rendering/OgreVisualManager.cc
===================================================================
--- code/branches/federation/gazebo/server/rendering/OgreVisualManager.cc
2009-03-12 03:18:46 UTC (rev 7463)
+++ code/branches/federation/gazebo/server/rendering/OgreVisualManager.cc
2009-03-12 17:47:22 UTC (rev 7464)
@@ -1,118 +0,0 @@
-/*
- * Gazebo - Outdoor Multi-Robot Simulator
- * Copyright (C) 2003
- * Nate Koenig & Andrew Howard
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-/* Desc: Manager of Ogre Visuals
- * Author: Nate Koenig
- * Date: 09 Mar 2009
- * SVN: $Id:$
- */
-
-#include "Model.hh"
-#include "Geom.hh"
-#include "GazeboError.hh"
-#include "GazeboMessage.hh"
-#include "Entity.hh"
-#include "OgreVisual.hh"
-#include "OgreVisualManager.hh"
-
-using namespace gazebo;
-
-////////////////////////////////////////////////////////////////////////////////
-/// Constructor
-OgreVisualManager::OgreVisualManager()
-{
-}
-
-////////////////////////////////////////////////////////////////////////////////
-/// Destructor
-OgreVisualManager::~OgreVisualManager()
-{
-}
-
-////////////////////////////////////////////////////////////////////////////////
-/// Create a new ogre visual
-OgreVisual *OgreVisualManager::CreateVisual( const std::string &name,
- OgreVisual *parent, Entity *owner)
-{
- OgreVisual *newVis = NULL;
- std::map<std::string, OgreVisual*>::iterator iter;
-
- iter = this->visuals.find(name);
-
- if (iter == this->visuals.end())
- {
- newVis = new OgreVisual(parent, owner);
- newVis->SetName(name);
- this->visuals[name] = newVis;
- }
- else
- gzthrow(std::string("Name of ogre visual already exists: ") + name);
-
- return newVis;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-/// Delete a visual
-void OgreVisualManager::DeleteVisual( OgreVisual *visual )
-{
- std::map<std::string, OgreVisual*>::iterator iter;
-
- iter = this->visuals.find(visual->GetName());
-
- if (iter != this->visuals.end())
- {
- delete iter->second;
- iter->second = NULL;
- this->visuals.erase(iter);
- }
- else
- {
- gzerr(0) << "Unknown visual[" << visual->GetName() << "]\n";
- }
-
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
-/// Update all the visuals
-void OgreVisualManager::Update()
-{
- std::map<std::string, OgreVisual*>::iterator iter;
- OgreVisual *vis = NULL;
- Entity *owner = NULL;
- Pose3d pose;
-
- //printf("----------------------\n");
- for (iter = this->visuals.begin(); iter != this->visuals.end(); iter++)
- {
- vis = iter->second;
- owner = vis->GetOwner();
- if (!owner)
- continue;
-
- Geom *geom = dynamic_cast<Geom*>(owner);
-
- if (geom || !owner->GetParent())
- vis->SetPose(owner->GetPose());
- else
- vis->SetPose(owner->GetPose() - owner->GetParent()->GetPose());
- }
-}
-
Deleted: code/branches/federation/gazebo/server/rendering/OgreVisualManager.hh
===================================================================
--- code/branches/federation/gazebo/server/rendering/OgreVisualManager.hh
2009-03-12 03:18:46 UTC (rev 7463)
+++ code/branches/federation/gazebo/server/rendering/OgreVisualManager.hh
2009-03-12 17:47:22 UTC (rev 7464)
@@ -1,75 +0,0 @@
-/*
- * Gazebo - Outdoor Multi-Robot Simulator
- * Copyright (C) 2003
- * Nate Koenig & Andrew Howard
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-/* Desc: Manager of Ogre Visuals
- * Author: Nate Koenig
- * Date: 09 Mar 2009
- * SVN: $Id:$
- */
-
-#ifndef OGREVISUALMANAGER_HH
-#define OGREVISUALMANAGER_HH
-
-#include <map>
-
-#include "SingletonT.hh"
-
-namespace gazebo
-{
- class OgreVisual;
- class Entity;
-
- /// \brief Class to manage all the ogre visuals
- class OgreVisualManager : public SingletonT<OgreVisualManager>
- {
- /// \brief Constructor
- private: OgreVisualManager();
-
- /// \brief Destructor
- private: virtual ~OgreVisualManager();
-
- /// \brief Create a new ogre visual
- /// \param name Unique name for the new visual
- /// \param parent Parent visual
- /// \param owner The entity that owns the visual
- /// \return The new ogre visual
- public: OgreVisual *CreateVisual( const std::string &name,
- OgreVisual *parent=NULL,
- Entity *owner = NULL );
-
- /// \brief Delete a visual
- public: void DeleteVisual( OgreVisual *visual );
-
- /// \brief Remove a visual
- /// \param name Unique name of the visual to remove
- public: void RemoveVisual( const std::string &name );
-
- /// \brief Update all the visuals
- public: void Update();
-
- // All the visuals
- private: std::map<std::string, OgreVisual*> visuals;
-
- private: friend class DestroyerT<OgreVisualManager>;
- private: friend class SingletonT<OgreVisualManager>;
- };
-}
-
-#endif
Modified: code/branches/federation/gazebo/server/rendering/SConscript
===================================================================
--- code/branches/federation/gazebo/server/rendering/SConscript 2009-03-12
03:18:46 UTC (rev 7463)
+++ code/branches/federation/gazebo/server/rendering/SConscript 2009-03-12
17:47:22 UTC (rev 7464)
@@ -13,7 +13,6 @@
'OgreSimpleShape.cc',
'OgreHUD.cc',
'OgreVisual.cc',
- 'OgreVisualManager.cc',
'OgreCamera.cc',
'CameraManager.cc',
'UserCamera.cc'
@@ -29,7 +28,6 @@
'#/server/rendering/OgreHUD.hh',
'#/server/rendering/OgreSimpleShape.hh',
'#/server/rendering/OgreVisual.hh',
- '#/server/rendering/OgreVisualManager.hh',
'#/server/rendering/OgreCamera.hh',
'#/server/rendering/CameraManager.hh',
'#/server/rendering/UserCamera.hh'
Modified: code/branches/federation/gazebo/server/rendering/UserCamera.cc
===================================================================
--- code/branches/federation/gazebo/server/rendering/UserCamera.cc
2009-03-12 03:18:46 UTC (rev 7463)
+++ code/branches/federation/gazebo/server/rendering/UserCamera.cc
2009-03-12 17:47:22 UTC (rev 7464)
@@ -84,6 +84,7 @@
this->viewport->setVisibilityMask(this->visibilityMask);
+ OgreAdaptor::Instance()->RegisterCamera(this);
}
////////////////////////////////////////////////////////////////////////////////
@@ -92,7 +93,8 @@
{
OgreCamera::UpdateCam();
- OgreAdaptor::Instance()->UpdateWindow(this->window, this);
+ // NATE
+ //OgreAdaptor::Instance()->UpdateWindow(this->window, this);
if (this->saveFramesP->GetValue())
{
@@ -145,3 +147,10 @@
return avgFPS;
}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Get the ogre window
+Ogre::RenderWindow *UserCamera::GetWindow()
+{
+ return this->window;
+}
Modified: code/branches/federation/gazebo/server/rendering/UserCamera.hh
===================================================================
--- code/branches/federation/gazebo/server/rendering/UserCamera.hh
2009-03-12 03:18:46 UTC (rev 7463)
+++ code/branches/federation/gazebo/server/rendering/UserCamera.hh
2009-03-12 17:47:22 UTC (rev 7464)
@@ -72,6 +72,9 @@
/// \brief Get the average FPS
public: virtual float GetAvgFPS();
+ /// \brief Get the ogre window
+ public: Ogre::RenderWindow *GetWindow();
+
/// Pointer to the viewport
protected: Ogre::Viewport *viewport;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit