Update of /cvsroot/playerstage/code/gazebo/server/rendering
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11622/server/rendering
Added Files:
Tag: ogre
OgreAdaptor.cc OgreAdaptor.hh OgreFrameListener.cc
OgreFrameListener.hh SConscript
Log Message:
Added new gazebo files
--- NEW FILE: OgreAdaptor.hh ---
/*
* 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: Middleman between OGRE and Gazebo
* Author: Nate Koenig
* Date: 13 Feb 2006
* CVS: $Id: OgreAdaptor.hh,v 1.1.2.1 2006/12/16 22:41:17 natepak Exp $
*/
#ifndef OGREADAPTOR
#define OGREADAPTOR
#include <X11/Xlib.h>
#include <X11/Xutil.h>
namespace Ogre
{
class Root;
class SceneManager;
class RenderWindow;
class Viewport;
class InputReader;
class Window;
class Camera;
class SceneNode;
class LogManager;
}
namespace CEGUI
{
class OgreCEGUIRenderer;
class System;
}
class OgreFrameListener;
class OgreAdaptor
{
/// Constructor
private: OgreAdaptor();
/// Destructor
private: virtual ~OgreAdaptor();
public: static OgreAdaptor *Instance();
// Default initialization. Let OGRE create the window and rendering context
public: int Init();
/// Initialize Ogre Rendering engine
public: int Init(Display *display, XVisualInfo *visual, Window windowId, int
width, int height);
/// Render a single frame
public: int Render();
private: void SetupResources();
private: void SetupRenderSystem(bool create);
private: void CreateCameras();
private: void CreateViewports();
public: void CreateScene();
private: void CreateWindow(int width, int height);
public: Ogre::Root *root;
public: Ogre::SceneManager *sceneMgr;
public: Ogre::RenderWindow *window;
public: Ogre::Camera *camera;
public: Ogre::Viewport *viewport;
public: Ogre::InputReader *inputDevice;
public: Ogre::SceneNode *cameraNode;
public: Ogre::SceneNode *cameraPitchNode;
private: Ogre::LogManager *logManager;
// Our custom frame listener
private: OgreFrameListener *frameListener;
/// Render context info
private: Display *display;
private: XVisualInfo *visual;
private: Window windowId;
private: static OgreAdaptor *myself;
// CE GUI stuff
public: CEGUI::OgreCEGUIRenderer *guiRenderer;
public: CEGUI::System *guiSystem;
};
class OgreGLXWindowInterface
{
public: virtual ~OgreGLXWindowInterface() = 0;
// Call this with true when the window is mapped/visible, false when the
window is unmapped/invisible
public: virtual void exposed(bool active) = 0;
// Call this to notify the window was resized
public: virtual void resized(size_t width, size_t height) = 0;
};
#endif
--- NEW FILE: SConscript ---
#Import variable
Import('env staticObjs sharedObjs')
sources = Split('OgreAdaptor.cc OgreFrameListener.cc')
staticObjs.append( env.StaticObject(sources) )
sharedObjs.append( env.SharedObject(sources) )
--- NEW FILE: OgreFrameListener.cc ---
#include <CEGUISystem.h>
#include <OgreCEGUIRenderer.h>
#include <OgreKeyEvent.h>
#include <OgreMouseEvent.h>
#include "Camera.hh"
#include "CameraManager.hh"
#include "OgreAdaptor.hh"
#include "OgreFrameListener.hh"
extern bool userQuit;
OgreFrameListener::OgreFrameListener( OgreAdaptor *ogreAdaptor )
{
this->ogreAdaptor = ogreAdaptor;
this->moveAmount = 5;
this->rotateAmount = 72;
this->eventProcessor = new Ogre::EventProcessor();
this->eventProcessor->initialise(this->ogreAdaptor->window);
this->eventProcessor->startProcessingEvents();
this->eventProcessor->addKeyListener(this);
this->eventProcessor->addMouseListener( this );
this->eventProcessor->addMouseMotionListener( this );
this->inputDevice = this->eventProcessor->getInputReader();
this->directionVec[0] = 0;
this->directionVec[1] = 0;
this->directionVec[2] = 0;
}
OgreFrameListener::~OgreFrameListener()
{
}
bool OgreFrameListener::frameStarted( const Ogre::FrameEvent &evt)
{
Camera *camera;
if ((camera = CameraManager::Instance()->GetActiveCamera()))
{
camera->Translate(this->directionVec * evt.timeSinceLastFrame );
}
return true;
}
bool OgreFrameListener::frameEnded( const Ogre::FrameEvent &/*evt*/)
{
return true;
}
void OgreFrameListener::keyClicked( Ogre::KeyEvent * /*e*/ )
{
}
void OgreFrameListener::keyPressed( Ogre::KeyEvent *e )
{
switch (e->getKey())
{
case Ogre::KC_ESCAPE:
userQuit = true;
break;
case Ogre::KC_UP:
case Ogre::KC_W:
this->directionVec.z -= this->moveAmount;
break;
case Ogre::KC_DOWN:
case Ogre::KC_S:
this->directionVec.z += this->moveAmount;
break;
case Ogre::KC_LEFT:
case Ogre::KC_A:
this->directionVec.x -= this->moveAmount;
break;
case Ogre::KC_RIGHT:
case Ogre::KC_D:
this->directionVec.x += this->moveAmount;
break;
case Ogre::KC_PGDOWN:
case Ogre::KC_E:
this->directionVec.y -= this->moveAmount;
break;
case Ogre::KC_PGUP:
case Ogre::KC_Q:
this->directionVec.y += this->moveAmount;
break;
}
}
void OgreFrameListener::keyReleased( Ogre::KeyEvent *e )
{
switch (e->getKey())
{
case Ogre::KC_UP:
case Ogre::KC_W:
this->directionVec.z += this->moveAmount;
break;
case Ogre::KC_DOWN:
case Ogre::KC_S:
this->directionVec.z -= this->moveAmount;
break;
case Ogre::KC_LEFT:
case Ogre::KC_A:
this->directionVec.x += this->moveAmount;
break;
case Ogre::KC_RIGHT:
case Ogre::KC_D:
this->directionVec.x -= this->moveAmount;
break;
case Ogre::KC_PGDOWN:
case Ogre::KC_E:
this->directionVec.y += this->moveAmount;
break;
case Ogre::KC_PGUP:
case Ogre::KC_Q:
this->directionVec.y -= this->moveAmount;
break;
}
}
void OgreFrameListener::mouseDragged(Ogre::MouseEvent* e)
{
Camera *camera;
if ((camera = CameraManager::Instance()->GetActiveCamera()))
{
camera->RotateYaw(-e->getRelX( ) * this->rotateAmount);
camera->RotatePitch(-e->getRelY() * this->rotateAmount);
}
}
void OgreFrameListener::mouseMoved(Ogre::MouseEvent *e)
{
// Update CEGUI with the mouse motion
/* CEGUI::System::getSingleton().injectMouseMove(
e->getRelX() * this->ogreAdaptor->guiRenderer->getWidth(),
e->getRelY() * this->ogreAdaptor->guiRenderer->getHeight());
*/
}
void OgreFrameListener::mousePressed(Ogre::MouseEvent* e)
{
CEGUI::MouseCursor::getSingleton().hide();
}
void OgreFrameListener::mouseReleased(Ogre::MouseEvent* e)
{
CEGUI::MouseCursor::getSingleton().show();
}
--- NEW FILE: OgreFrameListener.hh ---
#ifndef OGREFRAMELISTENER_HH
#define OGREFRAMELISTENER_HH
#include <OgreFrameListener.h>
#include <OgreEventListeners.h>
#include <Ogre.h>
namespace Ogre
{
class EventProcessor;
class InputReader;
class MouseEvent;
}
class OgreAdaptor;
class OgreFrameListener : public Ogre::FrameListener, public Ogre::KeyListener,
public Ogre::MouseListener, public Ogre::MouseMotionListener
{
public: OgreFrameListener( OgreAdaptor *ogreAdaptor );
public: virtual ~OgreFrameListener();
public: virtual bool frameStarted( const Ogre::FrameEvent &evt);
public: virtual bool frameEnded( const Ogre::FrameEvent &evt);
public: virtual void keyClicked( Ogre::KeyEvent *e );
public: virtual void keyPressed( Ogre::KeyEvent *e );
public: virtual void keyReleased( Ogre::KeyEvent *e );
// MouseDragged
public: void mouseMoved(Ogre::MouseEvent *e);
public: void mouseDragged(Ogre::MouseEvent* e);
// MouseListener
public: void mouseClicked(Ogre::MouseEvent* /*e*/){}
public: void mouseEntered(Ogre::MouseEvent* /*e*/) {}
public: void mouseExited(Ogre::MouseEvent* /*e*/) {}
public: void mouseReleased(Ogre::MouseEvent* e);
public: void mousePressed(Ogre::MouseEvent* e);
private: Ogre::Vector3 directionVec;
private: OgreAdaptor *ogreAdaptor;
private: float moveAmount;
private: float rotateAmount;
private: Ogre::EventProcessor *eventProcessor;
private: Ogre::InputReader *inputDevice;
};
#endif
--- NEW FILE: OgreAdaptor.cc ---
#include <CEGUISystem.h>
#include <CEGUISchemeManager.h>
#include <OgreCEGUIRenderer.h>
#include <OgreLogManager.h>
#include <Ogre.h>
#include "OgreFrameListener.hh"
#include "OgreAdaptor.hh"
OgreAdaptor *OgreAdaptor::myself = NULL;
/// Constructor
OgreAdaptor::OgreAdaptor()
{
printf("Create Log Manager\n");
// Create a new log manager and prevent output from going to stdout
this->logManager = new Ogre::LogManager();
this->logManager->createLog("Ogre.log", true, false, false);
printf("Create Root\n");
// Make the root
this->root = new Ogre::Root();
printf("Post Create Root\n");
}
/// Destructor
OgreAdaptor::~OgreAdaptor()
{
}
OgreAdaptor *OgreAdaptor::Instance()
{
printf("Before\n");
if (myself == NULL)
myself = new OgreAdaptor();
printf("After\n");
return myself;
}
int OgreAdaptor::Init()
{
printf("init1\n");
// Setup the available resources
this->SetupResources();
printf("init2\n");
// Setup the rendering system, and create the context
this->SetupRenderSystem(true);
printf("init3\n");
// Initialize the root node, and create a window
this->window = this->root->initialise(true);
printf("init4\n");
// Get the SceneManager, in this case a generic one
this->sceneMgr = this->root->createSceneManager(Ogre::ST_GENERIC);
printf("init5\n");
this->CreateCameras();
printf("init6\n");
this->CreateViewports();
printf("init7\n");
// Set default mipmap level (NB some APIs ignore this)
Ogre::TextureManager::getSingleton().setDefaultNumMipmaps( 5 );
printf("init8\n");
// Load Resources
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
printf("init9\n");
// Default lighting
this->sceneMgr->setAmbientLight(Ogre::ColourValue(0.0f, 0.0f, 0.0f, 1.0f));
this->sceneMgr->setShadowTechnique( Ogre::SHADOWTYPE_STENCIL_ADDITIVE );
printf("init10\n");
// Add a sky dome to our scene
this->sceneMgr->setSkyDome(true,"Gazebo/CloudySky",5,8);
printf("init11\n");
// Create our frame listener and register it
this->frameListener = new OgreFrameListener(this);
this->root->addFrameListener(this->frameListener);
printf("K\n");
// CEGUI setup
this->guiRenderer = new CEGUI::OgreCEGUIRenderer(this->window,
Ogre::RENDER_QUEUE_OVERLAY, false, 0, this->sceneMgr);
/*
printf("L\n");
this->guiSystem = new CEGUI::System(this->guiRenderer);
// Mouse
CEGUI::SchemeManager::getSingleton().loadScheme((CEGUI::utf8*)"TaharezLook.scheme");
CEGUI::MouseCursor::getSingleton().setImage("TaharezLook", "MouseArrow");
*/
return 0;
}
int OgreAdaptor::Init(Display *display, XVisualInfo *visual,
Window windowId, int width, int height)
{
Ogre::NameValuePairList params;
Ogre::StringVector paramsVector;
this->display = display;
this->visual = visual;
this->windowId = windowId;
// Setup the available resources
this->SetupResources();
// Setup the rendering system, and don't create the context
this->SetupRenderSystem(false);
// Initialize the root node, and don't create a window
this->window = this->root->initialise(false);
// Create the window
this->CreateWindow(width,height);
// Get the SceneManager, in this case a generic one
this->sceneMgr = this->root->createSceneManager(Ogre::ST_GENERIC);
this->CreateCameras();
this->CreateViewports();
// Set default mipmap level (NB some APIs ignore this)
Ogre::TextureManager::getSingleton().setDefaultNumMipmaps( 2 );
// Load Resources
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
// Default lighting
this->sceneMgr->setAmbientLight(Ogre::ColourValue(0.8f, 0.8f, 0.8f, 1.0f));
this->sceneMgr->setShadowTechnique( Ogre::SHADOWTYPE_STENCIL_ADDITIVE );
OgreGLXWindowInterface* pWindowInterface = NULL;
this->window->getCustomAttribute("GLXWINDOWINTERFACE", &pWindowInterface);
//pWindowInterface->exposed(true);
// Create our frame listener and register it
this->frameListener = new OgreFrameListener(this);
this->root->addFrameListener(this->frameListener);
return 0;
}
void OgreAdaptor::SetupResources()
{
// Load resource paths from config file
Ogre::ConfigFile cf;
cf.load( "resources.cfg");
// Go through all sections & settings in the file
Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
Ogre::String secName, typeName, archName;
while ( seci.hasMoreElements())
{
secName = seci.peekNextKey();
Ogre::ConfigFile::SettingsMultiMap* settings = seci.getNext();
Ogre::ConfigFile::SettingsMultiMap::iterator i;
for ( i = settings->begin(); i != settings->end(); ++i)
{
typeName = i->first;
archName = i->second;
Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName,
typeName, secName);
}
}
}
void OgreAdaptor::SetupRenderSystem(bool create)
{
// Set parameters of render system (window size, etc.)
//if (!this->root->restoreConfig())
{
Ogre::RenderSystemList *rsList = this->root->getAvailableRenderers();
int c = 0;
Ogre::RenderSystem *selectedRenderSystem = NULL;
do
{
if (c == (int)rsList->size())
break;
selectedRenderSystem = rsList->at(c);
c++;
} while (selectedRenderSystem->getName().compare("OpenGL Rendering
Subsystem")!= 0);
if (selectedRenderSystem == NULL)
printf("ERROR!!!\n");
selectedRenderSystem->setConfigOption("Full Screen","No");
selectedRenderSystem->setConfigOption("FSAA","2");
if (create)
{
selectedRenderSystem->setConfigOption("Video Mode","800 x 600 @ 16-bit
colour");
}
this->root->setRenderSystem(selectedRenderSystem);
}
}
void OgreAdaptor::CreateCameras()
{
// Create the camera
/*this->camera = this->sceneMgr->createCamera( "PlayerCam" );
this->camera->setNearClipDistance(2);
this->cameraNode =
this->sceneMgr->getRootSceneNode()->createChildSceneNode("CameraNode",
Ogre::Vector3(0,5,5));
this->cameraNode->yaw( Ogre::Degree(45) );
this->cameraPitchNode =
this->cameraNode->createChildSceneNode("CameraPitchNode");
this->cameraPitchNode->attachObject(this->camera);
*/
}
void OgreAdaptor::CreateViewports()
{
// Create one viewport, entire window
/*Ogre::Viewport* vp = this->window->addViewport(this->camera);
vp->setBackgroundColour( Ogre::ColourValue(0,0,0) );
// Alter the camera aspect ratio to match the viewport
this->camera->setAspectRatio( Ogre::Real(vp->getActualWidth()) /
Ogre::Real(vp->getActualHeight()));
*/
}
void OgreAdaptor::CreateScene()
{
// Create the scene
Ogre::Entity *ent = this->sceneMgr->createEntity( "Ninja", "ninja.mesh" );
ent->setCastShadows(true);
this->sceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
Ogre::Plane plane(Ogre::Vector3::UNIT_Y,0);
Ogre::MeshManager::getSingleton().createPlane("ground",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,plane,
1500,1500,20,20,true,1,5,5,Ogre::Vector3::UNIT_Z);
ent = this->sceneMgr->createEntity( "GroundEntity", "ground");
this->sceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
ent->setMaterialName("Examples/Rockwall");
ent->setCastShadows(false);
Ogre::Light *light = this->sceneMgr->createLight( "Light1" );
light->setType( Ogre::Light::LT_POINT );
light->setPosition( Ogre::Vector3(0,200,-50) );
light->setDiffuseColour( 1.0, 0.0, 0.0 );
light->setSpecularColour( 1.0, 0.0, 0.0 );
}
void OgreAdaptor::CreateWindow(int width, int height)
{
Ogre::StringVector paramsVector;
Ogre::NameValuePairList params;
paramsVector.push_back( Ogre::StringConverter::toString( (int)this->display )
);
paramsVector.push_back(
Ogre::StringConverter::toString((int)this->visual->screen));
paramsVector.push_back( Ogre::StringConverter::toString((int)this->windowId));
paramsVector.push_back( Ogre::StringConverter::toString((int)this->visual));
params["parentWindowHandle"] = Ogre::StringConverter::toString(paramsVector);
this->window = this->root->createRenderWindow( "WindowName", width, height,
false, ¶ms);
}
int OgreAdaptor::Render()
{
Ogre::PlatformManager::getSingleton().messagePump(window);
root->renderOneFrame();
return 0;
}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit