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 | #include <cassert> |
---|
35 | |
---|
36 | #include <OgreSceneManager.h> |
---|
37 | #include <OgreSceneNode.h> |
---|
38 | #include <OgreRenderWindow.h> |
---|
39 | #include <OgreViewport.h> |
---|
40 | |
---|
41 | #include "tinyxml/tinyxml.h" |
---|
42 | #include "util/SubString.h" |
---|
43 | #include "util/Math.h" |
---|
44 | #include "util/String.h" |
---|
45 | #include "util/Debug.h" |
---|
46 | #include "core/CoreIncludes.h" |
---|
47 | #include "core/ConfigValueIncludes.h" |
---|
48 | #include "GraphicsEngine.h" |
---|
49 | #include "objects/Scene.h" |
---|
50 | |
---|
51 | namespace orxonox |
---|
52 | { |
---|
53 | CreateFactory(Camera); |
---|
54 | |
---|
55 | Camera::Camera(BaseObject* creator) : PositionableEntity(creator) |
---|
56 | { |
---|
57 | RegisterObject(Camera); |
---|
58 | |
---|
59 | assert(this->getScene()); |
---|
60 | assert(this->getScene()->getSceneManager()); |
---|
61 | |
---|
62 | this->camera_ = this->getScene()->getSceneManager()->createCamera(getUniqueNumberString()); |
---|
63 | this->getNode()->attachObject(this->camera_); |
---|
64 | |
---|
65 | this->bHasFocus_ = false; |
---|
66 | this->bDrag_ = false; |
---|
67 | this->nearClipDistance_ = 1; |
---|
68 | |
---|
69 | this->setObjectMode(0x0); |
---|
70 | |
---|
71 | this->setConfigValues(); |
---|
72 | this->configvaluecallback_changedNearClipDistance(); |
---|
73 | |
---|
74 | this->requestFocus(); // ! HACK ! REMOVE THIS ! |
---|
75 | } |
---|
76 | |
---|
77 | Camera::~Camera() |
---|
78 | { |
---|
79 | if (this->isInitialized()) |
---|
80 | { |
---|
81 | this->releaseFocus(); |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | void Camera::setConfigValues() |
---|
86 | { |
---|
87 | SetConfigValue(nearClipDistance_, 1.0f).callback(this, &Camera::configvaluecallback_changedNearClipDistance); |
---|
88 | } |
---|
89 | |
---|
90 | void Camera::configvaluecallback_changedNearClipDistance() |
---|
91 | { |
---|
92 | this->camera_->setNearClipDistance(this->nearClipDistance_); |
---|
93 | } |
---|
94 | |
---|
95 | void Camera::tick(float dt) |
---|
96 | { |
---|
97 | /* |
---|
98 | // this stuff here may need some adjustments |
---|
99 | float coeff = (this->bDrag_) ? min(1.0f, 15.0f * dt) : (1.0f); |
---|
100 | |
---|
101 | Vector3 offset = this->getNode()->getWorldPosition() - this->cameraNode_->getWorldPosition(); |
---|
102 | this->cameraNode_->translate(coeff * offset); |
---|
103 | |
---|
104 | this->cameraNode_->setOrientation(Quaternion::Slerp(coeff, this->cameraNode_->getWorldOrientation(), this->getWorldOrientation(), false)); |
---|
105 | */ |
---|
106 | } |
---|
107 | |
---|
108 | void Camera::requestFocus() |
---|
109 | { |
---|
110 | CameraHandler::getInstance().requestFocus(this); |
---|
111 | } |
---|
112 | |
---|
113 | void Camera::releaseFocus() |
---|
114 | { |
---|
115 | CameraHandler::getInstance().releaseFocus(this); |
---|
116 | } |
---|
117 | |
---|
118 | /** |
---|
119 | what to do when camera loses focus (do not request focus in this function!!) |
---|
120 | this is called by the CameraHandler singleton class to notify the camera |
---|
121 | */ |
---|
122 | void Camera::removeFocus() |
---|
123 | { |
---|
124 | this->bHasFocus_ = false; |
---|
125 | } |
---|
126 | |
---|
127 | void Camera::setFocus(Ogre::Viewport* viewport) |
---|
128 | { |
---|
129 | this->bHasFocus_ = true; |
---|
130 | viewport->setCamera(this->camera_); |
---|
131 | } |
---|
132 | } |
---|