aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorCameraMaya.cpp
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 18:54:10 +1000
committerDavid Walter Seikel2013-01-13 18:54:10 +1000
commit959831f4ef5a3e797f576c3de08cd65032c997ad (patch)
treee7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorCameraMaya.cpp
parentAdd info about changes to Irrlicht. (diff)
downloadSledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorCameraMaya.cpp634
1 files changed, 317 insertions, 317 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorCameraMaya.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorCameraMaya.cpp
index 00ac133..646b159 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorCameraMaya.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorCameraMaya.cpp
@@ -1,317 +1,317 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt 1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine". 2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h 3// For conditions of distribution and use, see copyright notice in irrlicht.h
4 4
5#include "CSceneNodeAnimatorCameraMaya.h" 5#include "CSceneNodeAnimatorCameraMaya.h"
6#include "ICursorControl.h" 6#include "ICursorControl.h"
7#include "ICameraSceneNode.h" 7#include "ICameraSceneNode.h"
8#include "SViewFrustum.h" 8#include "SViewFrustum.h"
9#include "ISceneManager.h" 9#include "ISceneManager.h"
10 10
11namespace irr 11namespace irr
12{ 12{
13namespace scene 13namespace scene
14{ 14{
15 15
16//! constructor 16//! constructor
17CSceneNodeAnimatorCameraMaya::CSceneNodeAnimatorCameraMaya(gui::ICursorControl* cursor, 17CSceneNodeAnimatorCameraMaya::CSceneNodeAnimatorCameraMaya(gui::ICursorControl* cursor,
18 f32 rotateSpeed, f32 zoomSpeed, f32 translateSpeed, f32 distance) 18 f32 rotateSpeed, f32 zoomSpeed, f32 translateSpeed, f32 distance)
19 : CursorControl(cursor), OldCamera(0), MousePos(0.5f, 0.5f), 19 : CursorControl(cursor), OldCamera(0), MousePos(0.5f, 0.5f),
20 ZoomSpeed(zoomSpeed), RotateSpeed(rotateSpeed), TranslateSpeed(translateSpeed), 20 ZoomSpeed(zoomSpeed), RotateSpeed(rotateSpeed), TranslateSpeed(translateSpeed),
21 CurrentZoom(distance), RotX(0.0f), RotY(0.0f), 21 CurrentZoom(distance), RotX(0.0f), RotY(0.0f),
22 Zooming(false), Rotating(false), Moving(false), Translating(false) 22 Zooming(false), Rotating(false), Moving(false), Translating(false)
23{ 23{
24 #ifdef _DEBUG 24 #ifdef _DEBUG
25 setDebugName("CSceneNodeAnimatorCameraMaya"); 25 setDebugName("CSceneNodeAnimatorCameraMaya");
26 #endif 26 #endif
27 27
28 if (CursorControl) 28 if (CursorControl)
29 { 29 {
30 CursorControl->grab(); 30 CursorControl->grab();
31 MousePos = CursorControl->getRelativePosition(); 31 MousePos = CursorControl->getRelativePosition();
32 } 32 }
33 33
34 allKeysUp(); 34 allKeysUp();
35} 35}
36 36
37 37
38//! destructor 38//! destructor
39CSceneNodeAnimatorCameraMaya::~CSceneNodeAnimatorCameraMaya() 39CSceneNodeAnimatorCameraMaya::~CSceneNodeAnimatorCameraMaya()
40{ 40{
41 if (CursorControl) 41 if (CursorControl)
42 CursorControl->drop(); 42 CursorControl->drop();
43} 43}
44 44
45 45
46//! It is possible to send mouse and key events to the camera. Most cameras 46//! It is possible to send mouse and key events to the camera. Most cameras
47//! may ignore this input, but camera scene nodes which are created for 47//! may ignore this input, but camera scene nodes which are created for
48//! example with scene::ISceneManager::addMayaCameraSceneNode or 48//! example with scene::ISceneManager::addMayaCameraSceneNode or
49//! scene::ISceneManager::addMeshViewerCameraSceneNode, may want to get this input 49//! scene::ISceneManager::addMeshViewerCameraSceneNode, may want to get this input
50//! for changing their position, look at target or whatever. 50//! for changing their position, look at target or whatever.
51bool CSceneNodeAnimatorCameraMaya::OnEvent(const SEvent& event) 51bool CSceneNodeAnimatorCameraMaya::OnEvent(const SEvent& event)
52{ 52{
53 if (event.EventType != EET_MOUSE_INPUT_EVENT) 53 if (event.EventType != EET_MOUSE_INPUT_EVENT)
54 return false; 54 return false;
55 55
56 switch(event.MouseInput.Event) 56 switch(event.MouseInput.Event)
57 { 57 {
58 case EMIE_LMOUSE_PRESSED_DOWN: 58 case EMIE_LMOUSE_PRESSED_DOWN:
59 MouseKeys[0] = true; 59 MouseKeys[0] = true;
60 break; 60 break;
61 case EMIE_RMOUSE_PRESSED_DOWN: 61 case EMIE_RMOUSE_PRESSED_DOWN:
62 MouseKeys[2] = true; 62 MouseKeys[2] = true;
63 break; 63 break;
64 case EMIE_MMOUSE_PRESSED_DOWN: 64 case EMIE_MMOUSE_PRESSED_DOWN:
65 MouseKeys[1] = true; 65 MouseKeys[1] = true;
66 break; 66 break;
67 case EMIE_LMOUSE_LEFT_UP: 67 case EMIE_LMOUSE_LEFT_UP:
68 MouseKeys[0] = false; 68 MouseKeys[0] = false;
69 break; 69 break;
70 case EMIE_RMOUSE_LEFT_UP: 70 case EMIE_RMOUSE_LEFT_UP:
71 MouseKeys[2] = false; 71 MouseKeys[2] = false;
72 break; 72 break;
73 case EMIE_MMOUSE_LEFT_UP: 73 case EMIE_MMOUSE_LEFT_UP:
74 MouseKeys[1] = false; 74 MouseKeys[1] = false;
75 break; 75 break;
76 case EMIE_MOUSE_MOVED: 76 case EMIE_MOUSE_MOVED:
77 MousePos = CursorControl->getRelativePosition(); 77 MousePos = CursorControl->getRelativePosition();
78 break; 78 break;
79 case EMIE_MOUSE_WHEEL: 79 case EMIE_MOUSE_WHEEL:
80 case EMIE_LMOUSE_DOUBLE_CLICK: 80 case EMIE_LMOUSE_DOUBLE_CLICK:
81 case EMIE_RMOUSE_DOUBLE_CLICK: 81 case EMIE_RMOUSE_DOUBLE_CLICK:
82 case EMIE_MMOUSE_DOUBLE_CLICK: 82 case EMIE_MMOUSE_DOUBLE_CLICK:
83 case EMIE_LMOUSE_TRIPLE_CLICK: 83 case EMIE_LMOUSE_TRIPLE_CLICK:
84 case EMIE_RMOUSE_TRIPLE_CLICK: 84 case EMIE_RMOUSE_TRIPLE_CLICK:
85 case EMIE_MMOUSE_TRIPLE_CLICK: 85 case EMIE_MMOUSE_TRIPLE_CLICK:
86 case EMIE_COUNT: 86 case EMIE_COUNT:
87 return false; 87 return false;
88 } 88 }
89 return true; 89 return true;
90} 90}
91 91
92 92
93//! OnAnimate() is called just before rendering the whole scene. 93//! OnAnimate() is called just before rendering the whole scene.
94void CSceneNodeAnimatorCameraMaya::animateNode(ISceneNode *node, u32 timeMs) 94void CSceneNodeAnimatorCameraMaya::animateNode(ISceneNode *node, u32 timeMs)
95{ 95{
96 //Alt + LM = Rotate around camera pivot 96 //Alt + LM = Rotate around camera pivot
97 //Alt + LM + MM = Dolly forth/back in view direction (speed % distance camera pivot - max distance to pivot) 97 //Alt + LM + MM = Dolly forth/back in view direction (speed % distance camera pivot - max distance to pivot)
98 //Alt + MM = Move on camera plane (Screen center is about the mouse pointer, depending on move speed) 98 //Alt + MM = Move on camera plane (Screen center is about the mouse pointer, depending on move speed)
99 99
100 if (!node || node->getType() != ESNT_CAMERA) 100 if (!node || node->getType() != ESNT_CAMERA)
101 return; 101 return;
102 102
103 ICameraSceneNode* camera = static_cast<ICameraSceneNode*>(node); 103 ICameraSceneNode* camera = static_cast<ICameraSceneNode*>(node);
104 104
105 // If the camera isn't the active camera, and receiving input, then don't process it. 105 // If the camera isn't the active camera, and receiving input, then don't process it.
106 if (!camera->isInputReceiverEnabled()) 106 if (!camera->isInputReceiverEnabled())
107 return; 107 return;
108 108
109 scene::ISceneManager * smgr = camera->getSceneManager(); 109 scene::ISceneManager * smgr = camera->getSceneManager();
110 if (smgr && smgr->getActiveCamera() != camera) 110 if (smgr && smgr->getActiveCamera() != camera)
111 return; 111 return;
112 112
113 if (OldCamera != camera) 113 if (OldCamera != camera)
114 { 114 {
115 LastCameraTarget = OldTarget = camera->getTarget(); 115 LastCameraTarget = OldTarget = camera->getTarget();
116 OldCamera = camera; 116 OldCamera = camera;
117 } 117 }
118 else 118 else
119 { 119 {
120 OldTarget += camera->getTarget() - LastCameraTarget; 120 OldTarget += camera->getTarget() - LastCameraTarget;
121 } 121 }
122 122
123 f32 nRotX = RotX; 123 f32 nRotX = RotX;
124 f32 nRotY = RotY; 124 f32 nRotY = RotY;
125 f32 nZoom = CurrentZoom; 125 f32 nZoom = CurrentZoom;
126 126
127 if ( (isMouseKeyDown(0) && isMouseKeyDown(2)) || isMouseKeyDown(1) ) 127 if ( (isMouseKeyDown(0) && isMouseKeyDown(2)) || isMouseKeyDown(1) )
128 { 128 {
129 if (!Zooming) 129 if (!Zooming)
130 { 130 {
131 ZoomStart = MousePos; 131 ZoomStart = MousePos;
132 Zooming = true; 132 Zooming = true;
133 } 133 }
134 else 134 else
135 { 135 {
136 const f32 targetMinDistance = 0.1f; 136 const f32 targetMinDistance = 0.1f;
137 nZoom += (ZoomStart.X - MousePos.X) * ZoomSpeed; 137 nZoom += (ZoomStart.X - MousePos.X) * ZoomSpeed;
138 138
139 if (nZoom < targetMinDistance) // jox: fixed bug: bounce back when zooming to close 139 if (nZoom < targetMinDistance) // jox: fixed bug: bounce back when zooming to close
140 nZoom = targetMinDistance; 140 nZoom = targetMinDistance;
141 } 141 }
142 } 142 }
143 else if (Zooming) 143 else if (Zooming)
144 { 144 {
145 const f32 old = CurrentZoom; 145 const f32 old = CurrentZoom;
146 CurrentZoom = CurrentZoom + (ZoomStart.X - MousePos.X ) * ZoomSpeed; 146 CurrentZoom = CurrentZoom + (ZoomStart.X - MousePos.X ) * ZoomSpeed;
147 nZoom = CurrentZoom; 147 nZoom = CurrentZoom;
148 148
149 if (nZoom < 0) 149 if (nZoom < 0)
150 nZoom = CurrentZoom = old; 150 nZoom = CurrentZoom = old;
151 Zooming = false; 151 Zooming = false;
152 } 152 }
153 153
154 // Translation --------------------------------- 154 // Translation ---------------------------------
155 155
156 core::vector3df translate(OldTarget); 156 core::vector3df translate(OldTarget);
157 const core::vector3df upVector(camera->getUpVector()); 157 const core::vector3df upVector(camera->getUpVector());
158 const core::vector3df target = camera->getTarget(); 158 const core::vector3df target = camera->getTarget();
159 159
160 core::vector3df pos = camera->getPosition(); 160 core::vector3df pos = camera->getPosition();
161 core::vector3df tvectX = pos - target; 161 core::vector3df tvectX = pos - target;
162 tvectX = tvectX.crossProduct(upVector); 162 tvectX = tvectX.crossProduct(upVector);
163 tvectX.normalize(); 163 tvectX.normalize();
164 164
165 const SViewFrustum* const va = camera->getViewFrustum(); 165 const SViewFrustum* const va = camera->getViewFrustum();
166 core::vector3df tvectY = (va->getFarLeftDown() - va->getFarRightDown()); 166 core::vector3df tvectY = (va->getFarLeftDown() - va->getFarRightDown());
167 tvectY = tvectY.crossProduct(upVector.Y > 0 ? pos - target : target - pos); 167 tvectY = tvectY.crossProduct(upVector.Y > 0 ? pos - target : target - pos);
168 tvectY.normalize(); 168 tvectY.normalize();
169 169
170 if (isMouseKeyDown(2) && !Zooming) 170 if (isMouseKeyDown(2) && !Zooming)
171 { 171 {
172 if (!Translating) 172 if (!Translating)
173 { 173 {
174 TranslateStart = MousePos; 174 TranslateStart = MousePos;
175 Translating = true; 175 Translating = true;
176 } 176 }
177 else 177 else
178 { 178 {
179 translate += tvectX * (TranslateStart.X - MousePos.X)*TranslateSpeed + 179 translate += tvectX * (TranslateStart.X - MousePos.X)*TranslateSpeed +
180 tvectY * (TranslateStart.Y - MousePos.Y)*TranslateSpeed; 180 tvectY * (TranslateStart.Y - MousePos.Y)*TranslateSpeed;
181 } 181 }
182 } 182 }
183 else if (Translating) 183 else if (Translating)
184 { 184 {
185 translate += tvectX * (TranslateStart.X - MousePos.X)*TranslateSpeed + 185 translate += tvectX * (TranslateStart.X - MousePos.X)*TranslateSpeed +
186 tvectY * (TranslateStart.Y - MousePos.Y)*TranslateSpeed; 186 tvectY * (TranslateStart.Y - MousePos.Y)*TranslateSpeed;
187 OldTarget = translate; 187 OldTarget = translate;
188 Translating = false; 188 Translating = false;
189 } 189 }
190 190
191 // Rotation ------------------------------------ 191 // Rotation ------------------------------------
192 192
193 if (isMouseKeyDown(0) && !Zooming) 193 if (isMouseKeyDown(0) && !Zooming)
194 { 194 {
195 if (!Rotating) 195 if (!Rotating)
196 { 196 {
197 RotateStart = MousePos; 197 RotateStart = MousePos;
198 Rotating = true; 198 Rotating = true;
199 nRotX = RotX; 199 nRotX = RotX;
200 nRotY = RotY; 200 nRotY = RotY;
201 } 201 }
202 else 202 else
203 { 203 {
204 nRotX += (RotateStart.X - MousePos.X) * RotateSpeed; 204 nRotX += (RotateStart.X - MousePos.X) * RotateSpeed;
205 nRotY += (RotateStart.Y - MousePos.Y) * RotateSpeed; 205 nRotY += (RotateStart.Y - MousePos.Y) * RotateSpeed;
206 } 206 }
207 } 207 }
208 else if (Rotating) 208 else if (Rotating)
209 { 209 {
210 RotX += (RotateStart.X - MousePos.X) * RotateSpeed; 210 RotX += (RotateStart.X - MousePos.X) * RotateSpeed;
211 RotY += (RotateStart.Y - MousePos.Y) * RotateSpeed; 211 RotY += (RotateStart.Y - MousePos.Y) * RotateSpeed;
212 nRotX = RotX; 212 nRotX = RotX;
213 nRotY = RotY; 213 nRotY = RotY;
214 Rotating = false; 214 Rotating = false;
215 } 215 }
216 216
217 // Set pos ------------------------------------ 217 // Set pos ------------------------------------
218 218
219 pos = translate; 219 pos = translate;
220 pos.X += nZoom; 220 pos.X += nZoom;
221 221
222 pos.rotateXYBy(nRotY, translate); 222 pos.rotateXYBy(nRotY, translate);
223 pos.rotateXZBy(-nRotX, translate); 223 pos.rotateXZBy(-nRotX, translate);
224 224
225 camera->setPosition(pos); 225 camera->setPosition(pos);
226 camera->setTarget(translate); 226 camera->setTarget(translate);
227 227
228 // Rotation Error ---------------------------- 228 // Rotation Error ----------------------------
229 229
230 // jox: fixed bug: jitter when rotating to the top and bottom of y 230 // jox: fixed bug: jitter when rotating to the top and bottom of y
231 pos.set(0,1,0); 231 pos.set(0,1,0);
232 pos.rotateXYBy(-nRotY); 232 pos.rotateXYBy(-nRotY);
233 pos.rotateXZBy(-nRotX+180.f); 233 pos.rotateXZBy(-nRotX+180.f);
234 camera->setUpVector(pos); 234 camera->setUpVector(pos);
235 LastCameraTarget = camera->getTarget(); 235 LastCameraTarget = camera->getTarget();
236} 236}
237 237
238 238
239bool CSceneNodeAnimatorCameraMaya::isMouseKeyDown(s32 key) const 239bool CSceneNodeAnimatorCameraMaya::isMouseKeyDown(s32 key) const
240{ 240{
241 return MouseKeys[key]; 241 return MouseKeys[key];
242} 242}
243 243
244 244
245void CSceneNodeAnimatorCameraMaya::allKeysUp() 245void CSceneNodeAnimatorCameraMaya::allKeysUp()
246{ 246{
247 for (s32 i=0; i<3; ++i) 247 for (s32 i=0; i<3; ++i)
248 MouseKeys[i] = false; 248 MouseKeys[i] = false;
249} 249}
250 250
251 251
252//! Sets the rotation speed 252//! Sets the rotation speed
253void CSceneNodeAnimatorCameraMaya::setRotateSpeed(f32 speed) 253void CSceneNodeAnimatorCameraMaya::setRotateSpeed(f32 speed)
254{ 254{
255 RotateSpeed = speed; 255 RotateSpeed = speed;
256} 256}
257 257
258 258
259//! Sets the movement speed 259//! Sets the movement speed
260void CSceneNodeAnimatorCameraMaya::setMoveSpeed(f32 speed) 260void CSceneNodeAnimatorCameraMaya::setMoveSpeed(f32 speed)
261{ 261{
262 TranslateSpeed = speed; 262 TranslateSpeed = speed;
263} 263}
264 264
265 265
266//! Sets the zoom speed 266//! Sets the zoom speed
267void CSceneNodeAnimatorCameraMaya::setZoomSpeed(f32 speed) 267void CSceneNodeAnimatorCameraMaya::setZoomSpeed(f32 speed)
268{ 268{
269 ZoomSpeed = speed; 269 ZoomSpeed = speed;
270} 270}
271 271
272 272
273//! Set the distance 273//! Set the distance
274void CSceneNodeAnimatorCameraMaya::setDistance(f32 distance) 274void CSceneNodeAnimatorCameraMaya::setDistance(f32 distance)
275{ 275{
276 CurrentZoom=distance; 276 CurrentZoom=distance;
277} 277}
278 278
279 279
280//! Gets the rotation speed 280//! Gets the rotation speed
281f32 CSceneNodeAnimatorCameraMaya::getRotateSpeed() const 281f32 CSceneNodeAnimatorCameraMaya::getRotateSpeed() const
282{ 282{
283 return RotateSpeed; 283 return RotateSpeed;
284} 284}
285 285
286 286
287// Gets the movement speed 287// Gets the movement speed
288f32 CSceneNodeAnimatorCameraMaya::getMoveSpeed() const 288f32 CSceneNodeAnimatorCameraMaya::getMoveSpeed() const
289{ 289{
290 return TranslateSpeed; 290 return TranslateSpeed;
291} 291}
292 292
293 293
294//! Gets the zoom speed 294//! Gets the zoom speed
295f32 CSceneNodeAnimatorCameraMaya::getZoomSpeed() const 295f32 CSceneNodeAnimatorCameraMaya::getZoomSpeed() const
296{ 296{
297 return ZoomSpeed; 297 return ZoomSpeed;
298} 298}
299 299
300 300
301//! Returns the current distance, i.e. orbit radius 301//! Returns the current distance, i.e. orbit radius
302f32 CSceneNodeAnimatorCameraMaya::getDistance() const 302f32 CSceneNodeAnimatorCameraMaya::getDistance() const
303{ 303{
304 return CurrentZoom; 304 return CurrentZoom;
305} 305}
306 306
307 307
308ISceneNodeAnimator* CSceneNodeAnimatorCameraMaya::createClone(ISceneNode* node, ISceneManager* newManager) 308ISceneNodeAnimator* CSceneNodeAnimatorCameraMaya::createClone(ISceneNode* node, ISceneManager* newManager)
309{ 309{
310 CSceneNodeAnimatorCameraMaya * newAnimator = 310 CSceneNodeAnimatorCameraMaya * newAnimator =
311 new CSceneNodeAnimatorCameraMaya(CursorControl, RotateSpeed, ZoomSpeed, TranslateSpeed); 311 new CSceneNodeAnimatorCameraMaya(CursorControl, RotateSpeed, ZoomSpeed, TranslateSpeed);
312 return newAnimator; 312 return newAnimator;
313} 313}
314 314
315} // end namespace 315} // end namespace
316} // end namespace 316} // end namespace
317 317