Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/shaders/src/orxonox/CameraManager.cc @ 10960

Last change on this file since 10960 was 9348, checked in by landauf, 12 years ago

merged branch presentation2012merge back to trunk

  • Property svn:eol-style set to native
File size: 2.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 <cassert>
32
33#include <OgreSceneManager.h>
34#include <OgreViewport.h>
35#include <OgreCompositorManager.h>
36
37#include "util/ScopedSingletonManager.h"
38#include "core/GameMode.h"
39#include "core/GraphicsManager.h"
40#include "core/ObjectList.h"
41#include "tools/Shader.h"
42#include "graphics/Camera.h"
43
44namespace orxonox
45{
46    ManageScopedSingleton(CameraManager, ScopeID::Graphics, false);
47
48    CameraManager::CameraManager()
49    {
50        RegisterRootObject(CameraManager);
51
52        assert(GameMode::showsGraphics());
53    }
54
55    CameraManager::~CameraManager()
56    {
57    }
58
59    Camera* CameraManager::getActiveCamera() const
60    {
61        if (!this->cameraList_.empty())
62            return this->cameraList_.front();
63        else
64            return 0;
65    }
66
67    void CameraManager::requestFocus(Camera* camera)
68    {
69        // notify old camera (if it exists)
70        if (!this->cameraList_.empty())
71            this->cameraList_.front()->removeFocus();
72
73        camera->setFocus();
74
75        // make sure we don't add it twice
76        for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end();)
77            if ((*it) == camera)
78                this->cameraList_.erase(it++);
79            else
80                ++it;
81        // add to list
82        this->cameraList_.push_front(camera);
83    }
84
85    void CameraManager::releaseFocus(Camera* camera)
86    {
87        // notify the cam of releasing the focus
88        if (!this->cameraList_.empty() && this->cameraList_.front() == camera)
89        {
90            camera->removeFocus();
91            this->cameraList_.pop_front();
92
93            // set new focus if possible
94            if (!this->cameraList_.empty())
95                this->cameraList_.front()->setFocus();
96            else
97                this->useCamera(NULL);
98        }
99        else
100            this->cameraList_.remove(camera);
101    }
102
103    void CameraManager::useCamera(Ogre::Camera* camera)
104    {
105        GraphicsManager::getInstance().setCamera(camera);
106    }
107}
Note: See TracBrowser for help on using the repository browser.