[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: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
[1502] | 28 | #include "OrxonoxStableHeaders.h" |
---|
| 29 | #include "CameraHandler.h" |
---|
| 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] | 37 | namespace orxonox |
---|
| 38 | { |
---|
[2023] | 39 | CameraHandler* CameraHandler::singletonRef_s = 0; |
---|
| 40 | |
---|
| 41 | CameraHandler::CameraHandler(Ogre::Viewport* viewport) |
---|
| 42 | : viewport_(viewport) |
---|
[2019] | 43 | { |
---|
[2023] | 44 | assert(singletonRef_s == 0); |
---|
| 45 | singletonRef_s = this; |
---|
[2019] | 46 | } |
---|
[1202] | 47 | |
---|
[2023] | 48 | CameraHandler::~CameraHandler() |
---|
[2019] | 49 | { |
---|
[2023] | 50 | assert(singletonRef_s != 0); |
---|
| 51 | singletonRef_s = 0; |
---|
[2019] | 52 | } |
---|
[1202] | 53 | |
---|
[2019] | 54 | Camera* CameraHandler::getActiveCamera() const |
---|
| 55 | { |
---|
| 56 | if (this->cameraList_.size() > 0) |
---|
| 57 | return this->cameraList_.front(); |
---|
| 58 | else |
---|
| 59 | return 0; |
---|
| 60 | } |
---|
[1202] | 61 | |
---|
[2019] | 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); |
---|
[2023] | 73 | camera->setFocus(this->viewport_); |
---|
[1202] | 74 | } |
---|
| 75 | |
---|
[2019] | 76 | void CameraHandler::releaseFocus(Camera* camera) |
---|
[1202] | 77 | { |
---|
[2019] | 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) |
---|
[2023] | 89 | cameraList_.front()->setFocus(this->viewport_); |
---|
[2019] | 90 | } |
---|
| 91 | else |
---|
| 92 | { |
---|
| 93 | this->cameraList_.remove(camera); |
---|
| 94 | } |
---|
[1202] | 95 | } |
---|
| 96 | } |
---|