Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6119 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
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 */
[5929]28
[2073]29#include "CameraManager.h"
[1502]30
[2662]31#include <OgreSceneManager.h>
[2023]32#include <OgreViewport.h>
[2662]33#include <OgreCompositorManager.h>
[1202]34
[3280]35#include "util/StringUtils.h"
[2896]36#include "core/GameMode.h"
[5929]37#include "core/GraphicsManager.h"
[3370]38#include "core/GUIManager.h"
[3196]39#include "core/ObjectList.h"
[5929]40#include "core/ScopedSingletonManager.h"
[3196]41#include "tools/Shader.h"
[5738]42#include "graphics/Camera.h"
43#include "Scene.h"
[1202]44
[2019]45namespace orxonox
46{
[3370]47    CameraManager* CameraManager::singletonPtr_s = 0;
[5929]48    ManageScopedSingleton(CameraManager, ScopeID::Graphics, false);
[2023]49
[5929]50    CameraManager::CameraManager()
51        : viewport_(GraphicsManager::getInstance().getViewport())
[2019]52    {
[5929]53        assert(GameMode::showsGraphics());
[2019]54    }
[1202]55
[2073]56    CameraManager::~CameraManager()
[2019]57    {
[5929]58        GUIManager::getInstance().setCamera(0);
[2019]59    }
[1202]60
[2073]61    Camera* CameraManager::getActiveCamera() const
[2019]62    {
[5929]63        if (!this->cameraList_.empty())
[2019]64            return this->cameraList_.front();
65        else
66            return 0;
67    }
[1202]68
[2073]69    void CameraManager::requestFocus(Camera* camera)
[2019]70    {
71        // notify old camera (if it exists)
[5929]72        if (!this->cameraList_.empty())
[2019]73            this->cameraList_.front()->removeFocus();
74
[2662]75        camera->setFocus();
[2064]76
[2662]77        // make sure we don't add it twice
[5929]78        for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end();)
[2662]79            if ((*it) == camera)
[5929]80                this->cameraList_.erase(it++);
81            else
82                ++it;
[2019]83        // add to list
84        this->cameraList_.push_front(camera);
[1202]85    }
86
[2073]87    void CameraManager::releaseFocus(Camera* camera)
[1202]88    {
[2019]89        // notify the cam of releasing the focus
[5929]90        if (!this->cameraList_.empty() && this->cameraList_.front() == camera)
[2019]91        {
92            camera->removeFocus();
93            this->cameraList_.pop_front();
94
[2662]95            // set new focus if possible
[5929]96            if (!this->cameraList_.empty())
[2662]97                this->cameraList_.front()->setFocus();
[2019]98        }
99        else
100            this->cameraList_.remove(camera);
[1202]101    }
[2662]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);
[2896]119        GUIManager::getInstance().setCamera(camera);
[2662]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    }
[1202]127}
Note: See TracBrowser for help on using the repository browser.