Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/worldentities/Camera.cc @ 2194

Last change on this file since 2194 was 2171, checked in by landauf, 16 years ago

merged revisions 2111-2170 from objecthierarchy branch back to trunk.

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