Changeset 5924 for code/branches/core5/src/orxonox
- Timestamp:
- Oct 9, 2009, 6:04:16 PM (15 years ago)
- Location:
- code/branches/core5/src/orxonox
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core5/src/orxonox/CameraManager.cc
r5911 r5924 38 38 #include "core/GUIManager.h" 39 39 #include "core/ObjectList.h" 40 #include "core/ScopedSingletonManager.h" 40 41 #include "tools/Shader.h" 41 42 #include "graphics/Camera.h" … … 44 45 namespace orxonox 45 46 { 46 CameraManager::CameraManager(BaseObject* creator) 47 : BaseObject(creator) 48 , viewport_(GraphicsManager::getInstance().getViewport()) 49 , fallbackCamera_(NULL) 47 CameraManager* CameraManager::singletonPtr_s = 0; 48 ManageScopedSingleton(CameraManager, ScopeID::Graphics, false); 49 50 CameraManager::CameraManager() 51 : viewport_(GraphicsManager::getInstance().getViewport()) 50 52 { 51 assert(GameMode::showsGraphics());52 53 } 53 54 54 55 CameraManager::~CameraManager() 55 56 { 56 for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end();) 57 if ((*it)->camera_ == GUIManager::getInstance().getCamera()) 58 GUIManager::getInstance().setCamera(NULL); 59 60 if (this->fallbackCamera_) 61 this->getScene()->getSceneManager()->destroyCamera(this->fallbackCamera_); 57 GUIManager::getInstance().setCamera(0); 62 58 } 63 59 64 60 Camera* CameraManager::getActiveCamera() const 65 61 { 66 if ( !this->cameraList_.empty())62 if (this->cameraList_.size() > 0) 67 63 return this->cameraList_.front(); 68 64 else … … 72 68 void CameraManager::requestFocus(Camera* camera) 73 69 { 70 if (!GameMode::showsGraphics()) 71 assert(0); 72 74 73 // notify old camera (if it exists) 75 if ( !this->cameraList_.empty())74 if (this->cameraList_.size() > 0) 76 75 this->cameraList_.front()->removeFocus(); 77 76 … … 79 78 80 79 // make sure we don't add it twice 81 for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end(); )80 for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end(); ++it) 82 81 if ((*it) == camera) 83 this->cameraList_.erase(it++); 84 else 85 ++it; 82 return; 86 83 87 84 // add to list … … 91 88 void CameraManager::releaseFocus(Camera* camera) 92 89 { 90 if (!GameMode::showsGraphics()) 91 assert(0); 92 93 93 // notify the cam of releasing the focus 94 94 if (!this->cameraList_.empty() && this->cameraList_.front() == camera) … … 98 98 99 99 // set new focus if possible 100 if ( !this->cameraList_.empty())100 if (this->cameraList_.size() > 0) 101 101 this->cameraList_.front()->setFocus(); 102 else103 {104 // there are no more cameras, create a fallback105 if (!this->fallbackCamera_)106 this->fallbackCamera_ = camera->getScene()->getSceneManager()->createCamera(getUniqueNumberString());107 this->useCamera(this->fallbackCamera_);108 }109 102 } 110 103 else -
code/branches/core5/src/orxonox/CameraManager.h
r5911 r5924 41 41 #include <list> 42 42 #include "util/OgreForwardRefs.h" 43 #include "core/BaseObject.h" 43 #include "util/Singleton.h" 44 #include "core/OrxonoxClass.h" 45 #include "core/SmartPtr.h" 44 46 45 47 namespace orxonox 46 48 { 47 class _OrxonoxExport CameraManager : public BaseObject49 class _OrxonoxExport CameraManager : public Singleton<CameraManager>, public OrxonoxClass 48 50 { 51 friend class Singleton<CameraManager>; 49 52 public: 50 CameraManager( BaseObject* creator);53 CameraManager(); 51 54 ~CameraManager(); 52 55 … … 58 61 void useCamera(Ogre::Camera* camera); 59 62 63 static CameraManager* getInstancePtr() { return singletonPtr_s; } 64 60 65 private: 61 66 CameraManager(const CameraManager&); // don't use … … 63 68 std::list<Camera*> cameraList_; 64 69 Ogre::Viewport* viewport_; 65 Ogre::Camera* fallbackCamera_; 70 71 static CameraManager* singletonPtr_s; 66 72 }; 67 73 } -
code/branches/core5/src/orxonox/Scene.cc
r5914 r5924 46 46 #include "tools/BulletConversions.h" 47 47 #include "Radar.h" 48 #include "CameraManager.h"49 48 #include "worldentities/WorldEntity.h" 50 49 … … 67 66 68 67 this->radar_ = new Radar(); 69 this->cameraManager_ = new CameraManager(this);70 68 } 71 69 else … … 76 74 77 75 this->radar_ = 0; 78 this->cameraManager_ = 0;79 76 } 80 77 … … 98 95 { 99 96 if (GameMode::showsGraphics()) 100 {101 // Check whether we're still using this scene manager for the GUI102 if (GUIManager::getInstance().getCamera() && GUIManager::getInstance().getCamera()->getSceneManager() == this->sceneManager_)103 GUIManager::getInstance().setCamera(NULL);104 97 Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_); 105 }106 98 else 107 99 delete this->sceneManager_; … … 109 101 if (this->radar_) 110 102 this->radar_->destroy(); 111 112 if (this->cameraManager_)113 this->cameraManager_->destroy();114 103 115 104 this->setPhysicalWorld(false); -
code/branches/core5/src/orxonox/Scene.h
r5911 r5924 73 73 inline Radar* getRadar() 74 74 { return this->radar_; } 75 76 inline CameraManager* getCameraManager()77 { return this->cameraManager_.get(); }78 75 79 76 inline virtual uint32_t getSceneID() const { return this->getObjectID(); } … … 100 97 bool bShadows_; 101 98 Radar* radar_; 102 SmartPtr<CameraManager> cameraManager_;103 99 104 100 -
code/branches/core5/src/orxonox/graphics/Camera.cc
r5916 r5924 38 38 #include "core/CoreIncludes.h" 39 39 #include "core/ConfigValueIncludes.h" 40 #include "core/G ameMode.h"40 #include "core/GUIManager.h" 41 41 #include "Scene.h" 42 42 #include "CameraManager.h" … … 50 50 RegisterObject(Camera); 51 51 52 if (!GameMode::showsGraphics())53 ThrowException(AbortLoading, "Can't create Camera, no graphics.");54 52 if (!this->getScene()) 55 53 ThrowException(AbortLoading, "Can't create Camera, no scene."); … … 78 76 if (this->isInitialized()) 79 77 { 78 if( GUIManager::getInstance().getCamera() == this->camera_ ) 79 GUIManager::getInstance().setCamera( NULL ); 80 80 this->releaseFocus(); 81 81 … … 120 120 void Camera::requestFocus() 121 121 { 122 this->getScene()->getCameraManager()->requestFocus(this);122 CameraManager::getInstance().requestFocus(this); 123 123 } 124 124 125 125 void Camera::releaseFocus() 126 126 { 127 this->getScene()->getCameraManager()->releaseFocus(this);127 CameraManager::getInstance().releaseFocus(this); 128 128 } 129 129 … … 140 140 { 141 141 this->bHasFocus_ = true; 142 this->getScene()->getCameraManager()->useCamera(this->camera_);142 CameraManager::getInstance().useCamera(this->camera_); 143 143 } 144 144
Note: See TracChangeset
for help on using the changeset viewer.