Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/menuanimations/src/orxonox/CameraManager.cc @ 6637

Last change on this file since 6637 was 5929, checked in by rgrieder, 15 years ago

Merged core5 branch back to the trunk.
Key features include clean level unloading and an extended XML event system.

Two important notes:
Delete your keybindings.ini files! * or you will still get parser errors when loading the key bindings.
Delete build_dir/lib/modules/libgamestates.module! * or orxonox won't start.
Best thing to do is to delete the build folder ;)

  • 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    CameraManager* CameraManager::singletonPtr_s = 0;
48    ManageScopedSingleton(CameraManager, ScopeID::Graphics, false);
49
50    CameraManager::CameraManager()
51        : viewport_(GraphicsManager::getInstance().getViewport())
52    {
53        assert(GameMode::showsGraphics());
54    }
55
56    CameraManager::~CameraManager()
57    {
58        GUIManager::getInstance().setCamera(0);
59    }
60
61    Camera* CameraManager::getActiveCamera() const
62    {
63        if (!this->cameraList_.empty())
64            return this->cameraList_.front();
65        else
66            return 0;
67    }
68
69    void CameraManager::requestFocus(Camera* camera)
70    {
71        // notify old camera (if it exists)
72        if (!this->cameraList_.empty())
73            this->cameraList_.front()->removeFocus();
74
75        camera->setFocus();
76
77        // make sure we don't add it twice
78        for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end();)
79            if ((*it) == camera)
80                this->cameraList_.erase(it++);
81            else
82                ++it;
83        // add to list
84        this->cameraList_.push_front(camera);
85    }
86
87    void CameraManager::releaseFocus(Camera* camera)
88    {
89        // notify the cam of releasing the focus
90        if (!this->cameraList_.empty() && this->cameraList_.front() == camera)
91        {
92            camera->removeFocus();
93            this->cameraList_.pop_front();
94
95            // set new focus if possible
96            if (!this->cameraList_.empty())
97                this->cameraList_.front()->setFocus();
98        }
99        else
100            this->cameraList_.remove(camera);
101    }
102
103    void CameraManager::useCamera(Ogre::Camera* camera)
104    {
105        // This workaround is needed to avoid weird behaviour with active compositors while
106        // switching the camera (like freezing the image)
107        //
108        // Last known Ogre version needing this workaround:
109        // 1.4.8
110
111        // deactivate all compositors
112        {
113            Ogre::ResourceManager::ResourceMapIterator iterator = Ogre::CompositorManager::getSingleton().getResourceIterator();
114            while (iterator.hasMoreElements())
115                Ogre::CompositorManager::getSingleton().setCompositorEnabled(this->viewport_, iterator.getNext()->getName(), false);
116        }
117
118        this->viewport_->setCamera(camera);
119        GUIManager::getInstance().setCamera(camera);
120
121        // reactivate all visible compositors
122        {
123            for (ObjectList<Shader>::iterator it = ObjectList<Shader>::begin(); it != ObjectList<Shader>::end(); ++it)
124                it->updateVisibility();
125        }
126    }
127}
Note: See TracBrowser for help on using the repository browser.