Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/src/orxonox/CameraManager.cc @ 6259

Last change on this file since 6259 was 6182, checked in by rgrieder, 15 years ago

Singleton pointer initialisation should be part of the ManageScopedSingleton macro to ensure the order.

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
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:
25 *      Fabian 'x3n' Landau
26 *
27 */
28
29#include "CameraManager.h"
30
31#include <OgreSceneManager.h>
32#include <OgreViewport.h>
33#include <OgreCompositorManager.h>
34
35#include "util/StringUtils.h"
36#include "core/GameMode.h"
37#include "core/GraphicsManager.h"
38#include "core/GUIManager.h"
39#include "core/ObjectList.h"
40#include "core/ScopedSingletonManager.h"
41#include "tools/Shader.h"
42#include "graphics/Camera.h"
43#include "Scene.h"
44
45namespace orxonox
46{
47    ManageScopedSingleton(CameraManager, ScopeID::Graphics, false);
48
49    CameraManager::CameraManager()
50        : viewport_(GraphicsManager::getInstance().getViewport())
51    {
52        assert(GameMode::showsGraphics());
53    }
54
55    CameraManager::~CameraManager()
56    {
57        GUIManager::getInstance().setCamera(0);
58    }
59
60    Camera* CameraManager::getActiveCamera() const
61    {
62        if (!this->cameraList_.empty())
63            return this->cameraList_.front();
64        else
65            return 0;
66    }
67
68    void CameraManager::requestFocus(Camera* camera)
69    {
70        // notify old camera (if it exists)
71        if (!this->cameraList_.empty())
72            this->cameraList_.front()->removeFocus();
73
74        camera->setFocus();
75
76        // make sure we don't add it twice
77        for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end();)
78            if ((*it) == camera)
79                this->cameraList_.erase(it++);
80            else
81                ++it;
82        // add to list
83        this->cameraList_.push_front(camera);
84    }
85
86    void CameraManager::releaseFocus(Camera* camera)
87    {
88        // notify the cam of releasing the focus
89        if (!this->cameraList_.empty() && this->cameraList_.front() == camera)
90        {
91            camera->removeFocus();
92            this->cameraList_.pop_front();
93
94            // set new focus if possible
95            if (!this->cameraList_.empty())
96                this->cameraList_.front()->setFocus();
97        }
98        else
99            this->cameraList_.remove(camera);
100    }
101
102    void CameraManager::useCamera(Ogre::Camera* camera)
103    {
104        // This workaround is needed to avoid weird behaviour with active compositors while
105        // switching the camera (like freezing the image)
106        //
107        // Last known Ogre version needing this workaround:
108        // 1.4.8
109
110        // deactivate all compositors
111        {
112            Ogre::ResourceManager::ResourceMapIterator iterator = Ogre::CompositorManager::getSingleton().getResourceIterator();
113            while (iterator.hasMoreElements())
114                Ogre::CompositorManager::getSingleton().setCompositorEnabled(this->viewport_, iterator.getNext()->getName(), false);
115        }
116
117        this->viewport_->setCamera(camera);
118        GUIManager::getInstance().setCamera(camera);
119
120        // reactivate all visible compositors
121        {
122            for (ObjectList<Shader>::iterator it = ObjectList<Shader>::begin(); it != ObjectList<Shader>::end(); ++it)
123                it->updateVisibility();
124        }
125    }
126}
Note: See TracBrowser for help on using the repository browser.