Update of /cvsroot/simspark/simspark/spark/plugin/openglsysogre In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv25806 Added Files: Tag: projectx .cvsignore Makefile.am export.cpp ogrematerialexporter.cpp ogrematerialexporter.h ogrematerialexporter_c.cpp ogremeshexporter.cpp ogremeshexporter.h ogremeshexporter_c.cpp ogreobjectmanager.cpp ogreobjectmanager.h ogreobjectmanager_c.cpp ogrerenderserver.cpp ogrerenderserver.h ogrerenderserver_c.cpp openglsysframelistener.cpp openglsysframelistener.h openglsystemogre.cpp openglsystemogre.h openglsystemogre_c.cpp Log Message: added ogre renderer --- NEW FILE: .cvsignore --- *.la *.lo .deps .libs Makefile Makefile.in --- NEW FILE: ogrematerialexporter.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Tue May 9 2006 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: ogrematerialexporter.h,v 1.1.2.1 2007/07/18 23:06:41 fruit Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. MaterialExporter NOTE: This class serves as an (abstract) exporter to register materials with other graphic engines (possibly also for exporting). HISTORY: 03/05/07 - OO - Initial version */ #ifndef OGREMATERIALEXPORTER_H #define OGREMATERIALEXPORTER_H #include <kerosin/materialserver/materialexporter.h> /** \class OgreMaterialExporter. This class implements a MaterialExporter for the ogre render server, which needs to be informed about the materials used for a specific simulation. By registering an OgreMaterialExporter implementation to the MaterialServer, materials are registered to the Ogre system. */ class OgreMaterialExporter : public kerosin::MaterialExporter { public: OgreMaterialExporter() { std::cerr << "OgreMaterialExporter constructed\n"; } virtual ~OgreMaterialExporter() { std::cerr << "OgreMaterialExporter destroyed\n"; } /** Register / Export the given material. \param material the material to register / export. */ virtual void RegisterMaterial(boost::shared_ptr<kerosin::Material> basematerial); }; DECLARE_CLASS(OgreMaterialExporter); #endif // OGREMATERIALEXPORTER --- NEW FILE: openglsysframelistener.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Tue May 9 2006 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: openglsysframelistener.cpp,v 1.1.2.1 2007/07/18 23:06:42 fruit Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. OpenGLSysFrameListener (derived from ExampleFrameListener shipping with OGRE) HISTORY: 16/03/07 - OO - Initial version */ #include "openglsysframelistener.h" using namespace Ogre; using namespace OIS; void OpenGLSysFrameListener::UpdateStats() { return; #if 0 static String currFps = "Current FPS: "; static String avgFps = "Average FPS: "; static String bestFps = "Best FPS: "; static String worstFps = "Worst FPS: "; static String tris = "Triangle Count: "; static String batches = "Batch Count: "; // update stats when necessary try { OverlayElement* guiAvg = OverlayManager::getSingleton().getOverlayElement("Spark/AverageFps"); OverlayElement* guiCurr = OverlayManager::getSingleton().getOverlayElement("Spark/CurrFps"); OverlayElement* guiBest = OverlayManager::getSingleton().getOverlayElement("Spark/BestFps"); OverlayElement* guiWorst = OverlayManager::getSingleton().getOverlayElement("Spark/WorstFps"); const RenderTarget::FrameStats& stats = mWindow->getStatistics(); guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS)); guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS)); guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS) +" "+StringConverter::toString(stats.bestFrameTime)+" ms"); guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS) +" "+StringConverter::toString(stats.worstFrameTime)+" ms"); OverlayElement* guiTris = OverlayManager::getSingleton().getOverlayElement("Spark/NumTris"); guiTris->setCaption(tris + StringConverter::toString(stats.triangleCount)); OverlayElement* guiBatches = OverlayManager::getSingleton().getOverlayElement("Spark/NumBatches"); guiBatches->setCaption(batches + StringConverter::toString(stats.batchCount)); OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Spark/DebugText"); mDebugText = "P: " + StringConverter::toString(mOOM->GetMainCamera()->getDerivedPosition()) + " " + "O: " + StringConverter::toString(mOOM->GetMainCamera()->getDerivedOrientation()); guiDbg->setCaption(mDebugText); } catch(...) { /* ignore */ } #endif } OpenGLSysFrameListener::OpenGLSysFrameListener(RenderWindow* win, OgreObjectManager* oom, bool bufferedKeys, bool bufferedMouse, bool bufferedJoy) : mOOM(oom), mTranslateVector(Vector3::ZERO), mWindow(win), mStatsOn(true), mNumScreenShots(0), mMoveScale(0.0f), mRotScale(0.0f), mTimeUntilNextToggle(0), mFiltering(TFO_BILINEAR), mAniso(1), mSceneDetailIndex(0), mMoveSpeed(40), mRotateSpeed(36), mDebugOverlay(0), mShowBBs(false) // mInputManager(0), mMouse(0), mKeyboard(0), mJoy(0), { mDebugOverlay = OverlayManager::getSingleton().getByName("Spark/DebugOverlay"); // LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***"); ParamList pl; size_t windowHnd = 0; std::ostringstream windowHndStr; win->getCustomAttribute("WINDOW", &windowHnd); windowHndStr << windowHnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); #if 0 mInputManager = InputManager::createInputSystem( pl ); //Create all devices (We only catch joystick exceptions here, as, most people have Key/Mouse) mKeyboard = static_cast<Keyboard*>(mInputManager->createInputObject( OISKeyboard, bufferedKeys )); mMouse = static_cast<Mouse*>(mInputManager->createInputObject( OISMouse, bufferedMouse )); try { mJoy = static_cast<JoyStick*>(mInputManager->createInputObject( OISJoyStick, bufferedJoy )); } catch(...) { mJoy = 0; } #endif //Set initial mouse clipping size windowResized(mWindow); showDebugOverlay(true); //Register as a Window listener WindowEventUtilities::addWindowEventListener(mWindow, this); } OpenGLSysFrameListener::~OpenGLSysFrameListener() { //Remove ourself as a Window listener WindowEventUtilities::removeWindowEventListener(mWindow, this); windowClosed(mWindow); } void OpenGLSysFrameListener::windowResized(RenderWindow* rw) { unsigned int width, height, depth; int left, top; rw->getMetrics(width, height, depth, left, top); #if 0 const OIS::MouseState &ms = mMouse->getMouseState(); ms.width = width; ms.height = height; #endif } void OpenGLSysFrameListener::windowClosed(RenderWindow* rw) { #if 0 //Only close for window that created OIS (the main window for us) if (rw == mWindow) { if (mInputManager) { mInputManager->destroyInputObject(mMouse); mInputManager->destroyInputObject(mKeyboard); mInputManager->destroyInputObject(mJoy); OIS::InputManager::destroyInputSystem(mInputManager); mInputManager = 0; } } #endif } #if 0 bool OpenGLSysFrameListener::processUnbufferedKeyInput(const FrameEvent& evt) { if (mKeyboard->isKeyDown(KC_A)) mTranslateVector.x = -mMoveScale; // Move camera left if (mKeyboard->isKeyDown(KC_D)) mTranslateVector.x = mMoveScale; // Move camera RIGHT if(mKeyboard->isKeyDown(KC_UP) || mKeyboard->isKeyDown(KC_W) ) mTranslateVector.z = -mMoveScale; // Move camera forward if (mKeyboard->isKeyDown(KC_DOWN) || mKeyboard->isKeyDown(KC_S)) mTranslateVector.z = mMoveScale; // Move camera backward if (mKeyboard->isKeyDown(KC_PGUP)) mTranslateVector.y = mMoveScale; // Move camera up if (mKeyboard->isKeyDown(KC_PGDOWN)) mTranslateVector.y = -mMoveScale; // Move camera down if (mKeyboard->isKeyDown(KC_RIGHT)) mCamera->yaw(-mRotScale); if (mKeyboard->isKeyDown(KC_LEFT)) mCamera->yaw(mRotScale); if (mKeyboard->isKeyDown(KC_ESCAPE) || mKeyboard->isKeyDown(KC_Q)) return false; if (mKeyboard->isKeyDown(KC_F) && mTimeUntilNextToggle <= 0) { mStatsOn = !mStatsOn; showDebugOverlay(mStatsOn); mTimeUntilNextToggle = 1; } if (mKeyboard->isKeyDown(KC_T) && mTimeUntilNextToggle <= 0) { switch(mFiltering) { case TFO_BILINEAR: mFiltering = TFO_TRILINEAR; mAniso = 1; break; case TFO_TRILINEAR: mFiltering = TFO_ANISOTROPIC; mAniso = 8; break; case TFO_ANISOTROPIC: mFiltering = TFO_BILINEAR; mAniso = 1; break; default: break; } MaterialManager::getSingleton().setDefaultTextureFiltering(mFiltering); MaterialManager::getSingleton().setDefaultAnisotropy(mAniso); showDebugOverlay(mStatsOn); mTimeUntilNextToggle = 1; } if (mKeyboard->isKeyDown(KC_SYSRQ) && mTimeUntilNextToggle <= 0) { std::ostringstream ss; ss << "screenshot_" << ++mNumScreenShots << ".png"; mWindow->writeContentsToFile(ss.str()); mTimeUntilNextToggle = 0.5; mDebugText = "Saved: " + ss.str(); } if (mKeyboard->isKeyDown(KC_R) && mTimeUntilNextToggle <=0) { mSceneDetailIndex = (mSceneDetailIndex+1)%3 ; switch(mSceneDetailIndex) { case 0 : mCamera->setPolygonMode(PM_SOLID); break; case 1 : mCamera->setPolygonMode(PM_WIREFRAME); break; case 2 : mCamera->setPolygonMode(PM_POINTS); break; } mTimeUntilNextToggle = 0.5; } static bool displayCameraDetails = true; if (mKeyboard->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0) { displayCameraDetails = !displayCameraDetails; mTimeUntilNextToggle = 0.5; if (!displayCameraDetails) mDebugText = ""; } // Print camera details if (displayCameraDetails) mDebugText = "P: " + StringConverter::toString(mCamera->getDerivedPosition()) + " " + "O: " + StringConverter::toString(mCamera->getDerivedOrientation()); // Return true to continue rendering return true; } bool OpenGLSysFrameListener::processUnbufferedMouseInput(const FrameEvent& evt) { // Rotation factors, may not be used if the second mouse button is pressed // 2nd mouse button - slide, otherwise rotate const MouseState &ms = mMouse->getMouseState(); if (ms.buttonDown( MB_Right )) { mTranslateVector.x += ms.X.rel * 0.13; mTranslateVector.y -= ms.Y.rel * 0.13; } else { mRotX = Degree(-ms.X.rel * 0.13); mRotY = Degree(-ms.Y.rel * 0.13); } return true; } #endif #if 0 void OpenGLSysFrameListener::moveCamera() { // Make all the changes to the camera // Note that YAW direction is around a fixed axis (freelook style) rather than a natural YAW //(e.g. airplane) mCamera->yaw(mRotX); mCamera->pitch(mRotY); mCamera->moveRelative(mTranslateVector); } #endif void OpenGLSysFrameListener::showDebugOverlay(bool show) { if (mDebugOverlay) { if (show) mDebugOverlay->show(); else mDebugOverlay->hide(); } } // Override frameStarted event to process that (don't care about frameEnded) bool OpenGLSysFrameListener::frameStarted(const FrameEvent& evt) { if (mWindow->isClosed()) return false; #if 0 //Need to capture/update each device mKeyboard->capture(); mMouse->capture(); if( mJoy ) mJoy->capture(); bool buffJ = (mJoy) ? mJoy->buffered() : true; // Check if one of the devices is not buffered if (!mMouse->buffered() || !mKeyboard->buffered() || !buffJ) { // one of the input modes is immediate, so setup what is needed for immediate movement if (mTimeUntilNextToggle >= 0) mTimeUntilNextToggle -= evt.timeSinceLastFrame; // If this is the first frame, pick a speed if (evt.timeSinceLastFrame == 0) { mMoveScale = 1; mRotScale = 0.1; } // Otherwise scale movement units by time passed since last frame else { // Move about 100 units per second, mMoveScale = mMoveSpeed * evt.timeSinceLastFrame; // Take about 10 seconds for full rotation mRotScale = mRotateSpeed * evt.timeSinceLastFrame; } mRotX = 0; mRotY = 0; mTranslateVector = Ogre::Vector3::ZERO; } //Check to see which device is not buffered, and handle it if (!mKeyboard->buffered()) if (processUnbufferedKeyInput(evt) == false) return false; if (!mMouse->buffered()) if (processUnbufferedMouseInput(evt) == false) return false; if (!mMouse->buffered() || !mKeyboard->buffered() || !buffJ) moveCamera(); #endif #if 0 static Real timeDelay = 0; timeDelay -= evt.timeSinceLastFrame; KEY_PRESSED(OIS::KC_B, 1, mShowBBs = !mShowBBs, mSceneMgr->showBoundingBoxes(mShowBBs); ) #endif return true; } bool OpenGLSysFrameListener::frameEnded(const FrameEvent& evt) { // UpdateStats(); return true; } --- NEW FILE: ogremeshexporter.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Tue May 9 2006 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: ogremeshexporter.h,v 1.1.2.1 2007/07/18 23:06:41 fruit Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. MeshBridge NOTE: This class serves as an (abstract) exporter to register meshes with other graphic engines (possibly also for exporting). HISTORY: 30/03/07 - OO - Initial version */ #ifndef OGREMESHEXPORTER_H #define OGREMESHEXPORTER_H #include <oxygen/geometryserver/meshexporter.h> /** \class OgreMeshExporter. This class implements a MeshExporter for the ogre render server, which needs to be informed about the meshes used for a specific simulation. By registering an OgreMeshExporter implementation to the GeometryServer, meshes are registered to the Ogre system. */ class OgreMeshExporter : public oxygen::MeshExporter { public: OgreMeshExporter() { std::cerr << "OgreMeshExporter constructed\n"; } virtual ~OgreMeshExporter() { std::cerr << "OgreMeshExporter destroyed\n"; } /** Register / Export the given mesh. \param mesh the mesh to register / export. */ virtual void RegisterMesh(boost::shared_ptr<oxygen::TriMesh> mesh); }; DECLARE_CLASS(OgreMeshExporter); #endif // OGREMESHEXPORTER --- NEW FILE: Makefile.am --- if BUILD_KEROSIN pkglib_LTLIBRARIES = openglsysogre.la endif openglsysogre_la_SOURCES = \ ogrerenderserver.cpp ogrerenderserver_c.cpp ogrerenderserver.h \ openglsysframelistener.h openglsysframelistener.cpp \ openglsystemogre.h openglsystemogre.cpp openglsystemogre_c.cpp \ ogremeshexporter.h ogremeshexporter.cpp ogremeshexporter_c.cpp \ ogrematerialexporter.h ogrematerialexporter.cpp ogrematerialexporter_c.cpp \ ogreobjectmanager.h ogreobjectmanager.cpp ogreobjectmanager_c.cpp export.cpp # -module tells automake we're not building a library but a loadable module # so we don't need the "lib" prefix in the module name ./libois.a openglsysogre_la_LDFLAGS = -module -avoid-version AM_CPPFLAGS = -I${top_srcdir}/lib @RUBY_CPPFLAGS@ #-I/Library/Frameworks/Ogre.framework/Headers --- NEW FILE: openglsystemogre.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Tue May 9 2006 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: openglsystemogre.h,v 1.1.2.1 2007/07/18 23:06:42 fruit Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. OpenGLSystemOGRE HISTORY: 16/03/07 - OO - Initial version */ #ifndef __OpenGLSystemOGRE_H__ #define __OpenGLSystemOGRE_H__ #include <zeitgeist/corecontext.h> #include <kerosin/openglserver/openglsystem.h> #include "openglsystemogre.h" #include "ogreobjectmanager.h" #include "openglsysframelistener.h" #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 #define WIN32_LEAN_AND_MEAN #include "windows.h" #endif using namespace Ogre; #define KEY_PRESSED(_key,_timeDelay, _macro) \ { \ if (mKeyboard->isKeyDown(_key) && timeDelay <= 0) \ { \ timeDelay = _timeDelay; \ _macro ; \ } \ } /** Base class which manages the standard startup of an Ogre application. Designed to be subclassed for specific examples if required. */ class OpenGLSystemOGRE : public kerosin::OpenGLSystem { public: /// Standard constructor OpenGLSystemOGRE(); /// Standard destructor virtual ~OpenGLSystemOGRE(); bool Init(); void Update(); void SwapBuffers(); virtual bool IsGLLocked() const { return true; } protected: void CreateScene(); // Create new frame listener void createFrameListener(); protected: //! a reference to the node where we store some pointers to Ogre objects boost::shared_ptr<OgreObjectManager> mObjectManager; SceneNode *mpObjsNode; // the node wich will hold our entities Ogre::Root *mRoot; OpenGLSysFrameListener* mFrameListener; Ogre::RenderWindow* mWindow; Ogre::String mResourcePath; /** Configures the application. @return false if the user chooses to abandon configuration. */ bool Configure(); void ChooseSceneManager(); void CreateCamera(); void CreateViewports(); /// Method which will define the source of resources (other than current folder) virtual void setupResources(); /// Optional override method where you can create resource listeners (e.g. for loading screens) virtual void createResourceListener(); /// Optional override method where you can perform resource group loading /// Must at least do ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); virtual void loadResources(); }; DECLARE_CLASS(OpenGLSystemOGRE); #endif --- NEW FILE: ogremeshexporter.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Tue May 9 2006 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: ogremeshexporter.cpp,v 1.1.2.1 2007/07/18 23:06:41 fruit Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. MeshExporter NOTE: This class serves as an (abstract) exporter to register meshes with other graphic engines (possibly also for exporting). HISTORY: 30/03/07 - OO - Initial version */ #include "ogremeshexporter.h" #include <zeitgeist/logserver/logserver.h> #ifdef __APPLE__ #include <Ogre/Ogre.h> #else #include <Ogre.h> #endif using namespace Ogre; void OgreMeshExporter::RegisterMesh(boost::shared_ptr<oxygen::TriMesh> mesh) { if (mesh.get() == 0) { GetLog()->Warning() << "(OgreMeshExporter) RegisterMesh with no mesh\n"; return; } GetLog()->Debug() << "(OgreMeshExporter) RegisterMesh " << mesh->GetName() << "\n"; std::cerr << "(OgreMeshExporter) RegisterMesh " << mesh->GetName() << "\n"; // create the same mesh manually in OGRE MeshPtr oMesh = MeshManager::getSingleton().createManual(mesh->GetName() + ".mesh", "Custom"); // we do one submesh per material SubMesh* oSubMesh = oMesh->createSubMesh(); // transfer the vertex data oSubMesh->useSharedVertices = false; oSubMesh->vertexData = new VertexData(); oSubMesh->vertexData->vertexCount = mesh->GetVertexCount(); // declare what the vertex contains VertexDeclaration* declaration = oSubMesh->vertexData->vertexDeclaration; static const unsigned short source = 0; size_t offset = 0; offset += declaration->addElement(source,offset,VET_FLOAT3,VES_POSITION).getSize(); offset += declaration->addElement(source,offset,VET_FLOAT3,VES_NORMAL).getSize(); offset += declaration->addElement(source,offset,VET_FLOAT2,VES_TEXTURE_COORDINATES).getSize(); // we create the hardware vertex buffer HardwareVertexBufferSharedPtr vbuffer = HardwareBufferManager::getSingleton().createVertexBuffer ( declaration->getVertexSize(source), // == offset oSubMesh->vertexData->vertexCount, // == GetVertexCount() HardwareBuffer::HBU_STATIC_WRITE_ONLY); // fill the hardware buffer, and record the axis aligned bounding box AxisAlignedBox aabox; float* vdata = static_cast<float*>(vbuffer->lock(HardwareBuffer::HBL_DISCARD)); const boost::shared_array<float> pos = mesh->GetPos(); const boost::shared_array<float> tex = mesh->GetTexCoords(); for (size_t i=0; i < mesh->GetVertexCount(); ++i) { // std::cerr << "registering pos: " << i << " (" << mesh->GetVertexCount() << ")\n"; // position Vector3 position(pos[i*3 + 0], pos[i*3 + 2], pos[i*3 + 1]); *vdata++ = position.x; *vdata++ = position.y; *vdata++ = position.z; aabox.merge(position); // normal Vector3 normal = position.normalisedCopy(); *vdata++ = normal.x; *vdata++ = normal.y; *vdata++ = normal.z; // texture coordinate #if 1 // std::cerr << "registering tex: " << i << " (" << mesh->GetVertexCount() << ")\n"; if (tex.get() != 0) { // in kerosin, the coordinates are 3-D with the 3rd coordinate set to 0 Vector2 tcoordinate(tex[i*3 + 0], tex[i*3 + 1]); *vdata++ = tcoordinate.x; *vdata++ = tcoordinate.y; } else { *vdata++ = 0.0; *vdata++ = 0.0; } #endif } vbuffer->unlock(); oSubMesh->vertexData->vertexBufferBinding->setBinding(source,vbuffer); // Creates the index data oxygen::TriMesh::TFaces::const_iterator i = mesh->GetFaces().begin(); const size_t verticesPerFace = 3; size_t total_faces = 0; if (mesh->GetFaces().size() < 1) { std::cerr << "(OgreMeshExporter) no faces found\n"; } else { total_faces = i->indeces->GetNumIndex(); if (mesh->GetFaces().size() > 1) { std::cerr << "(OgremeshExporter) ignoring multiple faces (not implemented)\n"; } } // std::cerr << "adding " << total_faces << "\n"; #if 1 oSubMesh->indexData->indexStart = 0; oSubMesh->indexData->indexCount = total_faces; oSubMesh->indexData->indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(HardwareIndexBuffer::IT_16BIT, oSubMesh->indexData->indexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY); uint16* idata = static_cast<uint16*>(oSubMesh->indexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD)); if (i != mesh->GetFaces().end()) { for (int j=0; j<total_faces; j+=3) { *idata++ = ((i->indeces->GetIndex()).get())[j]; *idata++ = ((i->indeces->GetIndex()).get())[j+2]; *idata++ = ((i->indeces->GetIndex()).get())[j+1]; } oSubMesh->indexData->indexBuffer->unlock(); // We must indicate the bounding box oMesh->_setBounds(aabox); oMesh->_setBoundingSphereRadius((aabox.getMaximum()-aabox.getMinimum()).length()/2.0); // Finally we set a material to the submesh oSubMesh->setMaterialName(i->material); } // And we load the mesh oMesh->load(); #endif } --- NEW FILE: ogrerenderserver.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Tue May 9 2006 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: ogrerenderserver.cpp,v 1.1.2.1 2007/07/18 23:06:42 fruit Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. OgreRenderServer NOTE: This is a renderserver in order to support Ogre HISTORY: 29/03/07 - OO - Initial version */ #include "ogrerenderserver.h" #include "ogreobjectmanager.h" #include <oxygen/sceneserver/sceneserver.h> #include <oxygen/sceneserver/scene.h> #include <oxygen/sceneserver/camera.h> #include <boost/shared_ptr.hpp> #include <oxygen/physicsserver/spherecollider.h> // #include <kerosin/renderserver/rendernode.h> #include <kerosin/sceneserver/staticmesh.h> #include <kerosin/sceneserver/light.h> #include <kerosin/materialserver/material.h> // #include <kerosin/openglserver/glbase.h> using namespace boost; using namespace oxygen; OgreRenderServer::OgreRenderServer() : mAmbientLight(Ogre::ColourValue::White) { } void OgreRenderServer::OnLink() { BaseRenderServer::OnLink(); mObjectManager = shared_dynamic_cast<OgreObjectManager>(GetCore()->Get("/sys/ogre/objectmanager")); if (mObjectManager.get() == 0) { std::cerr << "(OgreRenderServer) ERROR: no Ogre objectmanager object found\n"; return; } } void OgreRenderServer::Render() { if (! GetActiveScene() || (mObjectManager.get() == 0)) { std::cerr << "no active scene or no OgreObjectManager\n"; return; } Ogre::ColourValue oldAmbientLight = mAmbientLight; mAmbientLight = Ogre::ColourValue::Black; RenderScene(mActiveScene); CleanUpOgreSceneNodes(); if (oldAmbientLight != mAmbientLight) { Ogre::SceneManager* sceneManager = mObjectManager->GetSceneManager(); sceneManager->setAmbientLight(mAmbientLight); } } void OgreRenderServer::RenderScene(boost::shared_ptr<oxygen::BaseNode> node) { /* here, the kerosin renderserver takes the kerosin/staticmesh rendernode, and renders the node using the staticmesh an registered materials. */ shared_ptr<kerosin::StaticMesh> renderNode = shared_dynamic_cast<kerosin::StaticMesh>(node); if (renderNode.get() != 0) { Ogre::SceneNode* sceneNode = RegisterAtOgre(renderNode); UpdateOgreNode(sceneNode,renderNode); } else { shared_ptr<kerosin::Light> lightNode = shared_dynamic_cast<kerosin::Light>(node); if (lightNode.get() != 0) { Ogre::Light* light = RegisterAtOgre(lightNode); UpdateOgreNode(light,lightNode); } shared_ptr<oxygen::Camera> cameraNode = shared_dynamic_cast<oxygen::Camera>(node); if (cameraNode.get() != 0) { Ogre::Camera* camera = RegisterAtOgre(cameraNode); UpdateOgreNode(camera,cameraNode); } } // traverse the the hierarchy for (TLeafList::iterator i = node->begin(); i!= node->end(); ++i) { shared_ptr<BaseNode> node = shared_dynamic_cast<BaseNode>(*i); if (node.get() == 0) { continue; } RenderScene(node); } } Ogre::SceneNode* OgreRenderServer::RegisterAtOgre(shared_ptr<kerosin::StaticMesh> renderNode) { Ogre::SceneNode* sceneNode = 0; std::pair<TNodeRegistry::iterator, bool> inserted; const std::string entityName = renderNode->GetFullPath(); const std::string nodeName = entityName + ".node"; Ogre::SceneManager* sceneManager = mObjectManager->GetSceneManager(); inserted = mRenderNodeRegistry.insert(TNodeRegistry::value_type(entityName, true)); if (inserted.second) { // the node wasn't registered yet. const std::string meshName = renderNode->UseExternalMesh() ? renderNode->GetExternalMeshName() : renderNode->GetMesh()->GetName() + ".mesh"; if (renderNode->UseExternalMesh()) std::cerr << "(OgreRenderServer) RegisterAtOgre: trying to use ext. Mesh " << meshName << "\n"; // create an entity at ogre Ogre::Entity* entity = sceneManager->createEntity(entityName, meshName); // set if the entity is a shadow caster entity->setCastShadows(renderNode->CastShadows()); /** external meshes come with their own materials (?), so we don't * ** set the name here. */ if (!renderNode->UseExternalMesh()) { // look up and set the first material (right now, we use only one) const std::string materialName = ((renderNode->GetMaterials())[0])->GetName(); /** set all material names (we should get the sub-entities and * ** set different material name separately here. */ entity->setMaterialName(materialName); } // create an ogre scene node and attach the entity sceneNode = sceneManager->getRootSceneNode()->createChildSceneNode(nodeName); sceneNode->attachObject(entity); // finally, set the scale of the object salt::Vector3f scale(renderNode->GetScale()); if (renderNode->UseExternalMesh()) { salt::Vector3f exScale(renderNode->ExternalMeshScale()); std::cerr << "********************************************************************************\n"; std::cerr << "Using external mesh scale: " << exScale << " for " << nodeName << "\n"; std::cerr << "********************************************************************************\n"; sceneNode->setScale(exScale.x()*scale.x(), exScale.z()*scale.z(), exScale.y()*scale.y()); } else { sceneNode->setScale(scale.x(), scale.z(), scale.y()); } } else { // there was already a registered node, so we set <entry>.second to true to indicate // that the node was still processed this cycle. inserted.first->second = true; // get the pointer to the scene node sceneNode = sceneManager->getSceneNode(nodeName); } return sceneNode; } #if 1 Ogre::Light* OgreRenderServer::RegisterAtOgre(shared_ptr<kerosin::Light> lightNode) { /* In Ogre (and similar in kerosin), lights can be attached to a scene node. In this case, the position & direction of the lightin Ogre is derived from the scene node. We don't use this feature here, because we derive the position / direction of the light from simspark. */ Ogre::Light* light = 0; std::pair<TNodeRegistry::iterator, bool> inserted; const std::string lightName = lightNode->GetFullPath(); Ogre::SceneManager* sceneManager = mObjectManager->GetSceneManager(); inserted = mLightNodeRegistry.insert(TNodeRegistry::value_type(lightName, true)); if (inserted.second) { // the node wasn't registered yet. light = sceneManager->createLight(lightName); light->setType(Ogre::Light::LT_POINT); // SPOTLIGHT); // POINT); // //DIRECTIONAL kerosin::RGBA colour = lightNode->GetDiffuse(); light->setDiffuseColour(colour.r(), colour.g(), colour.b()); colour = lightNode->GetSpecular(); light->setSpecularColour(colour.r(), colour.g(), colour.b()); } else { // there was already a registered node, so we set <entry>.second to true to indicate // that the node was still processed this cycle. inserted.first->second = true; // get the pointer to the scene node light = sceneManager->getLight(lightName); } return light; } #endif Ogre::Camera* OgreRenderServer::RegisterAtOgre(shared_ptr<oxygen::Camera> cameraNode) { Ogre::Camera* camera = 0; std::pair<TNodeRegistry::iterator, bool> inserted; const std::string cameraName = cameraNode->GetFullPath(); Ogre::SceneManager* sceneManager = mObjectManager->GetSceneManager(); inserted = mCameraNodeRegistry.insert(TNodeRegistry::value_type(cameraName, true)); if (inserted.second) { // the node wasn't registered yet. const std::string cameraNodeName = cameraName + ".camera"; // create an ogre scene node Ogre::SceneNode* sceneNode = sceneManager->getRootSceneNode()->createChildSceneNode(cameraNodeName); // create an ogre camera node camera = sceneManager->createCamera(cameraName); std::cerr << "(OgreRenderServer) new camera created: " << cameraName << "\n"; camera->setPosition(Ogre::Vector3(0,0,0)); // Look back along -Z camera->lookAt(Ogre::Vector3(0,0,1000)); cameraNode->LookAt(salt::Vector3f(0,-1000,0)); camera->setNearClipDistance(cameraNode->GetZNear()); camera->setFarClipDistance(cameraNode->GetZFar()); camera->setFOVy(Ogre::Degree(cameraNode->GetFOV())); // and now attach the camera to the scene node sceneNode->attachObject(camera); Ogre::Viewport* vp = mObjectManager->GetMainViewport(); camera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight())); vp->setCamera(camera); mObjectManager->SetMainCamera(camera); } else { // there was already a registered node, so we set <entry>.second to true to indicate // that the node was still processed this cycle. inserted.first->second = true; // get the pointer to the camera node camera = sceneManager->getCamera(cameraName); } return camera; } void OgreRenderServer::CleanUpOgreSceneNodes() { TNodeRegistry::iterator i = mRenderNodeRegistry.begin(); while (i != mRenderNodeRegistry.end()) { TNodeRegistry::iterator j = i; j++; if (i->second) { i->second = false; } else { const std::string entityName = i->first; const std::string nodeName = entityName + ".node"; Ogre::SceneManager* sceneManager = mObjectManager->GetSceneManager(); std::cerr << "(OgreRenderServer) cleaning up unused entity node: " << entityName << "\n"; // destroy the scene node sceneManager->destroySceneNode(nodeName); // the entity should be destroyed only after entity and scene node are detached sceneManager->destroyEntity(entityName); mRenderNodeRegistry.erase(i); } i = j; } } void OgreRenderServer::UpdateOgreNode(Ogre::SceneNode* sceneNode, shared_ptr<kerosin::StaticMesh> renderNode) { const salt::Matrix m(renderNode->GetWorldTransform()); salt::Vector3f pos = m.Pos(); // m rotated around z by 180 degrees Ogre::Matrix4 matrix(-m.m[ 0],-m.m[ 1],-m.m[ 2],-m.m[ 3], -m.m[ 4],-m.m[ 5],-m.m[ 6],-m.m[ 7], m.m[ 8], m.m[ 9], m.m[10],m.m[11], m.m[12], m.m[13], m.m[14],m.m[15]); sceneNode->setPosition(pos.x(), pos.z(), -pos.y()); Ogre::Quaternion q = matrix.extractQuaternion(); sceneNode->setOrientation(q[0],-q[1],-q[3],q[2]); } void OgreRenderServer::UpdateOgreNode(Ogre::Light* light, shared_ptr<kerosin::Light> lightNode) { const salt::Matrix m(lightNode->GetWorldTransform()); salt::Vector3f pos = m.Pos(); light->setPosition(pos.x(), pos.z(), -pos.y()); // setDirection takes 3 params (describing an angle, I guess) // applies to spotlights and directional lights only // and so far there are none of these in simspark (?). To simulate at least // directional lights, we take the direction as the vector from position to origin. // Directional Lights don't have a position, so for these, that is a working fix. // For spot lights, the approach does have do be changed. light->setDirection(-pos.x(),-pos.z(), pos.y()); // light->setDirection(0,-1, -1); kerosin::RGBA colour = lightNode->GetAmbient(); mAmbientLight.r = std::min(1.0f, mAmbientLight.r + colour.r()); mAmbientLight.g = std::min(1.0f, mAmbientLight.g + colour.g()); mAmbientLight.b = std::min(1.0f, mAmbientLight.b + colour.b()); mAmbientLight.a = std::min(1.0f, mAmbientLight.a + colour.a()); } void OgreRenderServer::UpdateOgreNode(Ogre::Camera* camera, shared_ptr<oxygen::Camera> cameraNode) { const salt::Matrix m(cameraNode->GetWorldTransform()); // m rotated around z by 180 degrees Ogre::Matrix4 matrix(-m.m[ 0],-m.m[ 1],-m.m[ 2],-m.m[ 3], -m.m[ 4],-m.m[ 5],-m.m[ 6],-m.m[ 7], m.m[ 8], m.m[ 9], m.m[10], m.m[11], m.m[12], m.m[13], m.m[14], m.m[15]); salt::Vector3f pos = m.Pos(); Ogre::SceneNode* camNode = camera->getParentSceneNode(); if (camNode == 0) { // shouldn't happen, but just in case we try to be nice camera->setPosition(pos.x(), pos.z(), -pos.y()); } else { camNode->setPosition(pos.x(), pos.z(), -pos.y()); Ogre::Quaternion q = matrix.extractQuaternion(); /** ohne drehung der matrix: ohne aenderung: rotation um y beim links/rechts schauen, vorwaerts rueckwaerts vertauscht -q[0]: rotation um y beim links rechts schauen -q[1]: rotation um y beim links rechts schauen -q[2]: rotation um y beim links rechts schauen -q[3]: rotation um y beim links rechts schauen, hoch runter schauen vertauscht -q[0],-q[1]: rotation um y beim links rechts schauen, hoch runter schauen vertauscht -q[0],-q[2]: rotation um y beim links rechts schauen, hoch runter schauen vertauscht -q[0],-q[3]: rotation um y beim links rechts schauen -q[1],-q[2]: rotation um y beim links rechts schauen ... q[2],q[3] vertauscht: links/rechts rotation falsch, sonst alles richtig -q[0]; q[2],q[3] vertauscht: rotation um die y achse beim hoch/runterschauen -q[1]; q[2],q[3] vertauscht: links/rechts rotation falsch, rotation um y achse beim hoch runter -q[2]; q[2],q[3] vertauscht: links/rechts rotation falsch, rotation um y achse beim hoch runter -q[3]; q[2],q[3] vertauscht: links/rechts vo/hi vertauscht, rotation um y achse beim hoch runter -q[0],-q[1]; q[2],q[3] vertauscht: links/rechts vo/hi vertauscht, sonst alles richtig -q[0],-q[2]; q[2],q[3] vertauscht: links/rechts vo/hi vertauscht, hoch/runter schaun vertauscht -q[0],-q[3]; q[2],q[3] vertauscht: hoch/runter und links/rechts rotation vertauscht -q[1],-q[2]; q[2],q[3] vertauscht: hoch/runter und links/rechts rotation vertauscht -q[1],-q[3]; q[2],q[3] vertauscht: hoch/runter schaun vertauscht, li/re vo/hi vertauscht -q[2],-q[3]; q[2],q[3] vertauscht: li/re vo/hi vertauscht -q[0],-q[1],-q[2]; q[2],q[3] vertauscht: links/rechts vo/hi vertauscht, rotation um y beim hoch runter -q[0],-q[1],-q[3]; q[2],q[3] vertauscht: rotation um die y achse beim hoch/runterschauen -q[1],-q[2],-q[3]; q[2],q[3] vertauscht: rotation um die y achse beim hoch/runterschauen, li/re vo/hi -q[0],-q[1],-q[2],-q[3]: q[2],q[3] vertauscht: hoch/runterschaun vertauscht drehung der matrix: rotZ180: rotation um y beim links/rechts schauen, hoch runter vertauscht */ camNode->setOrientation(q[0],-q[1],-q[3],q[2]); } } int OgreRenderServer::Width() const { if ((mObjectManager.get() == 0) || (mObjectManager->GetRenderTarget() == 0)) { return 0; } return mObjectManager->GetRenderTarget()->getWidth(); } int OgreRenderServer::Height() const { if ((mObjectManager.get() == 0) || (mObjectManager->GetRenderTarget() == 0)) { return 0; } return mObjectManager->GetRenderTarget()->getHeight(); } bool OgreRenderServer::CopyFrame(char* buffer) const { if ((mObjectManager.get() == 0) || (mObjectManager->GetRenderTarget() == 0)) { return false; } // void copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer) Ogre::PixelBox pb(Width(),Height(),1,Ogre::PF_BYTE_RGB,buffer); mObjectManager->GetRenderTarget()->copyContentsToMemory(pb); return true; } #if 0 void OgreRenderServer::RegisterSceneManager(Ogre::SceneManager* sceneManager) { // mSceneManager = sceneManager; } #endif --- NEW FILE: openglsystemogre_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; -*- this file is part of simspark Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: openglsystemogre_c.cpp,v 1.1.2.1 2007/07/18 23:06:42 fruit Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "openglsystemogre.h" void CLASS(OpenGLSystemOGRE)::DefineClass() { DEFINE_BASECLASS(kerosin/OpenGLSystem); } --- NEW FILE: ogrerenderserver.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Tue May 9 2006 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: ogrerenderserver.h,v 1.1.2.1 2007/07/18 23:06:42 fruit Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. OgreRenderServer NOTE: This is a renderserver in order to support OGRE HISTORY: 29/03/07 - OO - Initial version */ #ifndef OGRERENDERSERVER_H #define OGRERENDERSERVER_H #include "ogreobjectmanager.h" #include <kerosin/renderserver/baserenderserver.h> #include <salt/matrix.h> #ifdef __APPLE__ #include <Ogre/Ogre.h> #else #include <Ogre.h> #endif namespace oxygen { class Camera; } namespace kerosin { class Light; class StaticMesh; } class OgreRenderServer : public kerosin::BaseRenderServer { public: typedef std::map<std::string, bool> TNodeRegistry; public: OgreRenderServer(); virtual ~OgreRenderServer() {} //! display the current active scene virtual void Render(); //! width of the render target virtual int Width() const; //! height of the render target virtual int Height() const; //! get a shot of the current frame virtual bool CopyFrame(char* buffer) const; //! register an Ogre SceneManager object // void RegisterSceneManager(Ogre::SceneManager* sceneManager); protected: virtual void OnLink(); private: void RenderScene(boost::shared_ptr<oxygen::BaseNode> node); Ogre::SceneNode* RegisterAtOgre(boost::shared_ptr<kerosin::StaticMesh> renderNode); Ogre::Light* RegisterAtOgre(boost::shared_ptr<kerosin::Light> lightNode); Ogre::Camera* RegisterAtOgre(boost::shared_ptr<oxygen::Camera> cameraNode); void UpdateOgreNode(Ogre::SceneNode* sceneNode, boost::shared_ptr<kerosin::StaticMesh> renderNode); void UpdateOgreNode(Ogre::Light* light, boost::shared_ptr<kerosin::Light> lightNode); void UpdateOgreNode(Ogre::Camera* light, boost::shared_ptr<oxygen::Camera> cameraNode); void CleanUpOgreSceneNodes(); boost::shared_ptr<OgreObjectManager> mObjectManager; TNodeRegistry mRenderNodeRegistry; TNodeRegistry mLightNodeRegistry; TNodeRegistry mCameraNodeRegistry; Ogre::ColourValue mAmbientLight; }; DECLARE_CLASS(OgreRenderServer); #endif // OGRERENDERSERVER_H --- NEW FILE: openglsysframelistener.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Tue May 9 2006 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: openglsysframelistener.h,v 1.1.2.1 2007/07/18 23:06:42 fruit Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. OpenGLSysFrameListener (derived from ExampleFrameListener shipping with OGRE) HISTORY: 16/03/07 - OO - Initial version */ /* ----------------------------------------------------------------------------- Filename: OpenGLSysFrameListener.h Description: Defines an example frame listener which responds to frame events. This frame listener just moves a specified camera around based on keyboard and mouse movements. Mouse: Freelook W or Up: Forward S or Down:Backward A: Step left D: Step right PgUp: Move upwards PgDown: Move downwards F: Toggle frame rate stats on/off R: Render mode T: Cycle texture filtering Bilinear, Trilinear, Anisotropic(8) P: Toggle on/off display of camera position / orientation ----------------------------------------------------------------------------- */ #ifndef OPENGLSYSFRAMELISTENER_H #define OPENGLSYSFRAMELISTENER_H #ifdef __APPLE__ #include <Ogre/Ogre.h> #else #include <Ogre.h> #endif //Use this define to signify OIS will be used as a DLL //(so that dll import/export macros are in effect) #define OIS_DYNAMIC_LIB #include <OIS/OIS.h> #include "ogreobjectmanager.h" class OpenGLSysFrameListener: public Ogre::FrameListener, public Ogre::WindowEventListener { public: // Constructor takes a RenderWindow because it uses that to determine input context OpenGLSysFrameListener(Ogre::RenderWindow* win, OgreObjectManager* oom, bool bufferedKeys = false, bool bufferedMouse = false, bool bufferedJoy = false); // Window has resized: derived from WindowEventListener. Adjust mouse clipping area virtual void windowResized(Ogre::RenderWindow* rw); // Window has been closed: derived from WindowEventListener. virtual void windowClosed(Ogre::RenderWindow* rw); virtual ~OpenGLSysFrameListener(); // virtual bool processUnbufferedKeyInput(const Ogre::FrameEvent& evt); // bool processUnbufferedMouseInput(const Ogre::FrameEvent& evt); // void moveCamera(); void showDebugOverlay(bool show); // Derived from FrameListener, called when a frame is about to begin rendering. // Override frameStarted event to process that (don't care about frameEnded) bool frameStarted(const Ogre::FrameEvent& evt); // DErived from FrameListener: called when a frame has just been rendered. bool frameEnded(const Ogre::FrameEvent& evt); protected: void UpdateStats(); protected: OgreObjectManager* mOOM; Ogre::Vector3 mTranslateVector; Ogre::RenderWindow* mWindow; bool mStatsOn; std::string mDebugText; bool mShowBBs; unsigned int mNumScreenShots; float mMoveScale; Ogre::Degree mRotScale; // just to stop toggles flipping too fast Ogre::Real mTimeUntilNextToggle ; Ogre::Radian mRotX, mRotY; Ogre::TextureFilterOptions mFiltering; int mAniso; int mSceneDetailIndex ; Ogre::Real mMoveSpeed; Ogre::Degree mRotateSpeed; Ogre::Overlay* mDebugOverlay; #if 0 //OIS Input devices OIS::InputManager* mInputManager; OIS::Mouse* mMouse; OIS::Keyboard* mKeyboard; OIS::JoyStick* mJoy; #endif }; #endif --- NEW FILE: ogreobjectmanager.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Wed May 9 2007 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: ogreobjectmanager.h,v 1.1.2.1 2007/07/18 23:06:41 fruit Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. OgreObjectManager (wrapper for Ogre SceneManager and other ogre pointers) HISTORY: 01/05/07 - OO - Initial version */ #ifndef OGREOBJECTMANAGER_H #define OGREOBJECTMANAGER_H #include <zeitgeist/leaf.h> #include <zeitgeist/class.h> namespace Ogre { class Camera; class SceneManager; class Viewport; class RenderTarget; } class OgreObjectManager : public zeitgeist::Leaf { public: /// Standard constructor OgreObjectManager(); /// Standard destructor ~OgreObjectManager(); /// set the SceneManager pointer void SetSceneManager(Ogre::SceneManager* sceneManager); /// return the SceneManager pointer Ogre::SceneManager* GetSceneManager() const; /// set the main camera pointer void SetMainCamera(Ogre::Camera* camera); /// return the main camera pointer Ogre::Camera* GetMainCamera() const; /// set the main viewport pointer void SetMainViewport(Ogre::Viewport* viewport); /// return the main viewport pointer Ogre::Viewport* GetMainViewport() const; /// set the render target (window) pointer void SetRenderTarget(Ogre::RenderTarget* render); /// return the render target pointer Ogre::RenderTarget* GetRenderTarget() const; protected: //! a pointer to the Ogre scenemanager used Ogre::SceneManager* mSceneManager; //! a pointer to the currently used main camera Ogre::Camera* mMainCamera; //! a pointer to the main viewport Ogre::Viewport* mMainViewport; //! a pointer to the render target Ogre::RenderTarget* mRenderTarget; }; DECLARE_CLASS(OgreObjectManager); #endif --- NEW FILE: ogrematerialexporter_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Tue May 9 2006 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: ogrematerialexporter_c.cpp,v 1.1.2.1 2007/07/18 23:06:41 fruit Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. OgreMaterialExporter NOTE: This class serves as exporter, to register materiales with other graphic engines (possibly also for exporting) HISTORY: 03/05/07 - OO - Initial version */ #include "ogrematerialexporter.h" using namespace kerosin; void CLASS(OgreMaterialExporter)::DefineClass() { DEFINE_BASECLASS(kerosin/MaterialExporter); } --- NEW FILE: ogremeshexporter_c.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Tue May 9 2006 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: ogremeshexporter_c.cpp,v 1.1.2.1 2007/07/18 23:06:41 fruit Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. MeshBridge NOTE: This class serves as an (abstract) bridge, to register meshes with other graphic engines (possibly also for exporting) HISTORY: 30/03/07 - OO - Initial version */ #include "ogremeshexporter.h" using namespace oxygen; void CLASS(OgreMeshExporter)::DefineClass() { DEFINE_BASECLASS(oxygen/MeshExporter); } --- NEW FILE: ogreobjectmanager.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of simspark Wed May 9 2007 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2007 RoboCup Soccer Server 3D Maintenance Group $Id: ogreobjectmanager.cpp,v 1.1.2.1 2007/07/18 23:06:41 fruit Exp $ 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; version 2 of the License. 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., 675 Mass Ave, Cambridge, MA 02139, USA. OgreObjectManager NOTE: This is a class collecting pointers to ogre objects to be used in various spark classes HISTORY: 01/05/07 - OO - Initial version */ #include "ogreobjectmanager.h" #ifdef __APPLE__ #include <Ogre/Ogre.h> #else #include <Ogre.h> #endif OgreObjectManager::OgreObjectManager() : mSceneManager(0), mMainCamera(0), mMainViewport(0), mRenderTarget(0) { } OgreObjectManager::~OgreObjectManager() { } void OgreObjectManager::SetSceneManager(Ogre::SceneManager* sceneManager) { mSceneManager = sceneManager; } Ogre::SceneManager* OgreObjectManager::GetSceneManager() const { return mSceneManager; } void OgreObjectManager::SetMainCamera(Ogre::Camera* camera) { mMainCamera = camera; } Ogre::Camera* OgreObjectManager::GetMainCamera() const { return mMainCamera; } void OgreObjectManager::SetMainViewport(Ogre::View... [truncated message content] |