diff options
Diffstat (limited to '')
-rw-r--r-- | ClientHamr/extantz/extantzCamera.cpp | 115 |
1 files changed, 54 insertions, 61 deletions
diff --git a/ClientHamr/extantz/extantzCamera.cpp b/ClientHamr/extantz/extantzCamera.cpp index cab1faa..cafc80b 100644 --- a/ClientHamr/extantz/extantzCamera.cpp +++ b/ClientHamr/extantz/extantzCamera.cpp | |||
@@ -33,7 +33,7 @@ ICameraSceneNode *addExtantzCamera(ISceneManager* sm, ISceneNode* parent, f32 ro | |||
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, rotateSpeed, moveSpeed, jumpSpeed, noVerticalMovement, invertMouseY); |
36 | ISceneNodeAnimator* anm = new extantzCamera(NULL, rotateSpeed, moveSpeed, jumpSpeed, noVerticalMovement, invertMouseY); | 36 | ISceneNodeAnimator* anm = new extantzCamera(rotateSpeed, moveSpeed, jumpSpeed, noVerticalMovement, invertMouseY); |
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,8 +46,10 @@ 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, f32 rotateSpeed, f32 moveSpeed, f32 jumpSpeed, bool noVerticalMovement, bool invertY) |
50 | : CursorControl(cursorControl), MaxVerticalAngle(88.0f), MoveSpeed(moveSpeed), RotateSpeed(rotateSpeed), JumpSpeed(jumpSpeed), | 50 | // : CursorControl(cursorControl), MaxVerticalAngle(88.0f), MoveSpeed(moveSpeed), RotateSpeed(rotateSpeed), JumpSpeed(jumpSpeed), |
51 | extantzCamera::extantzCamera(f32 rotateSpeed, f32 moveSpeed, f32 jumpSpeed, bool noVerticalMovement, bool invertY) | ||
52 | : MaxVerticalAngle(88.0f), MoveSpeed(moveSpeed), RotateSpeed(rotateSpeed), JumpSpeed(jumpSpeed), | ||
51 | MouseYDirection(invertY ? -1.0f : 1.0f), LastAnimationTime(0), firstUpdate(true), NoVerticalMovement(noVerticalMovement) | 53 | MouseYDirection(invertY ? -1.0f : 1.0f), LastAnimationTime(0), firstUpdate(true), NoVerticalMovement(noVerticalMovement) |
52 | { | 54 | { |
53 | #ifdef _DEBUG | 55 | #ifdef _DEBUG |
@@ -56,8 +58,6 @@ extantzCamera::extantzCamera(gui::ICursorControl* cursorControl, f32 rotateSpeed | |||
56 | 58 | ||
57 | // if (CursorControl) | 59 | // if (CursorControl) |
58 | // CursorControl->grab(); | 60 | // CursorControl->grab(); |
59 | |||
60 | allKeysUp(); | ||
61 | } | 61 | } |
62 | 62 | ||
63 | 63 | ||
@@ -69,39 +69,16 @@ extantzCamera::~extantzCamera() | |||
69 | } | 69 | } |
70 | 70 | ||
71 | 71 | ||
72 | #if 0 | 72 | /* Have a moveRotate array of floats. |
73 | // TODO - get rid of this, it's an Irrlicht callback, and I'm replacing it all with EFL. | 73 | * X, Y, Z, and whatever the usual letters are for rotations. lol |
74 | // Leaving it here for the moment as an example. | 74 | * Each one means "move or rotate this much in this direction". |
75 | bool extantzCamera::OnEvent(const SEvent& evt) | 75 | * Where 1.0 means "what ever the standard move is if that key is held down". |
76 | { | 76 | * So a keyboard move would just change it's part to 1.0 or -1.0 on key down, |
77 | switch(evt.EventType) | 77 | * and back to 0.0 on key up. Or 2.0 / -2.0 if in run mode. |
78 | { | 78 | * Which would even work in fly mode. |
79 | case EET_KEY_INPUT_EVENT: | 79 | * A joystick could be set to range over -2.0 to 2.0, and just set it's part directly. |
80 | for (u32 i=0; i<KeyMap.size(); ++i) | 80 | * A mouse look rotate, well will come to that when we need to. B-) |
81 | { | 81 | */ |
82 | if (KeyMap[i].KeyCode == evt.KeyInput.Key) | ||
83 | { | ||
84 | CursorKeys[KeyMap[i].Action] = evt.KeyInput.PressedDown; | ||
85 | return true; | ||
86 | } | ||
87 | } | ||
88 | break; | ||
89 | |||
90 | case EET_MOUSE_INPUT_EVENT: | ||
91 | if (evt.MouseInput.Event == EMIE_MOUSE_MOVED) | ||
92 | { | ||
93 | // CursorPos = CursorControl->getRelativePosition(); | ||
94 | return true; | ||
95 | } | ||
96 | break; | ||
97 | |||
98 | default: | ||
99 | break; | ||
100 | } | ||
101 | |||
102 | return false; | ||
103 | } | ||
104 | #endif | ||
105 | 82 | ||
106 | void extantzCamera::animateNode(ISceneNode* node, u32 timeMs) | 83 | void extantzCamera::animateNode(ISceneNode* node, u32 timeMs) |
107 | { | 84 | { |
@@ -127,8 +104,7 @@ void extantzCamera::animateNode(ISceneNode* node, u32 timeMs) | |||
127 | // If the camera isn't the active camera, and receiving input, then don't process it. | 104 | // If the camera isn't the active camera, and receiving input, then don't process it. |
128 | if(!camera->isInputReceiverEnabled()) | 105 | if(!camera->isInputReceiverEnabled()) |
129 | { | 106 | { |
130 | allKeysUp(); | 107 | // return; |
131 | return; | ||
132 | } | 108 | } |
133 | 109 | ||
134 | scene::ISceneManager * smgr = camera->getSceneManager(); | 110 | scene::ISceneManager * smgr = camera->getSceneManager(); |
@@ -216,15 +192,10 @@ void extantzCamera::animateNode(ISceneNode* node, u32 timeMs) | |||
216 | 192 | ||
217 | movedir.normalize(); | 193 | movedir.normalize(); |
218 | 194 | ||
219 | // TODO - There is no turning left or right, or the other things I'll need. So might as well create my own thing to replace this. | 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. |
220 | if (CursorKeys[EKA_MOVE_FORWARD]) | 196 | pos += movedir * timeDiff * MoveSpeed * move.x; |
221 | pos += movedir * timeDiff * MoveSpeed; | ||
222 | |||
223 | if (CursorKeys[EKA_MOVE_BACKWARD]) | ||
224 | pos -= movedir * timeDiff * MoveSpeed; | ||
225 | 197 | ||
226 | // strafing | 198 | // strafing |
227 | |||
228 | core::vector3df strafevect = target; | 199 | core::vector3df strafevect = target; |
229 | strafevect = strafevect.crossProduct(camera->getUpVector()); | 200 | strafevect = strafevect.crossProduct(camera->getUpVector()); |
230 | 201 | ||
@@ -233,15 +204,11 @@ void extantzCamera::animateNode(ISceneNode* node, u32 timeMs) | |||
233 | 204 | ||
234 | strafevect.normalize(); | 205 | strafevect.normalize(); |
235 | 206 | ||
236 | if (CursorKeys[EKA_STRAFE_LEFT]) | 207 | pos += strafevect * timeDiff * MoveSpeed * move.y; |
237 | pos += strafevect * timeDiff * MoveSpeed; | ||
238 | |||
239 | if (CursorKeys[EKA_STRAFE_RIGHT]) | ||
240 | pos -= strafevect * timeDiff * MoveSpeed; | ||
241 | 208 | ||
242 | // For jumping, we find the collision response animator attached to our camera | 209 | // For jumping, we find the collision response animator attached to our camera |
243 | // and if it's not falling, we tell it to jump. | 210 | // and if it's not falling, we tell it to jump. |
244 | if (CursorKeys[EKA_JUMP_UP]) | 211 | if (0.0 < move.jump) |
245 | { | 212 | { |
246 | const ISceneNodeAnimatorList& animators = camera->getAnimators(); | 213 | const ISceneNodeAnimatorList& animators = camera->getAnimators(); |
247 | ISceneNodeAnimatorList::ConstIterator it = animators.begin(); | 214 | ISceneNodeAnimatorList::ConstIterator it = animators.begin(); |
@@ -269,13 +236,6 @@ void extantzCamera::animateNode(ISceneNode* node, u32 timeMs) | |||
269 | } | 236 | } |
270 | 237 | ||
271 | 238 | ||
272 | void extantzCamera::allKeysUp() | ||
273 | { | ||
274 | for (u32 i=0; i<EKA_COUNT; ++i) | ||
275 | CursorKeys[i] = false; | ||
276 | } | ||
277 | |||
278 | |||
279 | //! Sets the rotation speed | 239 | //! Sets the rotation speed |
280 | void extantzCamera::setRotateSpeed(f32 speed) | 240 | void extantzCamera::setRotateSpeed(f32 speed) |
281 | { | 241 | { |
@@ -323,10 +283,43 @@ void extantzCamera::setInvertMouse(bool invert) | |||
323 | 283 | ||
324 | ISceneNodeAnimator* extantzCamera::createClone(ISceneNode* node, ISceneManager* newManager) | 284 | ISceneNodeAnimator* extantzCamera::createClone(ISceneNode* node, ISceneManager* newManager) |
325 | { | 285 | { |
326 | extantzCamera *newAnimator = new extantzCamera(CursorControl, RotateSpeed, MoveSpeed, JumpSpeed, NoVerticalMovement); | 286 | // extantzCamera *newAnimator = new extantzCamera(CursorControl, RotateSpeed, MoveSpeed, JumpSpeed, NoVerticalMovement); |
287 | extantzCamera *newAnimator = new extantzCamera(RotateSpeed, MoveSpeed, JumpSpeed, NoVerticalMovement); | ||
327 | return newAnimator; | 288 | return newAnimator; |
328 | } | 289 | } |
329 | 290 | ||
291 | #ifdef __cplusplus | ||
292 | extern "C" { | ||
293 | #endif | ||
294 | |||
295 | cameraMove *getCameraMove(ICameraSceneNode *camera) | ||
296 | { | ||
297 | cameraMove *cm = NULL; | ||
298 | |||
299 | if (camera) | ||
300 | { | ||
301 | const ISceneNodeAnimatorList &animators = camera->getAnimators(); | ||
302 | ISceneNodeAnimatorList::ConstIterator it = animators.begin(); | ||
303 | while(it != animators.end()) | ||
304 | { | ||
305 | // TODO - We assume FPS == extantzCamera, coz Irrlicht hard codes the camera types in an enum, which is a pain to add to from outside. | ||
306 | if(ESNAT_CAMERA_FPS == (*it)->getType()) | ||
307 | { | ||
308 | extantzCamera *ec = static_cast<extantzCamera *>(*it); | ||
309 | |||
310 | cm = &(ec->move); | ||
311 | } | ||
312 | |||
313 | it++; | ||
314 | } | ||
315 | } | ||
316 | return cm; | ||
317 | } | ||
318 | |||
319 | #ifdef __cplusplus | ||
320 | } | ||
321 | #endif | ||
322 | |||
330 | 323 | ||
331 | } // namespace scene | 324 | } // namespace scene |
332 | } // namespace irr | 325 | } // namespace irr |