aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ClientHamr
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-27 11:18:26 +1000
committerDavid Walter Seikel2013-01-27 11:18:26 +1000
commit37be70434d2d1ddd6d691863740d64ddbf0b2921 (patch)
treea1081a593ad8e4ca09440f2ddba08506b8a28627 /ClientHamr
parentClean up the rest of the object files. (diff)
downloadSledjHamr-37be70434d2d1ddd6d691863740d64ddbf0b2921.zip
SledjHamr-37be70434d2d1ddd6d691863740d64ddbf0b2921.tar.gz
SledjHamr-37be70434d2d1ddd6d691863740d64ddbf0b2921.tar.bz2
SledjHamr-37be70434d2d1ddd6d691863740d64ddbf0b2921.tar.xz
Move a bunch of stuff into the new cameraMove structure, and some clean ups.
Diffstat (limited to 'ClientHamr')
-rw-r--r--ClientHamr/extantz/CDemo.cpp2
-rw-r--r--ClientHamr/extantz/extantzCamera.cpp88
-rw-r--r--ClientHamr/extantz/extantzCamera.h44
3 files changed, 32 insertions, 102 deletions
diff --git a/ClientHamr/extantz/CDemo.cpp b/ClientHamr/extantz/CDemo.cpp
index 72e23e5..642adc3 100644
--- a/ClientHamr/extantz/CDemo.cpp
+++ b/ClientHamr/extantz/CDemo.cpp
@@ -191,7 +191,7 @@ void CDemo::switchToNextScene(GLData *gld)
191 } 191 }
192 timeForThisScene = -1; 192 timeForThisScene = -1;
193 193
194 gld->camera = addExtantzCamera(sm, 0, 100.0f, .4f, -1, false, 3.f, false, true); 194 gld->camera = addExtantzCamera(sm, NULL, -1);
195 camera = gld->camera; 195 camera = gld->camera;
196 camera->setPosition(core::vector3df(108, 140, -140)); 196 camera->setPosition(core::vector3df(108, 140, -140));
197 camera->setFarValue(5000.0f); 197 camera->setFarValue(5000.0f);
diff --git a/ClientHamr/extantz/extantzCamera.cpp b/ClientHamr/extantz/extantzCamera.cpp
index cafc80b..f4554be 100644
--- a/ClientHamr/extantz/extantzCamera.cpp
+++ b/ClientHamr/extantz/extantzCamera.cpp
@@ -27,13 +27,13 @@ namespace scene
27 27
28// Irrlicht hard codes a reference to the original FPS camera code inside it's scene manager. This is that code extracted so we can be more flexible. 28// Irrlicht hard codes a reference to the original FPS camera code inside it's scene manager. This is that code extracted so we can be more flexible.
29// TODO - Hmmm, Where's CursorControl come from? Ah, passed to the scene manager constructor, it's a GUI thing that we need to replace with an EFL thing. 29// TODO - Hmmm, Where's CursorControl come from? Ah, passed to the scene manager constructor, it's a GUI thing that we need to replace with an EFL thing.
30ICameraSceneNode *addExtantzCamera(ISceneManager* sm, ISceneNode* parent, f32 rotateSpeed, f32 moveSpeed, s32 id, bool noVerticalMovement, f32 jumpSpeed, bool invertMouseY, bool makeActive) 30ICameraSceneNode *addExtantzCamera(ISceneManager* sm, ISceneNode* parent, s32 id)
31{ 31{
32 ICameraSceneNode* node = sm->addCameraSceneNode(parent, core::vector3df(), core::vector3df(0, 0, 100), id, makeActive); 32 ICameraSceneNode* node = sm->addCameraSceneNode(parent, core::vector3df(), core::vector3df(0, 0, 100), id, true);
33 if (node) 33 if (node)
34 { 34 {
35// ISceneNodeAnimator* anm = new extantzCamera(CursorControl, rotateSpeed, moveSpeed, jumpSpeed, noVerticalMovement, invertMouseY); 35// ISceneNodeAnimator* anm = new extantzCamera(CursorControl);
36 ISceneNodeAnimator* anm = new extantzCamera(rotateSpeed, moveSpeed, jumpSpeed, noVerticalMovement, invertMouseY); 36 ISceneNodeAnimator* anm = new extantzCamera();
37 37
38 // Bind the node's rotation to its target. This is consistent with 1.4.2 and below. 38 // Bind the node's rotation to its target. This is consistent with 1.4.2 and below.
39 node->bindTargetAndRotation(true); 39 node->bindTargetAndRotation(true);
@@ -46,16 +46,19 @@ ICameraSceneNode *addExtantzCamera(ISceneManager* sm, ISceneNode* parent, f32 ro
46 46
47 47
48//! constructor 48//! constructor
49//extantzCamera::extantzCamera(gui::ICursorControl* cursorControl, f32 rotateSpeed, f32 moveSpeed, f32 jumpSpeed, bool noVerticalMovement, bool invertY) 49//extantzCamera::extantzCamera(gui::ICursorControl* cursorControl)
50// : CursorControl(cursorControl), MaxVerticalAngle(88.0f), MoveSpeed(moveSpeed), RotateSpeed(rotateSpeed), JumpSpeed(jumpSpeed), 50// : CursorControl(cursorControl), MaxVerticalAngle(88.0f), MoveSpeed(0.4f), RotateSpeed(100.0f), JumpSpeed(3.0f),
51extantzCamera::extantzCamera(f32 rotateSpeed, f32 moveSpeed, f32 jumpSpeed, bool noVerticalMovement, bool invertY) 51extantzCamera::extantzCamera()
52 : MaxVerticalAngle(88.0f), MoveSpeed(moveSpeed), RotateSpeed(rotateSpeed), JumpSpeed(jumpSpeed), 52 : MaxVerticalAngle(88.0f), MouseYDirection(1.0f), LastAnimationTime(0), NoVerticalMovement(false)
53 MouseYDirection(invertY ? -1.0f : 1.0f), LastAnimationTime(0), firstUpdate(true), NoVerticalMovement(noVerticalMovement)
54{ 53{
55 #ifdef _DEBUG 54 #ifdef _DEBUG
56 setDebugName("extantzCamera"); 55 setDebugName("extantzCamera");
57 #endif 56 #endif
58 57
58 move.MoveSpeed = 0.1f;
59 move.RotateSpeed = 1.0f;
60 move.JumpSpeed = 3.0f;
61
59// if (CursorControl) 62// if (CursorControl)
60// CursorControl->grab(); 63// CursorControl->grab();
61} 64}
@@ -87,7 +90,7 @@ void extantzCamera::animateNode(ISceneNode* node, u32 timeMs)
87 90
88 ICameraSceneNode* camera = static_cast<ICameraSceneNode*>(node); 91 ICameraSceneNode* camera = static_cast<ICameraSceneNode*>(node);
89 92
90 if (firstUpdate) 93 if (0 == LastAnimationTime)
91 { 94 {
92 camera->updateAbsolutePosition(); 95 camera->updateAbsolutePosition();
93// if (CursorControl ) 96// if (CursorControl )
@@ -97,11 +100,10 @@ void extantzCamera::animateNode(ISceneNode* node, u32 timeMs)
97// } 100// }
98 101
99 LastAnimationTime = timeMs; 102 LastAnimationTime = timeMs;
100
101 firstUpdate = false;
102 } 103 }
103 104
104 // 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 // TODO - it never is, coz we are bypassing that, but can we replace this with something else?
105 if(!camera->isInputReceiverEnabled()) 107 if(!camera->isInputReceiverEnabled())
106 { 108 {
107// return; 109// return;
@@ -112,7 +114,7 @@ void extantzCamera::animateNode(ISceneNode* node, u32 timeMs)
112 return; 114 return;
113 115
114 // get time 116 // get time
115 f32 timeDiff = (f32) ( timeMs - LastAnimationTime ); 117 f32 timeDiff = (f32) (timeMs - LastAnimationTime);
116 LastAnimationTime = timeMs; 118 LastAnimationTime = timeMs;
117 119
118 // update position 120 // update position
@@ -127,8 +129,8 @@ void extantzCamera::animateNode(ISceneNode* node, u32 timeMs)
127 { 129 {
128 if (CursorPos != CenterCursor) 130 if (CursorPos != CenterCursor)
129 { 131 {
130 relativeRotation.Y -= (0.5f - CursorPos.X) * RotateSpeed; 132 relativeRotation.Y -= (0.5f - CursorPos.X) * move.RotateSpeed;
131 relativeRotation.X -= (0.5f - CursorPos.Y) * RotateSpeed * MouseYDirection; 133 relativeRotation.X -= (0.5f - CursorPos.Y) * move.RotateSpeed * MouseYDirection;
132 134
133 // X < MaxVerticalAngle or X > 360-MaxVerticalAngle 135 // X < MaxVerticalAngle or X > 360-MaxVerticalAngle
134 136
@@ -192,8 +194,7 @@ void extantzCamera::animateNode(ISceneNode* node, u32 timeMs)
192 194
193 movedir.normalize(); 195 movedir.normalize();
194 196
195 // TODO - There is no turning left or right, flying, or the other things I'll need. So might as well create my own thing to replace the original FPS camera. 197 pos += movedir * timeDiff * move.MoveSpeed * move.x;
196 pos += movedir * timeDiff * MoveSpeed * move.x;
197 198
198 // strafing 199 // strafing
199 core::vector3df strafevect = target; 200 core::vector3df strafevect = target;
@@ -204,7 +205,7 @@ void extantzCamera::animateNode(ISceneNode* node, u32 timeMs)
204 205
205 strafevect.normalize(); 206 strafevect.normalize();
206 207
207 pos += strafevect * timeDiff * MoveSpeed * move.y; 208 pos += strafevect * timeDiff * move.MoveSpeed * move.y;
208 209
209 // For jumping, we find the collision response animator attached to our camera 210 // For jumping, we find the collision response animator attached to our camera
210 // and if it's not falling, we tell it to jump. 211 // and if it's not falling, we tell it to jump.
@@ -220,7 +221,7 @@ void extantzCamera::animateNode(ISceneNode* node, u32 timeMs)
220 static_cast<ISceneNodeAnimatorCollisionResponse *>(*it); 221 static_cast<ISceneNodeAnimatorCollisionResponse *>(*it);
221 222
222 if(!collisionResponse->isFalling()) 223 if(!collisionResponse->isFalling())
223 collisionResponse->jump(JumpSpeed); 224 collisionResponse->jump(move.JumpSpeed);
224 } 225 }
225 226
226 it++; 227 it++;
@@ -236,55 +237,10 @@ void extantzCamera::animateNode(ISceneNode* node, u32 timeMs)
236} 237}
237 238
238 239
239//! Sets the rotation speed
240void extantzCamera::setRotateSpeed(f32 speed)
241{
242 RotateSpeed = speed;
243}
244
245
246//! Sets the movement speed
247void extantzCamera::setMoveSpeed(f32 speed)
248{
249 MoveSpeed = speed;
250}
251
252
253//! Gets the rotation speed
254f32 extantzCamera::getRotateSpeed() const
255{
256 return RotateSpeed;
257}
258
259
260// Gets the movement speed
261f32 extantzCamera::getMoveSpeed() const
262{
263 return MoveSpeed;
264}
265
266
267//! Sets whether vertical movement should be allowed.
268void extantzCamera::setVerticalMovement(bool allow)
269{
270 NoVerticalMovement = !allow;
271}
272
273
274//! Sets whether the Y axis of the mouse should be inverted.
275void extantzCamera::setInvertMouse(bool invert)
276{
277 if (invert)
278 MouseYDirection = -1.0f;
279 else
280 MouseYDirection = 1.0f;
281}
282
283
284ISceneNodeAnimator* extantzCamera::createClone(ISceneNode* node, ISceneManager* newManager) 240ISceneNodeAnimator* extantzCamera::createClone(ISceneNode* node, ISceneManager* newManager)
285{ 241{
286// extantzCamera *newAnimator = new extantzCamera(CursorControl, RotateSpeed, MoveSpeed, JumpSpeed, NoVerticalMovement); 242// extantzCamera *newAnimator = new extantzCamera(CursorControl);
287 extantzCamera *newAnimator = new extantzCamera(RotateSpeed, MoveSpeed, JumpSpeed, NoVerticalMovement); 243 extantzCamera *newAnimator = new extantzCamera();
288 return newAnimator; 244 return newAnimator;
289} 245}
290 246
diff --git a/ClientHamr/extantz/extantzCamera.h b/ClientHamr/extantz/extantzCamera.h
index fe548d9..9d74236 100644
--- a/ClientHamr/extantz/extantzCamera.h
+++ b/ClientHamr/extantz/extantzCamera.h
@@ -28,6 +28,7 @@ typedef struct
28 float x, y, z; 28 float x, y, z;
29 float r, s, t; 29 float r, s, t;
30 float jump; 30 float jump;
31 float JumpSpeed, RotateSpeed, MoveSpeed;
31} cameraMove; 32} cameraMove;
32 33
33cameraMove *getCameraMove(ICameraSceneNode *camera); 34cameraMove *getCameraMove(ICameraSceneNode *camera);
@@ -46,15 +47,15 @@ namespace irr
46{ 47{
47namespace scene 48namespace scene
48{ 49{
49 ICameraSceneNode *addExtantzCamera(ISceneManager* sm, ISceneNode* parent, f32 rotateSpeed, f32 moveSpeed, s32 id, bool noVerticalMovement, f32 jumpSpeed, bool invertMouseY, bool makeActive); 50 ICameraSceneNode *addExtantzCamera(ISceneManager* sm, ISceneNode* parent, s32 id);
50 51
51 class extantzCamera : public ISceneNodeAnimator 52 class extantzCamera : public ISceneNodeAnimator
52 { 53 {
53 public: 54 public:
54 55
55 //! Constructor 56 //! Constructor
56// extantzCamera(gui::ICursorControl* cursorControl, f32 rotateSpeed = 100.0f, f32 moveSpeed = .5f, f32 jumpSpeed=0.f, bool noVerticalMovement=false, bool invertY=false); 57// extantzCamera(gui::ICursorControl* cursorControl);
57 extantzCamera(f32 rotateSpeed = 100.0f, f32 moveSpeed = .5f, f32 jumpSpeed=0.f, bool noVerticalMovement=false, bool invertY=false); 58 extantzCamera();
58 59
59 //! Destructor 60 //! Destructor
60 virtual ~extantzCamera(); 61 virtual ~extantzCamera();
@@ -62,26 +63,6 @@ namespace scene
62 //! Animates the scene node, currently only works on cameras 63 //! Animates the scene node, currently only works on cameras
63 virtual void animateNode(ISceneNode* node, u32 timeMs); 64 virtual void animateNode(ISceneNode* node, u32 timeMs);
64 65
65 //! Returns the speed of movement in units per second
66 virtual f32 getMoveSpeed() const;
67
68 //! Sets the speed of movement in units per second
69 virtual void setMoveSpeed(f32 moveSpeed);
70
71 //! Returns the rotation speed
72 virtual f32 getRotateSpeed() const;
73
74 //! Set the rotation speed
75 virtual void setRotateSpeed(f32 rotateSpeed);
76
77 //! Sets whether vertical movement should be allowed.
78 virtual void setVerticalMovement(bool allow);
79
80 //! Sets whether the Y axis of the mouse should be inverted.
81 /** If enabled then moving the mouse down will cause
82 the camera to look up. It is disabled by default. */
83 virtual void setInvertMouse(bool invert);
84
85 //! This animator will receive events when attached to the active camera 66 //! This animator will receive events when attached to the active camera
86 virtual bool isEventReceiverEnabled() const 67 virtual bool isEventReceiverEnabled() const
87 { 68 {
@@ -100,23 +81,16 @@ namespace scene
100 done with it. */ 81 done with it. */
101 virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0); 82 virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0);
102 83
84 bool NoVerticalMovement;
85 // -1.0f for inverted mouse, defaults to 1.0f
86 f32 MouseYDirection;
87
103 cameraMove move; 88 cameraMove move;
104 89
105 private: 90 private:
106 f32 MaxVerticalAngle; 91 f32 MaxVerticalAngle;
107
108 f32 MoveSpeed;
109 f32 RotateSpeed;
110 f32 JumpSpeed;
111 // -1.0f for inverted mouse, defaults to 1.0f
112 f32 MouseYDirection;
113
114 s32 LastAnimationTime; 92 s32 LastAnimationTime;
115 93// core::position2d<f32> CenterCursor, CursorPos;
116 core::position2d<f32> CenterCursor, CursorPos;
117
118 bool firstUpdate;
119 bool NoVerticalMovement;
120 }; 94 };
121}; 95};
122}; 96};