Changeset 2662 for code/trunk/src/orxonox/CameraManager.cc
- Timestamp:
- Feb 14, 2009, 10:17:35 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/CameraManager.cc
- Property svn:mergeinfo changed
r2261 r2662 29 29 #include "CameraManager.h" 30 30 31 #include <OgreSceneManager.h> 31 32 #include <OgreViewport.h> 33 #include <OgreCamera.h> 34 #include <OgreCompositorManager.h> 35 #include <OgreResource.h> 32 36 33 37 #include "core/Core.h" 38 #include "core/Iterator.h" 34 39 #include "objects/worldentities/Camera.h" 35 40 #include "objects/Scene.h" 41 #include "tools/Shader.h" 42 #include "util/String.h" 36 43 37 44 namespace orxonox … … 44 51 assert(singletonRef_s == 0); 45 52 singletonRef_s = this; 53 54 this->fallbackCamera_ = 0; 46 55 } 47 56 … … 50 59 assert(singletonRef_s != 0); 51 60 singletonRef_s = 0; 61 62 if (this->fallbackCamera_) 63 this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_); 52 64 } 53 65 … … 68 80 if (this->cameraList_.size() > 0) 69 81 this->cameraList_.front()->removeFocus(); 82 else if (this->fallbackCamera_) 83 { 84 this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_); 85 this->fallbackCamera_ = 0; 86 } 70 87 71 camera->setFocus(this->viewport_); 88 camera->setFocus(); 89 90 // make sure we don't add it twice 91 for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end(); ++it) 92 if ((*it) == camera) 93 return; 72 94 73 95 // add to list 74 std::list<Camera*>::iterator it;75 for (it = this->cameraList_.begin(); it != this->cameraList_.end(); ++it)76 {77 if ((*it) == camera)78 return; // make sure we don't add it twice79 }80 96 this->cameraList_.push_front(camera); 81 97 } … … 92 108 this->cameraList_.pop_front(); 93 109 94 // set new focus if necessary 95 if (cameraList_.size() > 0) 96 cameraList_.front()->setFocus(this->viewport_); 110 // set new focus if possible 111 if (this->cameraList_.size() > 0) 112 this->cameraList_.front()->setFocus(); 113 else 114 { 115 // there are no more cameras, create a fallback 116 if (!this->fallbackCamera_) 117 this->fallbackCamera_ = camera->getScene()->getSceneManager()->createCamera(getUniqueNumberString()); 118 this->useCamera(this->fallbackCamera_); 119 } 97 120 } 98 121 else … … 101 124 } 102 125 } 126 127 void CameraManager::useCamera(Ogre::Camera* camera) 128 { 129 // This workaround is needed to avoid weird behaviour with active compositors while 130 // switching the camera (like freezing the image) 131 // 132 // Last known Ogre version needing this workaround: 133 // 1.4.8 134 135 // deactivate all compositors 136 { 137 Ogre::ResourceManager::ResourceMapIterator iterator = Ogre::CompositorManager::getSingleton().getResourceIterator(); 138 while (iterator.hasMoreElements()) 139 Ogre::CompositorManager::getSingleton().setCompositorEnabled(this->viewport_, iterator.getNext()->getName(), false); 140 } 141 142 this->viewport_->setCamera(camera); 143 144 // reactivate all visible compositors 145 { 146 for (ObjectList<Shader>::iterator it = ObjectList<Shader>::begin(); it != ObjectList<Shader>::end(); ++it) 147 it->updateVisibility(); 148 } 149 } 103 150 }
Note: See TracChangeset
for help on using the changeset viewer.