Revision: 8972
          http://playerstage.svn.sourceforge.net/playerstage/?rev=8972&view=rev
Author:   natepak
Date:     2010-11-17 16:18:26 +0000 (Wed, 17 Nov 2010)

Log Message:
-----------
Added windowmanager

Added Paths:
-----------
    code/gazebo/branches/dev/server/rendering/WindowManager.cc
    code/gazebo/branches/dev/server/rendering/WindowManager.hh

Added: code/gazebo/branches/dev/server/rendering/WindowManager.cc
===================================================================
--- code/gazebo/branches/dev/server/rendering/WindowManager.cc                  
        (rev 0)
+++ code/gazebo/branches/dev/server/rendering/WindowManager.cc  2010-11-17 
16:18:26 UTC (rev 8972)
@@ -0,0 +1,105 @@
+#include <Ogre.h>
+#include <math.h>
+
+#include "OgreAdaptor.hh"
+#include "RTShaderSystem.hh"
+#include "Color.hh"
+#include "GazeboMessage.hh"
+#include "GazeboError.hh"
+#include "Camera.hh"
+#include "RenderControl.hh"
+#include "WindowManager.hh"
+
+using namespace gazebo;
+
+unsigned int WindowManager::windowCounter = 0;
+
+////////////////////////////////////////////////////////////////////////////////
+// Constructor
+WindowManager::WindowManager()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+WindowManager::~WindowManager()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int WindowManager::CreateWindow( RenderControl *control )
+{
+  int result = -1;
+
+  if (control)
+    result = this->CreateWindow( control->GetOgreHandle(), 
+                                 control->GetWidth(), control->GetHeight());
+  else
+    gzerr(0) << "Invalid RenderControl\n";
+
+  return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Attach a camera to a window
+void WindowManager::SetCamera( int windowId, Camera *camera)
+{
+  Ogre::Viewport *viewport = NULL;
+ 
+  viewport = this->windows[windowId]->addViewport(camera->GetCamera());
+
+  double ratio = (double)viewport->getActualWidth() / 
(double)viewport->getActualHeight();
+  double vfov = fabs(2.0 * atan(tan(camera->GetHFOV().GetAsRadian() / 2.0) / 
ratio));
+
+  camera->SetAspectRatio( ratio );
+  camera->GetCamera()->setFOVy(Ogre::Radian(vfov));
+
+  viewport->setClearEveryFrame(true);
+  viewport->setBackgroundColour( Color(0,0,0).GetOgreColor() );
+  viewport->setVisibilityMask(camera->GetVisibilityMask());
+
+  RTShaderSystem::AttachViewport(viewport, camera->GetScene());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Create a window
+int WindowManager::CreateWindow( const std::string ogreHandle, 
+                                                 unsigned int width, 
+                                                 unsigned int height) 
+{
+  Ogre::StringVector paramsVector;
+  Ogre::NameValuePairList params;
+  Ogre::RenderWindow *window = NULL;
+
+  params["parentWindowHandle"] = ogreHandle;
+
+  std::ostringstream stream;
+  stream << "OgreWindow(" << windowCounter++ << ")";
+
+  int attempts = 0;
+  while (window == NULL && (attempts++) < 10)
+  {
+    try
+    {
+      window = OgreAdaptor::Instance()->root->createRenderWindow( 
stream.str(), 
+                     width, height, false, &params);
+    }
+    catch (...)
+    {
+      gzerr(0) << " Unable to create the rendering window\n";
+      window = NULL;
+    }
+  }
+
+  if (attempts >= 10)
+  {
+    gzthrow("Unable to create the rendering window\n");
+  }
+
+  window->setActive(true);
+  //window->setVisible(true);
+  window->setAutoUpdated(false);
+
+  this->windows.push_back(window);
+
+  return this->windows.size()-1;
+}

Added: code/gazebo/branches/dev/server/rendering/WindowManager.hh
===================================================================
--- code/gazebo/branches/dev/server/rendering/WindowManager.hh                  
        (rev 0)
+++ code/gazebo/branches/dev/server/rendering/WindowManager.hh  2010-11-17 
16:18:26 UTC (rev 8972)
@@ -0,0 +1,42 @@
+#ifndef WINDOWMANAGER_HH
+#define WINDOWMANAGER_HH
+
+#include "SingletonT.hh"
+#include <string>
+#include <vector>
+
+namespace Ogre
+{
+  class RenderWindow;
+}
+
+namespace gazebo
+{
+  class RenderControl;
+  class Camera;
+
+  class WindowManager : public SingletonT<WindowManager>
+  {
+    public: WindowManager();
+    public: virtual ~WindowManager();
+
+    public: int CreateWindow( RenderControl *control );
+
+    public: int CreateWindow( std::string ogreHandle, 
+                              unsigned int width, 
+                              unsigned int height );
+
+
+    /// \brief Attach a camera to a window
+    public: void SetCamera( int windowId, Camera *camera);
+
+
+    private: std::vector<Ogre::RenderWindow *> windows;
+
+    private: static unsigned int windowCounter;
+    
+    private: friend class DestroyerT<WindowManager>;
+    private: friend class SingletonT<WindowManager>;
+  };
+}
+#endif


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to