[1039] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1056] | 3 | * > www.orxonox.net < |
---|
[1039] | 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: |
---|
[1287] | 25 | * Benjamin Knecht |
---|
[1039] | 26 | * |
---|
| 27 | */ |
---|
[784] | 28 | |
---|
[786] | 29 | #include "OrxonoxStableHeaders.h" |
---|
[1039] | 30 | #include "Camera.h" |
---|
[1287] | 31 | #include "CameraHandler.h" |
---|
[784] | 32 | |
---|
[715] | 33 | #include <string> |
---|
| 34 | |
---|
[515] | 35 | #include <OgreSceneManager.h> |
---|
| 36 | #include <OgreSceneNode.h> |
---|
| 37 | #include <OgreRenderWindow.h> |
---|
[708] | 38 | #include <OgreViewport.h> |
---|
[515] | 39 | |
---|
[742] | 40 | #include "util/tinyxml/tinyxml.h" |
---|
[1067] | 41 | #include "util/SubString.h" |
---|
[1064] | 42 | #include "util/Convert.h" |
---|
[742] | 43 | #include "util/Math.h" |
---|
[1032] | 44 | #include "core/Debug.h" |
---|
| 45 | #include "core/CoreIncludes.h" |
---|
| 46 | #include "GraphicsEngine.h" |
---|
[515] | 47 | |
---|
| 48 | namespace orxonox |
---|
| 49 | { |
---|
| 50 | |
---|
[1201] | 51 | Camera::Camera(Ogre::SceneNode* node) |
---|
| 52 | { |
---|
| 53 | this->bHasFocus_ = false; |
---|
[1287] | 54 | this->cameraNode_ = GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(node->getName() + "Camera"); |
---|
[1201] | 55 | if( node != NULL ) |
---|
[1287] | 56 | this->setPositionNode(node); |
---|
[1201] | 57 | } |
---|
[515] | 58 | |
---|
[1201] | 59 | Camera::~Camera() |
---|
| 60 | { |
---|
[1287] | 61 | CameraHandler::getInstance()->releaseFocus(this); |
---|
[1201] | 62 | } |
---|
| 63 | |
---|
[1287] | 64 | void Camera::setPositionNode(Ogre::SceneNode* node) |
---|
[1201] | 65 | { |
---|
| 66 | this->positionNode_ = node; |
---|
| 67 | // set camera to node values according to camera mode |
---|
| 68 | } |
---|
[560] | 69 | |
---|
[1201] | 70 | void Camera::setTargetNode(Ogre::SceneNode* obj) |
---|
| 71 | { |
---|
| 72 | this->targetNode_ = obj; |
---|
| 73 | } |
---|
| 74 | |
---|
[1287] | 75 | void Camera::tick(float dt) |
---|
| 76 | { |
---|
| 77 | if(this->positionNode_ != NULL) { |
---|
| 78 | // this stuff here may need some adjustments |
---|
| 79 | Vector3 offset = this->positionNode_->getWorldPosition() - this->cameraNode_->getPosition(); |
---|
| 80 | this->cameraNode_->translate(15*dt*offset); |
---|
| 81 | |
---|
| 82 | this->cameraNode_->setOrientation(Quaternion::Slerp(0.7, this->positionNode_->getWorldOrientation(), this->cameraNode_->getWorldOrientation(), false)); |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
[1201] | 86 | /** |
---|
| 87 | don't move anything before here! here the Ogre camera is set to values of this camera |
---|
| 88 | always call update after changes |
---|
| 89 | */ |
---|
| 90 | void Camera::update() |
---|
| 91 | { |
---|
| 92 | if(this->positionNode_ != NULL) |
---|
[1287] | 93 | { |
---|
| 94 | this->cameraNode_->setPosition(this->positionNode_->getWorldPosition()); |
---|
| 95 | this->cameraNode_->setOrientation(this->positionNode_->getWorldOrientation()); |
---|
| 96 | } |
---|
[1201] | 97 | } |
---|
| 98 | |
---|
| 99 | /** |
---|
| 100 | what to do when camera loses focus (do not request focus in this function!!) |
---|
| 101 | this is called by the CameraHandler singleton class to notify the camera |
---|
| 102 | */ |
---|
| 103 | void Camera::removeFocus() |
---|
| 104 | { |
---|
| 105 | this->bHasFocus_ = false; |
---|
[1287] | 106 | this->cameraNode_->detachObject(this->cam_); |
---|
[1201] | 107 | } |
---|
| 108 | |
---|
| 109 | void Camera::setFocus(Ogre::Camera* ogreCam) |
---|
| 110 | { |
---|
| 111 | this->bHasFocus_ = true; |
---|
| 112 | this->cam_ = ogreCam; |
---|
[1287] | 113 | this->cam_->setOrientation(this->cameraNode_->getWorldOrientation()); |
---|
| 114 | this->cameraNode_->attachObject(this->cam_); |
---|
[1201] | 115 | } |
---|
[515] | 116 | } |
---|