Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy2/src/orxonox/CameraManager.cc @ 2369

Last change on this file since 2369 was 2369, checked in by landauf, 15 years ago
  • Added a health bar
  • Some changes in CameraManager to handle the case when no camera exists after removing the last one, but this is still somehow buggy (freezes and later crashes reproducible but inexplicable after a few respawns)
  • Added PawnManager to handle destruction of Pawns without using delete within tick()
  • Property svn:eol-style set to native
  • Property svn:mergeinfo set to (toggle deleted branches)
    /code/branches/ceguilua/src/orxonox/objects/CameraHandler.cc1802-1808
    /code/branches/core3/src/orxonox/objects/CameraHandler.cc1572-1739
    /code/branches/gcc43/src/orxonox/objects/CameraHandler.cc1580
    /code/branches/gui/src/orxonox/objects/CameraHandler.cc1635-1723
    /code/branches/input/src/orxonox/objects/CameraHandler.cc1629-1636
    /code/branches/objecthierarchy/src/orxonox/CameraManager.cc2100,​2110-2169
    /code/branches/script_trigger/src/orxonox/objects/CameraHandler.cc1295-1953,​1955
File size: 3.8 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#include "OrxonoxStableHeaders.h"
29#include "CameraManager.h"
30
31#include <OgreViewport.h>
32#include <OgreSceneManager.h>
33#include <OgreCamera.h>
34
35#include "core/Core.h"
36#include "objects/worldentities/Camera.h"
37#include "objects/Scene.h"
38#include "util/String.h"
39
40namespace orxonox
41{
42    CameraManager* CameraManager::singletonRef_s = 0;
43
44    CameraManager::CameraManager(Ogre::Viewport* viewport)
45        : viewport_(viewport)
46    {
47        assert(singletonRef_s == 0);
48        singletonRef_s = this;
49
50        this->fallbackCamera_ = 0;
51    }
52
53    CameraManager::~CameraManager()
54    {
55        assert(singletonRef_s != 0);
56        singletonRef_s = 0;
57
58        if (this->fallbackCamera_)
59        {
60            this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_);
61COUT(0) << "remove camera-manager" << std::endl;
62        }
63    }
64
65    Camera* CameraManager::getActiveCamera() const
66    {
67        if (this->cameraList_.size() > 0)
68            return this->cameraList_.front();
69        else
70            return 0;
71    }
72
73    void CameraManager::requestFocus(Camera* camera)
74    {
75        if (!Core::showsGraphics())
76            return;
77
78        // notify old camera (if it exists)
79        if (this->cameraList_.size() > 0)
80            this->cameraList_.front()->removeFocus();
81        else if (this->fallbackCamera_)
82        {
83            this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_);
84            this->fallbackCamera_ = 0;
85COUT(0) << "remove fallback camera" << std::endl;
86        }
87
88        camera->setFocus(this->viewport_);
89
90        // make sure we don't add it twice
91        for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end(); ++it)
92            if ((*it) == camera)
93                return;
94
95        // add to list
96        this->cameraList_.push_front(camera);
97    }
98
99    void CameraManager::releaseFocus(Camera* camera)
100    {
101        if (!Core::showsGraphics())
102            return;
103
104        // notify the cam of releasing the focus
105        if (this->cameraList_.front() == camera)
106        {
107            camera->removeFocus();
108            this->cameraList_.pop_front();
109
110            // set new focus if possible
111            if (this->cameraList_.size() > 0)
112                this->cameraList_.front()->setFocus(this->viewport_);
113            else
114            {
115                // there are no more cameras, create a fallback
116                if (!this->fallbackCamera_)
117                {
118COUT(0) << "create fallback camera" << std::endl;
119                    this->fallbackCamera_ = camera->getScene()->getSceneManager()->createCamera(getUniqueNumberString());
120                }
121                this->viewport_->setCamera(this->fallbackCamera_);
122COUT(0) << "use fallback camera" << std::endl;
123            }
124        }
125        else
126        {
127            this->cameraList_.remove(camera);
128        }
129    }
130}
Note: See TracBrowser for help on using the repository browser.