Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/CameraManager.cc @ 5745

Last change on this file since 5745 was 5738, checked in by landauf, 15 years ago

merged libraries2 back to trunk

  • Property svn:eol-style set to native
File size: 4.4 KB
RevLine 
[1202]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Benjamin Knecht
24 *   Co-authors:
[2073]25 *      Fabian 'x3n' Landau
[1202]26 *
27 */
[2073]28#include "CameraManager.h"
[1502]29
[2662]30#include <OgreSceneManager.h>
[2023]31#include <OgreViewport.h>
[2662]32#include <OgreCompositorManager.h>
[1202]33
[3280]34#include "util/StringUtils.h"
[2896]35#include "core/GameMode.h"
[3370]36#include "core/GUIManager.h"
[3196]37#include "core/ObjectList.h"
38#include "tools/Shader.h"
[5738]39#include "graphics/Camera.h"
40#include "Scene.h"
[1202]41
[2019]42namespace orxonox
43{
[3370]44    CameraManager* CameraManager::singletonPtr_s = 0;
[2023]45
[2073]46    CameraManager::CameraManager(Ogre::Viewport* viewport)
[2023]47        : viewport_(viewport)
[2019]48    {
[2662]49        this->fallbackCamera_ = 0;
[2019]50    }
[1202]51
[2073]52    CameraManager::~CameraManager()
[2019]53    {
[2662]54        if (this->fallbackCamera_)
55            this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_);
[2019]56    }
[1202]57
[2073]58    Camera* CameraManager::getActiveCamera() const
[2019]59    {
60        if (this->cameraList_.size() > 0)
61            return this->cameraList_.front();
62        else
63            return 0;
64    }
[1202]65
[2073]66    void CameraManager::requestFocus(Camera* camera)
[2019]67    {
[2896]68        if (!GameMode::showsGraphics())
[2019]69            return;
70
71        // notify old camera (if it exists)
72        if (this->cameraList_.size() > 0)
73            this->cameraList_.front()->removeFocus();
[2662]74        else if (this->fallbackCamera_)
75        {
76            this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_);
77            this->fallbackCamera_ = 0;
78        }
[2019]79
[2662]80        camera->setFocus();
[2064]81
[2662]82        // make sure we don't add it twice
83        for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end(); ++it)
84            if ((*it) == camera)
85                return;
86
[2019]87        // add to list
88        this->cameraList_.push_front(camera);
[1202]89    }
90
[2073]91    void CameraManager::releaseFocus(Camera* camera)
[1202]92    {
[2896]93        if (!GameMode::showsGraphics())
[2019]94            return;
95
96        // notify the cam of releasing the focus
97        if (this->cameraList_.front() == camera)
98        {
99            camera->removeFocus();
100            this->cameraList_.pop_front();
101
[2662]102            // set new focus if possible
103            if (this->cameraList_.size() > 0)
104                this->cameraList_.front()->setFocus();
105            else
106            {
107                // there are no more cameras, create a fallback
108                if (!this->fallbackCamera_)
109                    this->fallbackCamera_ = camera->getScene()->getSceneManager()->createCamera(getUniqueNumberString());
110                this->useCamera(this->fallbackCamera_);
111            }
[2019]112        }
113        else
114        {
115            this->cameraList_.remove(camera);
116        }
[1202]117    }
[2662]118
119    void CameraManager::useCamera(Ogre::Camera* camera)
120    {
121        // This workaround is needed to avoid weird behaviour with active compositors while
122        // switching the camera (like freezing the image)
123        //
124        // Last known Ogre version needing this workaround:
125        // 1.4.8
126
127        // deactivate all compositors
128        {
129            Ogre::ResourceManager::ResourceMapIterator iterator = Ogre::CompositorManager::getSingleton().getResourceIterator();
130            while (iterator.hasMoreElements())
131                Ogre::CompositorManager::getSingleton().setCompositorEnabled(this->viewport_, iterator.getNext()->getName(), false);
132        }
133
134        this->viewport_->setCamera(camera);
[2896]135        GUIManager::getInstance().setCamera(camera);
[2662]136
137        // reactivate all visible compositors
138        {
139            for (ObjectList<Shader>::iterator it = ObjectList<Shader>::begin(); it != ObjectList<Shader>::end(); ++it)
140                it->updateVisibility();
141        }
142    }
[1202]143}
Note: See TracBrowser for help on using the repository browser.