Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7114 was 6417, checked in by rgrieder, 15 years ago

Merged presentation2 branch back to trunk.
Major new features:

  • Actual GUI with settings, etc.
  • Improved space ship steering (human interaction)
  • Rocket fire and more particle effects
  • Advanced sound framework
  • 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{
[5929]47    ManageScopedSingleton(CameraManager, ScopeID::Graphics, false);
[2023]48
[5929]49    CameraManager::CameraManager()
50        : viewport_(GraphicsManager::getInstance().getViewport())
[2019]51    {
[5929]52        assert(GameMode::showsGraphics());
[2019]53    }
[1202]54
[2073]55    CameraManager::~CameraManager()
[2019]56    {
[5929]57        GUIManager::getInstance().setCamera(0);
[2019]58    }
[1202]59
[2073]60    Camera* CameraManager::getActiveCamera() const
[2019]61    {
[5929]62        if (!this->cameraList_.empty())
[2019]63            return this->cameraList_.front();
64        else
65            return 0;
66    }
[1202]67
[2073]68    void CameraManager::requestFocus(Camera* camera)
[2019]69    {
70        // notify old camera (if it exists)
[5929]71        if (!this->cameraList_.empty())
[2019]72            this->cameraList_.front()->removeFocus();
73
[2662]74        camera->setFocus();
[2064]75
[2662]76        // make sure we don't add it twice
[5929]77        for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end();)
[2662]78            if ((*it) == camera)
[5929]79                this->cameraList_.erase(it++);
80            else
81                ++it;
[2019]82        // add to list
83        this->cameraList_.push_front(camera);
[1202]84    }
85
[2073]86    void CameraManager::releaseFocus(Camera* camera)
[1202]87    {
[2019]88        // notify the cam of releasing the focus
[5929]89        if (!this->cameraList_.empty() && this->cameraList_.front() == camera)
[2019]90        {
91            camera->removeFocus();
92            this->cameraList_.pop_front();
93
[2662]94            // set new focus if possible
[5929]95            if (!this->cameraList_.empty())
[2662]96                this->cameraList_.front()->setFocus();
[2019]97        }
98        else
99            this->cameraList_.remove(camera);
[1202]100    }
[2662]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);
[2896]118        GUIManager::getInstance().setCamera(camera);
[2662]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    }
[1202]126}
Note: See TracBrowser for help on using the repository browser.