Revision: 7492
http://playerstage.svn.sourceforge.net/playerstage/?rev=7492&view=rev
Author: hsujohnhsu
Date: 2009-03-17 00:23:10 +0000 (Tue, 17 Mar 2009)
Log Message:
-----------
Added ability to select body as well as model.
Added transparency setting for individual geoms.
Added a renderEngineEnabled flag for running headless.
Modified Paths:
--------------
code/gazebo/branches/ogre-1.4.9/server/Simulator.cc
code/gazebo/branches/ogre-1.4.9/server/Simulator.hh
code/gazebo/branches/ogre-1.4.9/server/physics/Body.cc
code/gazebo/branches/ogre-1.4.9/server/physics/Body.hh
code/gazebo/branches/ogre-1.4.9/server/physics/Geom.cc
code/gazebo/branches/ogre-1.4.9/server/physics/Geom.hh
Modified: code/gazebo/branches/ogre-1.4.9/server/Simulator.cc
===================================================================
--- code/gazebo/branches/ogre-1.4.9/server/Simulator.cc 2009-03-17 00:18:30 UTC
(rev 7491)
+++ code/gazebo/branches/ogre-1.4.9/server/Simulator.cc 2009-03-17 00:23:10 UTC
(rev 7492)
@@ -72,8 +72,11 @@
guiEnabled(true),
physicsEnabled(true),
timeout(-1),
- selectedEntity(NULL)
+ selectedEntity(NULL),
+ selectedBody(NULL)
{
+ selectedEntity = NULL;
+ selectedBody = NULL;
}
////////////////////////////////////////////////////////////////////////////////
@@ -94,7 +97,8 @@
GZ_DELETE (this->xmlFile)
GZ_DELETE (this->gazeboConfig)
gazebo::World::Instance()->Close();
- gazebo::OgreAdaptor::Instance()->Close();
+ if (this->renderEngineEnabled)
+ gazebo::OgreAdaptor::Instance()->Close();
//GZ_DELETE(this->renderEngine);
}
@@ -138,10 +142,11 @@
}
// Load the Ogre rendering system
- OgreAdaptor::Instance()->Load(rootNode);
+ if (this->renderEngineEnabled)
+ OgreAdaptor::Instance()->Load(rootNode);
// Create and initialize the Gui
- if (this->guiEnabled)
+ if (this->renderEngineEnabled && this->guiEnabled)
{
try
{
@@ -172,15 +177,16 @@
this->gui = NULL;
//Initialize RenderEngine
- try
- {
- OgreAdaptor::Instance()->Init(rootNode);
- this->renderEngine = OgreAdaptor::Instance();
- }
- catch (gazebo::GazeboError e)
- {
- gzthrow("Failed to Initialize the Rendering engine subsystem\n" << e );
- }
+ if (this->renderEngineEnabled)
+ try
+ {
+ OgreAdaptor::Instance()->Init(rootNode);
+ this->renderEngine = OgreAdaptor::Instance();
+ }
+ catch (gazebo::GazeboError e)
+ {
+ gzthrow("Failed to Initialize the Rendering engine subsystem\n" << e );
+ }
// Initialize the GUI
if (this->gui)
@@ -250,8 +256,11 @@
World::Instance()->GetPhysicsEngine()->Save(prefix, output);
output << "\n";
- this->GetRenderEngine()->Save(prefix, output);
- output << "\n";
+ if (this->renderEngineEnabled)
+ {
+ this->GetRenderEngine()->Save(prefix, output);
+ output << "\n";
+ }
this->gui->Save(prefix, output);
output << "\n";
@@ -281,9 +290,14 @@
{
double step = World::Instance()->GetPhysicsEngine()->GetStepTime();
double physicsUpdateRate =
World::Instance()->GetPhysicsEngine()->GetUpdateRate();
- double renderUpdateRate = OgreAdaptor::Instance()->GetUpdateRate();
+ double renderUpdateRate = 0;
+ double renderUpdatePeriod = 0;
+ if (this->renderEngineEnabled)
+ {
+ renderUpdateRate = OgreAdaptor::Instance()->GetUpdateRate();
+ renderUpdatePeriod = 1.0 / renderUpdateRate;
+ }
double physicsUpdatePeriod = 1.0 / physicsUpdateRate;
- double renderUpdatePeriod = 1.0 / renderUpdateRate;
double currTime;
double elapsedTime;
@@ -295,6 +309,12 @@
{
currTime = this->GetRealTime();
+#ifdef TIMING
+ double tmpT1 = this->GetWallTime();
+ std::cout << "--------------------------- START Simulator::MainLoop()
--------------------------" << std::endl;
+ std::cout << "Simulator::MainLoop() simTime(" << this->simTime << ") world
time (" << tmpT1 << ")" << std::endl;
+#endif
+
if (physicsUpdateRate == 0 ||
currTime - this->prevPhysicsTime >= physicsUpdatePeriod)
{
@@ -319,18 +339,28 @@
World::Instance()->Update();
}
- // Update the rendering
- if (renderUpdateRate == 0 ||
+#ifdef TIMING
+ double tmpT2 = this->GetWallTime();
+ std::cout << "Simulator::MainLoop() World::Instance() TOTAL DT(" <<
tmpT2-tmpT1 << ")" << std::endl;
+#endif
+
+ // Update the gui
+ if (this->renderEngineEnabled &&
+ renderUpdateRate == 0 ||
currTime - this->prevRenderTime >= renderUpdatePeriod)
{
- //this->GetRenderEngine()->Render();
- //this->prevRenderTime = this->GetRealTime();
- }
- // Update the gui
- if (this->gui)
- {
- this->gui->Update();
+ // Update the gui
+ if (this->gui)
+ {
+ this->gui->Update();
+#ifdef TIMING
+ double tmpT3 = this->GetWallTime();
+ std::cout << "Simulator::MainLoop() GUI DT(" << tmpT3-tmpT2 << ")" <<
std::endl;
+#endif
+ }
+
+ this->prevRenderTime = this->GetRealTime();
}
elapsedTime = (this->GetRealTime() - currTime);
@@ -341,6 +371,10 @@
usleep( (int)((1.0/MAX_FRAME_RATE - elapsedTime) * 1e6) );
}*/
+#ifdef TIMING
+ std::cout << "--------------------------- END Simulator::MainLoop()
--------------------------" << std::endl;
+#endif
+
if (this->timeout > 0 && this->GetRealTime() > this->timeout)
break;
}
@@ -362,7 +396,10 @@
OgreAdaptor *Simulator::GetRenderEngine() const
{
- return this->renderEngine;
+ if (this->renderEngineEnabled)
+ return this->renderEngine;
+ else
+ return NULL;
}
////////////////////////////////////////////////////////////////////////////////
@@ -463,6 +500,20 @@
}
////////////////////////////////////////////////////////////////////////////////
+// True if the gui is to be used
+void Simulator::SetRenderEngineEnabled( bool enabled )
+{
+ this->renderEngineEnabled = enabled;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Return true if the gui is enabled
+bool Simulator::GetRenderEngineEnabled() const
+{
+ return this->renderEngineEnabled;
+}
+
+////////////////////////////////////////////////////////////////////////////////
/// Set the length of time the simulation should run.
void Simulator::SetTimeout(double time)
{
@@ -487,17 +538,36 @@
/// Set the selected entity
void Simulator::SetSelectedEntity( Entity *ent )
{
+ // unselect selectedEntity
if (this->selectedEntity)
{
this->selectedEntity->GetVisualNode()->ShowSelectionBox(false);
+ this->selectedEntity->SetTransparency(0.0);
this->selectedEntity->SetSelected(false);
+ std::cout << " UnSetSelected Entity : " << this->selectedEntity->GetName()
<< std::endl;
}
+ // unselect selectedBody
+ if (this->selectedBody)
+ {
+ this->selectedBody->GetVisualNode()->ShowSelectionBox(false);
+ this->selectedBody->SetTransparency(0.0);
+ this->selectedBody->SetSelected(false);
+ std::cout << " UnSetSelected Body : " << this->selectedBody->GetName() <<
std::endl;
+ this->selectedBody = NULL;
+ }
+ // if a different entity is selected, show bounding box and SetSelected(true)
if (this->selectedEntity != ent)
{
+ // set selected entity to ent
this->selectedEntity = ent;
this->selectedEntity->GetVisualNode()->ShowSelectionBox(true);
+ this->selectedEntity->SetTransparency(0.6);
this->selectedEntity->SetSelected(true);
+ std::cout << " SetSelected Entity : " << this->selectedEntity->GetName()
<< std::endl;
+ std::cout << " ------------------------------------------------------- "
<< std::endl;
+ std::cout << " Drag with left mouse button to rotate in the plane of the
camera view port." << std::endl;
+ std::cout << " Drag with right mouse button to reposition object in the
plane of the camera view port." << std::endl;
}
else
this->selectedEntity = NULL;
@@ -512,6 +582,51 @@
}
////////////////////////////////////////////////////////////////////////////////
+/// Set the selected entity
+void Simulator::SetSelectedBody( Body *bod )
+{
+ // unselect selectedEntity
+ if (this->selectedEntity)
+ {
+ this->selectedEntity->GetVisualNode()->ShowSelectionBox(false);
+ this->selectedEntity->SetTransparency(0.0);
+ this->selectedEntity->SetSelected(false);
+ std::cout << " UnSetSelected Entity : " << this->selectedEntity->GetName()
<< std::endl;
+ this->selectedEntity = NULL;
+ }
+ // unselect selectedBody
+ if (this->selectedBody)
+ {
+ this->selectedBody->GetVisualNode()->ShowSelectionBox(false);
+ this->selectedBody->SetTransparency(0.0);
+ this->selectedBody->SetSelected(false);
+ std::cout << " UnSetSelected Body : " << this->selectedBody->GetName() <<
std::endl;
+ }
+
+ if (this->selectedBody != bod)
+ {
+ this->selectedBody = bod;
+ this->selectedBody->GetVisualNode()->ShowSelectionBox(true);
+ this->selectedBody->SetTransparency(0.6);
+ this->selectedBody->SetSelected(true);
+ std::cout << " SetSelected Body : " << this->selectedBody->GetName() <<
std::endl;
+ std::cout << " ------------------------------------------------------- "
<< std::endl;
+ std::cout << " Drag with left mouse button to apply torque." << std::endl;
+ std::cout << " Drag with right mouse button to apply force." << std::endl;
+ }
+ else
+ this->selectedBody = NULL;
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Get the selected body
+Body *Simulator::GetSelectedBody() const
+{
+ return this->selectedBody;
+}
+
+////////////////////////////////////////////////////////////////////////////////
/// Get the model that currently selected
Model *Simulator::GetSelectedModel() const
{
Modified: code/gazebo/branches/ogre-1.4.9/server/Simulator.hh
===================================================================
--- code/gazebo/branches/ogre-1.4.9/server/Simulator.hh 2009-03-17 00:18:30 UTC
(rev 7491)
+++ code/gazebo/branches/ogre-1.4.9/server/Simulator.hh 2009-03-17 00:23:10 UTC
(rev 7492)
@@ -45,6 +45,7 @@
class GazeboConfig;
class OgreAdaptor;
class Entity;
+ class Body;
class Model;
/// \brief The World
@@ -141,6 +142,12 @@
/// \brief Return true if the gui is enabled
public: bool GetGuiEnabled() const;
+ /// \brief True if the gui is to be used
+ public: void SetRenderEngineEnabled( bool enabled );
+
+ /// \brief Return true if the gui is enabled
+ public: bool GetRenderEngineEnabled() const;
+
/// \brief Set the length of time the simulation should run.
public: void SetTimeout(double time);
@@ -152,9 +159,11 @@
/// \brief Set the selected entity
public: void SetSelectedEntity( Entity *ent );
+ public: void SetSelectedBody( Body *bod );
/// \brief Get the selected entity
public: Entity *GetSelectedEntity() const;
+ public: Body *GetSelectedBody() const;
/// \brief Get the model that currently selected
public: Model *GetSelectedModel() const;
@@ -207,6 +216,9 @@
/// True if the GUI is enabled
private: bool guiEnabled;
+ /// True if the Rendering Engine is enabled
+ private: bool renderEngineEnabled;
+
/// True if physics is enabled
private: bool physicsEnabled;
@@ -215,6 +227,7 @@
/// The entity currently selected by the user
private: Entity *selectedEntity;
+ private: Body *selectedBody;
//Singleton implementation
private: friend class DestroyerT<Simulator>;
Modified: code/gazebo/branches/ogre-1.4.9/server/physics/Body.cc
===================================================================
--- code/gazebo/branches/ogre-1.4.9/server/physics/Body.cc 2009-03-17
00:18:30 UTC (rev 7491)
+++ code/gazebo/branches/ogre-1.4.9/server/physics/Body.cc 2009-03-17
00:23:10 UTC (rev 7492)
@@ -719,4 +719,16 @@
return NULL;
}
}
-
+
+////////////////////////////////////////////////////////////////////////////////
+/// Set transparency of the Body (children Geoms and Visuals)
+void Body::SetTransparency(float t)
+{
+ std::map< std::string, Geom* >::iterator giter;
+ // Fixup the poses of the geoms (they are attached to the CoM)
+ for (giter = this->geoms.begin(); giter != this->geoms.end(); giter++)
+ {
+ giter->second->SetTransparency(t);
+ }
+
+}
Modified: code/gazebo/branches/ogre-1.4.9/server/physics/Body.hh
===================================================================
--- code/gazebo/branches/ogre-1.4.9/server/physics/Body.hh 2009-03-17
00:18:30 UTC (rev 7491)
+++ code/gazebo/branches/ogre-1.4.9/server/physics/Body.hh 2009-03-17
00:23:10 UTC (rev 7492)
@@ -164,6 +164,9 @@
/// \brief Update the pose of the body
private: void UpdatePose();
+ /// \brief Set transparency for all child geometries
+ public: void SetTransparency(float t);
+
/// List of geometries attached to this body
private: std::map< std::string, Geom* > geoms;
Modified: code/gazebo/branches/ogre-1.4.9/server/physics/Geom.cc
===================================================================
--- code/gazebo/branches/ogre-1.4.9/server/physics/Geom.cc 2009-03-17
00:18:30 UTC (rev 7491)
+++ code/gazebo/branches/ogre-1.4.9/server/physics/Geom.cc 2009-03-17
00:23:10 UTC (rev 7492)
@@ -469,14 +469,29 @@
{
for (iter = this->visuals.begin(); iter != this->visuals.end(); iter++)
{
- (*iter)->SetTransparency(0.6);
+ this->SetTransparency(0.6);
}
}
else
{
for (iter = this->visuals.begin(); iter != this->visuals.end(); iter++)
{
+ this->SetTransparency(0.0);
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Set transparency for visuals of this Geom
+void Geom::SetTransparency(float t)
+{
+ std::vector<OgreVisual*>::iterator iter;
+
+ if (Simulator::Instance()->GetRenderEngineEnabled())
+ for (iter = this->visuals.begin(); iter != this->visuals.end(); iter++)
+ {
(*iter)->SetTransparency(0.0);
+ (*iter)->SetTransparency(t);
}
}
}
Modified: code/gazebo/branches/ogre-1.4.9/server/physics/Geom.hh
===================================================================
--- code/gazebo/branches/ogre-1.4.9/server/physics/Geom.hh 2009-03-17
00:18:30 UTC (rev 7491)
+++ code/gazebo/branches/ogre-1.4.9/server/physics/Geom.hh 2009-03-17
00:23:10 UTC (rev 7492)
@@ -159,6 +159,9 @@
/// \brief Get the model this geom belongs to
public: Model *GetModel() const;
+ /// \brief Set transparency of all visuals
+ public: void SetTransparency(float t);
+
/// Contact parameters
public: ContactParams *contact;
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