Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hud3/src/orxonox/objects/Camera.cc @ 1356

Last change on this file since 1356 was 1264, checked in by scheusso, 17 years ago

merge network3 and camera branch into merge branch

File size: 4.4 KB
Line 
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 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "Camera.h"
31
32#include <string>
33
34#include <OgreSceneManager.h>
35#include <OgreSceneNode.h>
36#include <OgreRenderWindow.h>
37#include <OgreViewport.h>
38
39#include "tinyxml/tinyxml.h"
40#include "util/SubString.h"
41#include "util/Convert.h"
42#include "util/Math.h"
43#include "core/Debug.h"
44#include "core/CoreIncludes.h"
45#include "GraphicsEngine.h"
46
47namespace orxonox
48{
49  //CreateFactory(Camera);
50
51  Camera::Camera(Ogre::SceneNode* node)
52  {
53    //RegisterObject(Camera);
54    this->bHasFocus_ = false;
55    if( node != NULL )
56      this->setCameraNode(node);
57
58  }
59
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"))
69    {
70      //    <Camera name="Camera" pos="0,0,-250" lookat="0,0,0" />
71
72      std::string name = xmlElem->Attribute("name");
73      std::string pos = xmlElem->Attribute("pos");
74      std::string lookat = xmlElem->Attribute("lookat");
75
76      this->cam_ = mgr->createCamera(name);
77
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]);
83
84      setPosition(Vector3(x,y,z));
85
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]);
91
92      cam_->lookAt(Vector3(x,y,z));
93
94      /*std::string node = xmlElem->Attribute("node");
95
96      Ogre::SceneNode* sceneNode = (Ogre::SceneNode*)mgr->getRootSceneNode()->createChildSceneNode(node); //getChild(node);
97      sceneNode->attachObject((Ogre::MovableObject*)cam_);
98      */
99
100      // FIXME: unused var
101      //Ogre::Viewport* vp =
102      //GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam_);
103    /*
104
105      COUT(4) << "Loader: Created camera "<< name  << std::endl << std::endl;
106    }
107  }*/
108
109  void Camera::setCameraNode(Ogre::SceneNode* node)
110  {
111    this->positionNode_ = node;
112    // set camera to node values according to camera mode
113  }
114
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)
129      this->cam_->setPosition(this->positionNode_->getPosition());
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;
141    this->positionNode_->detachObject(cam_);
142  }
143
144  void Camera::setFocus(Ogre::Camera* ogreCam)
145  {
146    this->bHasFocus_ = true;
147    this->cam_ = ogreCam;
148    this->positionNode_->attachObject(cam_);
149  }
150}
Note: See TracBrowser for help on using the repository browser.