[1505] | 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 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * Benjamin Knecht |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "OrxonoxStableHeaders.h" |
---|
| 30 | #include "Camera.h" |
---|
| 31 | #include "CameraHandler.h" |
---|
| 32 | |
---|
| 33 | #include <string> |
---|
| 34 | |
---|
| 35 | #include <OgreSceneManager.h> |
---|
| 36 | #include <OgreSceneNode.h> |
---|
| 37 | #include <OgreRenderWindow.h> |
---|
| 38 | #include <OgreViewport.h> |
---|
| 39 | |
---|
| 40 | #include "tinyxml/tinyxml.h" |
---|
| 41 | #include "util/SubString.h" |
---|
| 42 | #include "util/Math.h" |
---|
[1747] | 43 | #include "util/Debug.h" |
---|
[1505] | 44 | #include "core/CoreIncludes.h" |
---|
| 45 | #include "GraphicsEngine.h" |
---|
| 46 | |
---|
| 47 | namespace orxonox |
---|
| 48 | { |
---|
[1993] | 49 | CreateUnloadableFactory(Camera); |
---|
| 50 | |
---|
[1989] | 51 | Camera::Camera() |
---|
| 52 | { |
---|
| 53 | RegisterObject(Camera); |
---|
[1505] | 54 | |
---|
| 55 | this->bHasFocus_ = false; |
---|
[1989] | 56 | this->bDrag_ = false; |
---|
| 57 | this->cameraNode_ = GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode(); |
---|
| 58 | this->setObjectMode(0x0); |
---|
[1505] | 59 | } |
---|
| 60 | |
---|
| 61 | Camera::~Camera() |
---|
| 62 | { |
---|
[1989] | 63 | if (this->isInitialized()) |
---|
| 64 | { |
---|
| 65 | CameraHandler::getInstance()->releaseFocus(this); |
---|
| 66 | GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->removeAndDestroyChild(this->cameraNode_->getName()); |
---|
| 67 | } |
---|
[1505] | 68 | } |
---|
| 69 | |
---|
| 70 | void Camera::tick(float dt) |
---|
| 71 | { |
---|
| 72 | // this stuff here may need some adjustments |
---|
[1989] | 73 | float coeff = (this->bDrag_) ? min(1.0f, 15.0f * dt) : (1.0f); |
---|
[1505] | 74 | |
---|
[1989] | 75 | Vector3 offset = this->getNode()->getWorldPosition() - this->cameraNode_->getWorldPosition(); |
---|
[1505] | 76 | this->cameraNode_->translate(coeff * offset); |
---|
| 77 | |
---|
[1989] | 78 | this->cameraNode_->setOrientation(Quaternion::Slerp(coeff, this->cameraNode_->getWorldOrientation(), this->getWorldOrientation(), false)); |
---|
[1505] | 79 | } |
---|
| 80 | |
---|
| 81 | /** |
---|
| 82 | don't move anything before here! here the Ogre camera is set to values of this camera |
---|
| 83 | always call update after changes |
---|
| 84 | */ |
---|
| 85 | void Camera::update() |
---|
| 86 | { |
---|
[1989] | 87 | this->cameraNode_->setPosition(this->getWorldPosition()); |
---|
| 88 | this->cameraNode_->setOrientation(this->getWorldOrientation()); |
---|
[1505] | 89 | } |
---|
| 90 | |
---|
| 91 | /** |
---|
| 92 | what to do when camera loses focus (do not request focus in this function!!) |
---|
| 93 | this is called by the CameraHandler singleton class to notify the camera |
---|
| 94 | */ |
---|
| 95 | void Camera::removeFocus() |
---|
| 96 | { |
---|
| 97 | this->bHasFocus_ = false; |
---|
| 98 | this->cameraNode_->detachObject(this->cam_); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | void Camera::setFocus(Ogre::Camera* ogreCam) |
---|
| 102 | { |
---|
| 103 | this->bHasFocus_ = true; |
---|
| 104 | this->cam_ = ogreCam; |
---|
| 105 | this->cam_->setOrientation(this->cameraNode_->getWorldOrientation()); |
---|
| 106 | this->cameraNode_->attachObject(this->cam_); |
---|
| 107 | } |
---|
[1989] | 108 | |
---|
| 109 | void Camera::requestFocus() |
---|
| 110 | { |
---|
| 111 | CameraHandler::getInstance()->requestFocus(this); |
---|
| 112 | } |
---|
[1505] | 113 | } |
---|