Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/shader/src/orxonox/objects/Camera.cc @ 2274

Last change on this file since 2274 was 1505, checked in by rgrieder, 17 years ago

f* svn: It doesn't even inform you if you attempt to set a non existing property. It is svn:eol-style and not eol-style when using the command by the way…

  • Property svn:eol-style set to native
File size: 3.5 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 *      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/Convert.h"
43#include "util/Math.h"
44#include "core/Debug.h"
45#include "core/CoreIncludes.h"
46#include "GraphicsEngine.h"
47
48namespace orxonox
49{
50
51  Camera::Camera(Ogre::SceneNode* node)
52  {
53    this->bHasFocus_ = false;
54    this->cameraNode_ = GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(node->getName() + "Camera");
55    if( node != NULL )
56      this->setPositionNode(node);
57  }
58
59  Camera::~Camera()
60  {
61    CameraHandler::getInstance()->releaseFocus(this);
62    GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->removeAndDestroyChild(cameraNode_->getName());
63  }
64
65  void Camera::setPositionNode(Ogre::SceneNode* node)
66  {
67    this->positionNode_ = node;
68    // set camera to node values according to camera mode
69  }
70
71  void Camera::setTargetNode(Ogre::SceneNode* obj)
72  {
73    this->targetNode_ = obj;
74  }
75
76  void Camera::tick(float dt)
77  {
78    if (this->positionNode_ != NULL)
79    {
80      // this stuff here may need some adjustments
81      Vector3 offset = this->positionNode_->getWorldPosition() - this->cameraNode_->getWorldPosition();
82      float coeff = 15.0f * dt;
83      if (coeff > 1.0f)
84        coeff = 1.0f;
85
86      this->cameraNode_->translate(coeff * offset);
87
88      this->cameraNode_->setOrientation(Quaternion::Slerp(7.0f * dt, this->positionNode_->getWorldOrientation(), this->cameraNode_->getWorldOrientation(), false));
89    }
90  }
91
92  /**
93    don't move anything before here! here the Ogre camera is set to values of this camera
94    always call update after changes
95  */
96  void Camera::update()
97  {
98    if(this->positionNode_ != NULL)
99    {
100      this->cameraNode_->setPosition(this->positionNode_->getWorldPosition());
101      this->cameraNode_->setOrientation(this->positionNode_->getWorldOrientation());
102    }
103  }
104
105  /**
106    what to do when camera loses focus (do not request focus in this function!!)
107    this is called by the CameraHandler singleton class to notify the camera
108  */
109  void Camera::removeFocus()
110  {
111    this->bHasFocus_ = false;
112    this->cameraNode_->detachObject(this->cam_);
113  }
114
115  void Camera::setFocus(Ogre::Camera* ogreCam)
116  {
117    this->bHasFocus_ = true;
118    this->cam_ = ogreCam;
119    this->cam_->setOrientation(this->cameraNode_->getWorldOrientation());
120    this->cameraNode_->attachObject(this->cam_);
121  }
122}
Note: See TracBrowser for help on using the repository browser.