[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: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
[784] | 28 | |
---|
[786] | 29 | #include "OrxonoxStableHeaders.h" |
---|
[1039] | 30 | #include "Camera.h" |
---|
[784] | 31 | |
---|
[715] | 32 | #include <string> |
---|
| 33 | |
---|
[515] | 34 | #include <OgreSceneManager.h> |
---|
| 35 | #include <OgreSceneNode.h> |
---|
| 36 | #include <OgreRenderWindow.h> |
---|
[708] | 37 | #include <OgreViewport.h> |
---|
[515] | 38 | |
---|
[742] | 39 | #include "util/tinyxml/tinyxml.h" |
---|
[1067] | 40 | #include "util/SubString.h" |
---|
[1064] | 41 | #include "util/Convert.h" |
---|
[742] | 42 | #include "util/Math.h" |
---|
[1032] | 43 | #include "core/Debug.h" |
---|
| 44 | #include "core/CoreIncludes.h" |
---|
| 45 | #include "GraphicsEngine.h" |
---|
[515] | 46 | |
---|
| 47 | namespace orxonox |
---|
| 48 | { |
---|
[1212] | 49 | //CreateFactory(Camera); |
---|
[515] | 50 | |
---|
[1212] | 51 | Camera::Camera(Ogre::SceneNode* node) |
---|
| 52 | { |
---|
| 53 | //RegisterObject(Camera); |
---|
| 54 | this->bHasFocus_ = false; |
---|
| 55 | if( node != NULL ) |
---|
| 56 | this->setCameraNode(node); |
---|
[515] | 57 | |
---|
[1212] | 58 | } |
---|
[515] | 59 | |
---|
[1212] | 60 | Camera::~Camera() |
---|
| 61 | { |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | /*void Camera::loadParams(TiXmlElement* xmlElem) |
---|
| 65 | { |
---|
| 66 | Ogre::SceneManager* mgr = GraphicsEngine::getSingleton().getSceneManager(); |
---|
| 67 | |
---|
| 68 | if (xmlElem->Attribute("name") && xmlElem->Attribute("pos") && xmlElem->Attribute("lookat") && xmlElem->Attribute("node")) |
---|
[515] | 69 | { |
---|
[1212] | 70 | // <Camera name="Camera" pos="0,0,-250" lookat="0,0,0" /> |
---|
[560] | 71 | |
---|
[1212] | 72 | std::string name = xmlElem->Attribute("name"); |
---|
| 73 | std::string pos = xmlElem->Attribute("pos"); |
---|
| 74 | std::string lookat = xmlElem->Attribute("lookat"); |
---|
[560] | 75 | |
---|
[1212] | 76 | this->cam_ = mgr->createCamera(name); |
---|
[515] | 77 | |
---|
[1212] | 78 | float x, y, z; |
---|
| 79 | SubString posVec(xmlElem->Attribute("pos"), ','); |
---|
| 80 | convertValue<std::string, float>(&x, posVec[0]); |
---|
| 81 | convertValue<std::string, float>(&y, posVec[1]); |
---|
| 82 | convertValue<std::string, float>(&z, posVec[2]); |
---|
[515] | 83 | |
---|
[1212] | 84 | setPosition(Vector3(x,y,z)); |
---|
[515] | 85 | |
---|
[1212] | 86 | //std::string target = xmlElem->Attribute("lookat"); |
---|
| 87 | posVec.split(xmlElem->Attribute("lookat"), ','); |
---|
| 88 | convertValue<std::string, float>(&x, posVec[0]); |
---|
| 89 | convertValue<std::string, float>(&y, posVec[1]); |
---|
| 90 | convertValue<std::string, float>(&z, posVec[2]); |
---|
[515] | 91 | |
---|
[1212] | 92 | cam_->lookAt(Vector3(x,y,z)); |
---|
[515] | 93 | |
---|
[1212] | 94 | /*std::string node = xmlElem->Attribute("node"); |
---|
[515] | 95 | |
---|
[1212] | 96 | Ogre::SceneNode* sceneNode = (Ogre::SceneNode*)mgr->getRootSceneNode()->createChildSceneNode(node); //getChild(node); |
---|
| 97 | sceneNode->attachObject((Ogre::MovableObject*)cam_); |
---|
| 98 | */ |
---|
[560] | 99 | |
---|
[1212] | 100 | // FIXME: unused var |
---|
| 101 | //Ogre::Viewport* vp = |
---|
| 102 | //GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam_); |
---|
| 103 | /* |
---|
[560] | 104 | |
---|
[1212] | 105 | COUT(4) << "Loader: Created camera "<< name << std::endl << std::endl; |
---|
| 106 | } |
---|
| 107 | }*/ |
---|
[515] | 108 | |
---|
[1212] | 109 | void Camera::setCameraNode(Ogre::SceneNode* node) |
---|
| 110 | { |
---|
| 111 | this->positionNode_ = node; |
---|
| 112 | // set camera to node values according to camera mode |
---|
| 113 | } |
---|
[560] | 114 | |
---|
[1212] | 115 | void Camera::setTargetNode(Ogre::SceneNode* obj) |
---|
| 116 | { |
---|
| 117 | this->targetNode_ = obj; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | /** |
---|
| 121 | don't move anything before here! here the Ogre camera is set to values of this camera |
---|
| 122 | always call update after changes |
---|
| 123 | */ |
---|
| 124 | void Camera::update() |
---|
| 125 | { |
---|
| 126 | COUT(0) << "p " << this->positionNode_->getPosition() << std::endl; |
---|
| 127 | COUT(0) << "t " << this->targetNode_->getPosition() << std::endl; |
---|
| 128 | if(this->positionNode_ != NULL) |
---|
[1232] | 129 | this->cam_->setPosition(this->positionNode_->getPosition()); |
---|
[1212] | 130 | if(this->targetNode_ != NULL) |
---|
| 131 | this->cam_->lookAt(this->targetNode_->getPosition()); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | /** |
---|
| 135 | what to do when camera loses focus (do not request focus in this function!!) |
---|
| 136 | this is called by the CameraHandler singleton class to notify the camera |
---|
| 137 | */ |
---|
| 138 | void Camera::removeFocus() |
---|
| 139 | { |
---|
| 140 | this->bHasFocus_ = false; |
---|
[1232] | 141 | this->positionNode_->detachObject(cam_); |
---|
[1212] | 142 | } |
---|
| 143 | |
---|
| 144 | void Camera::setFocus(Ogre::Camera* ogreCam) |
---|
| 145 | { |
---|
| 146 | this->bHasFocus_ = true; |
---|
| 147 | this->cam_ = ogreCam; |
---|
| 148 | this->positionNode_->attachObject(cam_); |
---|
| 149 | } |
---|
[515] | 150 | } |
---|