[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 | |
---|
| 32 | #include <string> |
---|
[2019] | 33 | #include <cassert> |
---|
[1505] | 34 | |
---|
[2023] | 35 | #include <OgreCamera.h> |
---|
[1505] | 36 | #include <OgreSceneManager.h> |
---|
| 37 | #include <OgreSceneNode.h> |
---|
| 38 | #include <OgreViewport.h> |
---|
| 39 | |
---|
| 40 | #include "core/CoreIncludes.h" |
---|
[2019] | 41 | #include "core/ConfigValueIncludes.h" |
---|
| 42 | #include "objects/Scene.h" |
---|
[2073] | 43 | #include "CameraManager.h" |
---|
[1505] | 44 | |
---|
| 45 | namespace orxonox |
---|
| 46 | { |
---|
[2019] | 47 | CreateFactory(Camera); |
---|
[1993] | 48 | |
---|
[2019] | 49 | Camera::Camera(BaseObject* creator) : PositionableEntity(creator) |
---|
| 50 | { |
---|
| 51 | RegisterObject(Camera); |
---|
[1505] | 52 | |
---|
[2019] | 53 | assert(this->getScene()); |
---|
| 54 | assert(this->getScene()->getSceneManager()); |
---|
[1505] | 55 | |
---|
[2019] | 56 | this->camera_ = this->getScene()->getSceneManager()->createCamera(getUniqueNumberString()); |
---|
| 57 | this->getNode()->attachObject(this->camera_); |
---|
| 58 | |
---|
| 59 | this->bHasFocus_ = false; |
---|
| 60 | this->bDrag_ = false; |
---|
| 61 | this->nearClipDistance_ = 1; |
---|
| 62 | |
---|
| 63 | this->setObjectMode(0x0); |
---|
| 64 | |
---|
| 65 | this->setConfigValues(); |
---|
| 66 | this->configvaluecallback_changedNearClipDistance(); |
---|
| 67 | |
---|
| 68 | this->requestFocus(); // ! HACK ! REMOVE THIS ! |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | Camera::~Camera() |
---|
[1989] | 72 | { |
---|
[2019] | 73 | if (this->isInitialized()) |
---|
| 74 | { |
---|
| 75 | this->releaseFocus(); |
---|
| 76 | } |
---|
[1989] | 77 | } |
---|
[1505] | 78 | |
---|
[2019] | 79 | void Camera::setConfigValues() |
---|
| 80 | { |
---|
| 81 | SetConfigValue(nearClipDistance_, 1.0f).callback(this, &Camera::configvaluecallback_changedNearClipDistance); |
---|
| 82 | } |
---|
[1505] | 83 | |
---|
[2019] | 84 | void Camera::configvaluecallback_changedNearClipDistance() |
---|
| 85 | { |
---|
| 86 | this->camera_->setNearClipDistance(this->nearClipDistance_); |
---|
| 87 | } |
---|
[1505] | 88 | |
---|
[2019] | 89 | void Camera::tick(float dt) |
---|
| 90 | { |
---|
| 91 | /* |
---|
| 92 | // this stuff here may need some adjustments |
---|
| 93 | float coeff = (this->bDrag_) ? min(1.0f, 15.0f * dt) : (1.0f); |
---|
[1505] | 94 | |
---|
[2019] | 95 | Vector3 offset = this->getNode()->getWorldPosition() - this->cameraNode_->getWorldPosition(); |
---|
| 96 | this->cameraNode_->translate(coeff * offset); |
---|
[1505] | 97 | |
---|
[2019] | 98 | this->cameraNode_->setOrientation(Quaternion::Slerp(coeff, this->cameraNode_->getWorldOrientation(), this->getWorldOrientation(), false)); |
---|
| 99 | */ |
---|
| 100 | } |
---|
[1505] | 101 | |
---|
[2019] | 102 | void Camera::requestFocus() |
---|
| 103 | { |
---|
[2073] | 104 | CameraManager::getInstance().requestFocus(this); |
---|
[2019] | 105 | } |
---|
[1989] | 106 | |
---|
[2019] | 107 | void Camera::releaseFocus() |
---|
| 108 | { |
---|
[2073] | 109 | CameraManager::getInstance().releaseFocus(this); |
---|
[2019] | 110 | } |
---|
| 111 | |
---|
| 112 | /** |
---|
| 113 | what to do when camera loses focus (do not request focus in this function!!) |
---|
[2073] | 114 | this is called by the CameraManager singleton class to notify the camera |
---|
[2019] | 115 | */ |
---|
| 116 | void Camera::removeFocus() |
---|
| 117 | { |
---|
| 118 | this->bHasFocus_ = false; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | void Camera::setFocus(Ogre::Viewport* viewport) |
---|
| 122 | { |
---|
| 123 | this->bHasFocus_ = true; |
---|
| 124 | viewport->setCamera(this->camera_); |
---|
| 125 | } |
---|
[1505] | 126 | } |
---|