Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2210 was 2171, checked in by landauf, 16 years ago

merged revisions 2111-2170 from objecthierarchy branch back to trunk.

File size: 2.8 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 */
[1502]28#include "OrxonoxStableHeaders.h"
[2073]29#include "CameraManager.h"
[1502]30
[2023]31#include <OgreViewport.h>
[1202]32
[2019]33#include "core/Core.h"
[2027]34#include "objects/worldentities/Camera.h"
[1202]35
36
[2019]37namespace orxonox
38{
[2073]39    CameraManager* CameraManager::singletonRef_s = 0;
[2023]40
[2073]41    CameraManager::CameraManager(Ogre::Viewport* viewport)
[2023]42        : viewport_(viewport)
[2019]43    {
[2023]44        assert(singletonRef_s == 0);
45        singletonRef_s = this;
[2019]46    }
[1202]47
[2073]48    CameraManager::~CameraManager()
[2019]49    {
[2023]50        assert(singletonRef_s != 0);
51        singletonRef_s = 0;
[2019]52    }
[1202]53
[2073]54    Camera* CameraManager::getActiveCamera() const
[2019]55    {
56        if (this->cameraList_.size() > 0)
57            return this->cameraList_.front();
58        else
59            return 0;
60    }
[1202]61
[2073]62    void CameraManager::requestFocus(Camera* camera)
[2019]63    {
64        if (!Core::showsGraphics())
65            return;
66
67        // notify old camera (if it exists)
68        if (this->cameraList_.size() > 0)
69            this->cameraList_.front()->removeFocus();
70
[2064]71        camera->setFocus(this->viewport_);
72
[2019]73        // add to list
[2064]74        std::list<Camera*>::iterator it;
75        for (it = this->cameraList_.begin(); it != this->cameraList_.end(); ++it)
76        {
77            if ((*it) == camera)
78                return; // make sure we don't add it twice
79        }
[2019]80        this->cameraList_.push_front(camera);
[1202]81    }
82
[2073]83    void CameraManager::releaseFocus(Camera* camera)
[1202]84    {
[2019]85        if (!Core::showsGraphics())
86            return;
87
88        // notify the cam of releasing the focus
89        if (this->cameraList_.front() == camera)
90        {
91            camera->removeFocus();
92            this->cameraList_.pop_front();
93
94            // set new focus if necessary
95            if (cameraList_.size() > 0)
[2023]96                cameraList_.front()->setFocus(this->viewport_);
[2019]97        }
98        else
99        {
100            this->cameraList_.remove(camera);
101        }
[1202]102    }
103}
Note: See TracBrowser for help on using the repository browser.