Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/CameraHandler.cc @ 2031

Last change on this file since 2031 was 2030, checked in by rgrieder, 16 years ago
  • Moved SignalHandler from orxonox to util
  • Moved CameraHandler from orxonox/objects to orxonox
  • updated msvc files
File size: 2.5 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 *      ...
26 *
27 */
28#include "OrxonoxStableHeaders.h"
29#include "CameraHandler.h"
30
31#include <OgreViewport.h>
32
33#include "core/Core.h"
34#include "objects/worldentities/Camera.h"
35
36
37namespace orxonox
38{
39    CameraHandler* CameraHandler::singletonRef_s = 0;
40
41    CameraHandler::CameraHandler(Ogre::Viewport* viewport)
42        : viewport_(viewport)
43    {
44        assert(singletonRef_s == 0);
45        singletonRef_s = this;
46    }
47
48    CameraHandler::~CameraHandler()
49    {
50        assert(singletonRef_s != 0);
51        singletonRef_s = 0;
52    }
53
54    Camera* CameraHandler::getActiveCamera() const
55    {
56        if (this->cameraList_.size() > 0)
57            return this->cameraList_.front();
58        else
59            return 0;
60    }
61
62    void CameraHandler::requestFocus(Camera* camera)
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
71        // add to list
72        this->cameraList_.push_front(camera);
73        camera->setFocus(this->viewport_);
74    }
75
76    void CameraHandler::releaseFocus(Camera* camera)
77    {
78        if (!Core::showsGraphics())
79            return;
80
81        // notify the cam of releasing the focus
82        if (this->cameraList_.front() == camera)
83        {
84            camera->removeFocus();
85            this->cameraList_.pop_front();
86
87            // set new focus if necessary
88            if (cameraList_.size() > 0)
89                cameraList_.front()->setFocus(this->viewport_);
90        }
91        else
92        {
93            this->cameraList_.remove(camera);
94        }
95    }
96}
Note: See TracBrowser for help on using the repository browser.