diff options
author | David Walter Seikel | 2013-01-27 09:26:52 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-27 09:26:52 +1000 |
commit | 2624827ee680b0a721c408da690721b28e8f2427 (patch) | |
tree | 2e7958847b7ede1baba9f74cc8a58dea288a4cb8 /ClientHamr | |
parent | Delete a bunch of the keyboard handling stuff. (diff) | |
download | SledjHamr-2624827ee680b0a721c408da690721b28e8f2427.zip SledjHamr-2624827ee680b0a721c408da690721b28e8f2427.tar.gz SledjHamr-2624827ee680b0a721c408da690721b28e8f2427.tar.bz2 SledjHamr-2624827ee680b0a721c408da690721b28e8f2427.tar.xz |
Get the new camera actually working. Still some bugs to be ironed out.
Diffstat (limited to 'ClientHamr')
-rw-r--r-- | ClientHamr/extantz/CDemo.cpp | 13 | ||||
-rw-r--r-- | ClientHamr/extantz/CDemo.h | 2 | ||||
-rw-r--r-- | ClientHamr/extantz/crappisspuke.cpp | 2 | ||||
-rw-r--r-- | ClientHamr/extantz/extantz.c | 121 | ||||
-rw-r--r-- | ClientHamr/extantz/extantz.h | 12 | ||||
-rw-r--r-- | ClientHamr/extantz/extantzCamera.cpp | 115 | ||||
-rw-r--r-- | ClientHamr/extantz/extantzCamera.h | 48 |
7 files changed, 217 insertions, 96 deletions
diff --git a/ClientHamr/extantz/CDemo.cpp b/ClientHamr/extantz/CDemo.cpp index 7fc6ac1..b5cce65 100644 --- a/ClientHamr/extantz/CDemo.cpp +++ b/ClientHamr/extantz/CDemo.cpp | |||
@@ -10,7 +10,7 @@ | |||
10 | CDemo::CDemo(GLData *gld, bool a) | 10 | CDemo::CDemo(GLData *gld, bool a) |
11 | : additive(a), | 11 | : additive(a), |
12 | device(gld->device), | 12 | device(gld->device), |
13 | currentScene(0), | 13 | currentScene(2), |
14 | quakeLevelMesh(0), quakeLevelNode(0), skyboxNode(0), model1(0), model2(0), | 14 | quakeLevelMesh(0), quakeLevelNode(0), skyboxNode(0), model1(0), model2(0), |
15 | campFire(0), metaSelector(0), mapSelector(0), sceneStartTime(0), | 15 | campFire(0), metaSelector(0), mapSelector(0), sceneStartTime(0), |
16 | timeForThisScene(0) | 16 | timeForThisScene(0) |
@@ -53,7 +53,7 @@ void CDemo::setup(GLData *gld) | |||
53 | void CDemo::preDraw(GLData *gld, u32 now) | 53 | void CDemo::preDraw(GLData *gld, u32 now) |
54 | { | 54 | { |
55 | if (((now - sceneStartTime) > timeForThisScene) && (timeForThisScene != -1)) | 55 | if (((now - sceneStartTime) > timeForThisScene) && (timeForThisScene != -1)) |
56 | switchToNextScene(); | 56 | switchToNextScene(gld); |
57 | 57 | ||
58 | createParticleImpacts(); | 58 | createParticleImpacts(); |
59 | } | 59 | } |
@@ -80,7 +80,7 @@ bool CDemo::OnEvent(const SEvent& event) | |||
80 | } | 80 | } |
81 | 81 | ||
82 | 82 | ||
83 | void CDemo::switchToNextScene() | 83 | void CDemo::switchToNextScene(GLData *gld) |
84 | { | 84 | { |
85 | currentScene++; | 85 | currentScene++; |
86 | if (currentScene > 3) | 86 | if (currentScene > 3) |
@@ -191,12 +191,15 @@ void CDemo::switchToNextScene() | |||
191 | } | 191 | } |
192 | timeForThisScene = -1; | 192 | timeForThisScene = -1; |
193 | 193 | ||
194 | camera = addExtantzCamera(sm, 0, 100.0f, .4f, -1, false, 3.f, false, true); | 194 | gld->camera = addExtantzCamera(sm, 0, 100.0f, .4f, -1, false, 3.f, false, true); |
195 | camera = gld->camera; | ||
195 | camera->setPosition(core::vector3df(150, 170, -160)); | 196 | camera->setPosition(core::vector3df(150, 170, -160)); |
196 | camera->setFarValue(5000.0f); | 197 | camera->setFarValue(5000.0f); |
198 | gld->move = getCameraMove(gld->camera); | ||
197 | 199 | ||
198 | scene::ISceneNodeAnimatorCollisionResponse* collider = | 200 | scene::ISceneNodeAnimatorCollisionResponse* collider = |
199 | sm->createCollisionResponseAnimator(metaSelector, camera, core::vector3df(25, 100, 25), core::vector3df(0, quakeLevelMesh ? -10.f : 0.0f, 0), core::vector3df(0, 45, 0), 0.005f); | 201 | // sm->createCollisionResponseAnimator(metaSelector, camera, core::vector3df(25, 100, 25), core::vector3df(0, quakeLevelMesh ? -10.f : 0.0f, 0), core::vector3df(0, 45, 0), 0.005f); |
202 | sm->createCollisionResponseAnimator(metaSelector, camera, core::vector3df(25, 50, 25), core::vector3df(0, quakeLevelMesh ? -10.f : 0.0f, 0), core::vector3df(0, 45, 0), 0.005f); | ||
200 | camera->addAnimator(collider); | 203 | camera->addAnimator(collider); |
201 | collider->drop(); | 204 | collider->drop(); |
202 | } | 205 | } |
diff --git a/ClientHamr/extantz/CDemo.h b/ClientHamr/extantz/CDemo.h index 44ba346..035c01f 100644 --- a/ClientHamr/extantz/CDemo.h +++ b/ClientHamr/extantz/CDemo.h | |||
@@ -27,7 +27,7 @@ private: | |||
27 | 27 | ||
28 | void createLoadingScreen(); | 28 | void createLoadingScreen(); |
29 | void loadSceneData(); | 29 | void loadSceneData(); |
30 | void switchToNextScene(); | 30 | void switchToNextScene(GLData *gld); |
31 | void shoot(); | 31 | void shoot(); |
32 | void createParticleImpacts(); | 32 | void createParticleImpacts(); |
33 | 33 | ||
diff --git a/ClientHamr/extantz/crappisspuke.cpp b/ClientHamr/extantz/crappisspuke.cpp index 90cbbed..5bfb6e2 100644 --- a/ClientHamr/extantz/crappisspuke.cpp +++ b/ClientHamr/extantz/crappisspuke.cpp | |||
@@ -9,7 +9,7 @@ SExposedVideoData videoData; | |||
9 | 9 | ||
10 | IAnimatedMeshSceneNode *node; | 10 | IAnimatedMeshSceneNode *node; |
11 | CDemo *myDemo; | 11 | CDemo *myDemo; |
12 | // This is the movemen speed in units per second. | 12 | // This is the movement speed in units per second. |
13 | const f32 MOVEMENT_SPEED = 5.f; | 13 | const f32 MOVEMENT_SPEED = 5.f; |
14 | // In order to do framerate independent movement, we have to know | 14 | // In order to do framerate independent movement, we have to know |
15 | // how long it was since the last frame | 15 | // how long it was since the last frame |
diff --git a/ClientHamr/extantz/extantz.c b/ClientHamr/extantz/extantz.c index fb15019..46dc8a3 100644 --- a/ClientHamr/extantz/extantz.c +++ b/ClientHamr/extantz/extantz.c | |||
@@ -329,6 +329,107 @@ load_shader(GLData *gld, GLenum type, const char *shader_src) | |||
329 | return shader; | 329 | return shader; |
330 | } | 330 | } |
331 | 331 | ||
332 | static void _cb_mouse_down_GL(void *data, Evas *evas, Evas_Object *obj, void *event_info) | ||
333 | { | ||
334 | GLData *gld = data; | ||
335 | Evas_Event_Mouse_Down *ev = event_info; | ||
336 | |||
337 | if (1 == ev->button) | ||
338 | { | ||
339 | gld->camFocus = 1; | ||
340 | printf("Background GL object focused.\n"); | ||
341 | } | ||
342 | } | ||
343 | |||
344 | static void _cb_mouse_down_elm(void *data, Evas *evas, Evas_Object *obj, void *event_info) | ||
345 | { | ||
346 | GLData *gld = data; | ||
347 | Evas_Event_Mouse_Down *ev = event_info; | ||
348 | |||
349 | if (1 == ev->button) | ||
350 | { | ||
351 | gld->camFocus = 0; | ||
352 | // TODO - Yes we really DO need to figure out what was clicked on and set focus to it. sigh | ||
353 | // For now, we only got one window, focus on it's box. | ||
354 | elm_object_focus_set(gld->bx, EINA_TRUE); | ||
355 | printf("ELM object focused.\n"); | ||
356 | } | ||
357 | } | ||
358 | |||
359 | static Eina_Bool _on_camera_input(void *data, Evas_Object *obj, Evas_Object *src, Evas_Callback_Type type, void *event_info) | ||
360 | { | ||
361 | GLData *gld = data; | ||
362 | |||
363 | if (gld->camFocus) | ||
364 | { | ||
365 | if (gld->move) | ||
366 | { | ||
367 | // TODO - Careful, gld->move MIGHT be read at the other end by another thread. MIGHT, coz I really don't now at what point the camera animate routine is actually called. | ||
368 | Evas_Event_Key_Down *ev = event_info; | ||
369 | |||
370 | // Yes, we are dealing with the horrid Evas keyboard handling FUCKING STRING COMPARES! Soooo ... | ||
371 | // TODO - make this a hash lookup dammit. | ||
372 | // TODO - these are not working, coz Elm is grabbing the Left, Right, Up, and Down KEY_DOWNs. | ||
373 | if (EVAS_CALLBACK_KEY_DOWN == type) | ||
374 | { | ||
375 | if (0 == strcmp(ev->keyname, "Escape")) | ||
376 | { | ||
377 | } | ||
378 | else if (0 == strcmp(ev->key, "Left")) | ||
379 | gld->move->y = 1.0; | ||
380 | else if (0 == strcmp(ev->key, "Right")) | ||
381 | gld->move->y = -1.0; | ||
382 | else if (0 == strcmp(ev->key, "Up")) | ||
383 | gld->move->x = 1.0; | ||
384 | else if (0 == strcmp(ev->key, "Down")) | ||
385 | gld->move->x = -1.0; | ||
386 | else if (0 == strcmp(ev->key, "Prior")) | ||
387 | gld->move->x = 1.0; | ||
388 | else if (0 == strcmp(ev->key, "Next")) | ||
389 | gld->move->x = -1.0; | ||
390 | else if (0 == strcmp(ev->key, "Home")) | ||
391 | gld->move->y = 1.0; | ||
392 | else if (0 == strcmp(ev->key, "End")) | ||
393 | gld->move->y = -1.0; | ||
394 | else if (0 == strcmp(ev->key, "space")) | ||
395 | gld->move->jump = 1.0; | ||
396 | else | ||
397 | printf("Unexpected down keystroke - %s\n", ev->key); | ||
398 | } | ||
399 | else if (EVAS_CALLBACK_KEY_UP == type) | ||
400 | { | ||
401 | if (0 == strcmp(ev->keyname, "Escape")) | ||
402 | { | ||
403 | } | ||
404 | else if (0 == strcmp(ev->key, "Left")) | ||
405 | gld->move->y = 0.0; | ||
406 | else if (0 == strcmp(ev->key, "Right")) | ||
407 | gld->move->y = 0.0; | ||
408 | else if (0 == strcmp(ev->key, "Up")) | ||
409 | gld->move->x = 0.0; | ||
410 | else if (0 == strcmp(ev->key, "Down")) | ||
411 | gld->move->x = 0.0; | ||
412 | else if (0 == strcmp(ev->key, "Prior")) | ||
413 | gld->move->x = 0.0; | ||
414 | else if (0 == strcmp(ev->key, "Next")) | ||
415 | gld->move->x = 0.0; | ||
416 | else if (0 == strcmp(ev->key, "Home")) | ||
417 | gld->move->y = 0.0; | ||
418 | else if (0 == strcmp(ev->key, "End")) | ||
419 | gld->move->y = 0.0; | ||
420 | else if (0 == strcmp(ev->key, "space")) | ||
421 | gld->move->jump = 0.0; | ||
422 | else | ||
423 | printf("Unexpected up keystroke - %s\n", ev->key); | ||
424 | } | ||
425 | } | ||
426 | else | ||
427 | printf("Camera input not ready\n"); | ||
428 | } | ||
429 | |||
430 | return EINA_FALSE; // TRUE = event was processed here, don't propagate. FALSE = propagate event, not processed here. | ||
431 | } | ||
432 | |||
332 | static void _resize(GLData *gld) | 433 | static void _resize(GLData *gld) |
333 | { | 434 | { |
334 | Evas_GL_API *gl = gld->glapi; | 435 | Evas_GL_API *gl = gld->glapi; |
@@ -441,6 +542,7 @@ on_del(void *data, Evas *e, Evas_Object *obj, void *event_info) | |||
441 | if (!gld) return; | 542 | if (!gld) return; |
442 | Evas_GL_API *gl = gld->glapi; | 543 | Evas_GL_API *gl = gld->glapi; |
443 | 544 | ||
545 | elm_object_event_callback_del(gld->r1, _on_camera_input, gld); | ||
444 | ecore_animator_del(gld->animator); | 546 | ecore_animator_del(gld->animator); |
445 | 547 | ||
446 | if (gld->useEGL) | 548 | if (gld->useEGL) |
@@ -635,6 +737,11 @@ static void init_evas_gl(GLData *gld, int w, int h) | |||
635 | // ecore_animator_frametime_set(1.0); | 737 | // ecore_animator_frametime_set(1.0); |
636 | gld->animator = ecore_animator_add(doFrame, gld); // This animator will be called every frame tick, which defaults to 1/30 seconds. | 738 | gld->animator = ecore_animator_add(doFrame, gld); // This animator will be called every frame tick, which defaults to 1/30 seconds. |
637 | 739 | ||
740 | // In this code, we are making our own camera, so grab it's input when we are focused. | ||
741 | elm_object_event_callback_add(gld->win, _on_camera_input, gld); | ||
742 | evas_object_event_callback_add(gld->r1, EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_GL, gld); | ||
743 | gld->camFocus = 1; // Start with the GL camera focused. | ||
744 | |||
638 | return; | 745 | return; |
639 | } | 746 | } |
640 | 747 | ||
@@ -752,7 +859,8 @@ static void _grid_sel_cb(void *data, Evas_Object *obj, void *event_info) | |||
752 | // sprintf(buf, "dillo -f -g '%dx%d+%d+%d' %s &", w - (w / 5), h - 30, w / 5, y, thisGrid->splashPage); | 859 | // sprintf(buf, "dillo -f -g '%dx%d+%d+%d' %s &", w - (w / 5), h - 30, w / 5, y, thisGrid->splashPage); |
753 | sprintf(buf, "uzbl -g '%dx%d+%d+%d' -u %s &", w - (w / 5), h - 30, w / 5, y, thisGrid->splashPage); | 860 | sprintf(buf, "uzbl -g '%dx%d+%d+%d' -u %s &", w - (w / 5), h - 30, w / 5, y, thisGrid->splashPage); |
754 | printf("%s ### genlist obj [%p], item pointer [%p]\n", buf, obj, event_info); | 861 | printf("%s ### genlist obj [%p], item pointer [%p]\n", buf, obj, event_info); |
755 | system(buf); | 862 | // comment this out for now, busy dealing with input stuff, don't want to trigger this multiple times. |
863 | // system(buf); | ||
756 | } | 864 | } |
757 | 865 | ||
758 | static void | 866 | static void |
@@ -902,15 +1010,6 @@ fill(Evas_Object *win) | |||
902 | 1010 | ||
903 | evas_object_show(bx); | 1011 | evas_object_show(bx); |
904 | } | 1012 | } |
905 | |||
906 | static void | ||
907 | cb_mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info) | ||
908 | { | ||
909 | Evas_Event_Mouse_Down *ev = event_info; | ||
910 | |||
911 | if (ev->button == 1) elm_object_focus_set(obj, EINA_TRUE); | ||
912 | } | ||
913 | |||
914 | static void | 1013 | static void |
915 | cb_mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) | 1014 | cb_mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) |
916 | { | 1015 | { |
@@ -1043,7 +1142,7 @@ EAPI_MAIN int elm_main(int argc, char **argv) | |||
1043 | 1142 | ||
1044 | win3 = elm_win_add(gld->win, "inlined", ELM_WIN_INLINED_IMAGE); | 1143 | win3 = elm_win_add(gld->win, "inlined", ELM_WIN_INLINED_IMAGE); |
1045 | elm_win_title_set(win3, "world manager"); | 1144 | elm_win_title_set(win3, "world manager"); |
1046 | evas_object_event_callback_add(elm_win_inlined_image_object_get(win3), EVAS_CALLBACK_MOUSE_DOWN, cb_mouse_down, NULL); | 1145 | evas_object_event_callback_add(elm_win_inlined_image_object_get(win3), EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_elm, gld); |
1047 | elm_win_alpha_set(win3, EINA_TRUE); | 1146 | elm_win_alpha_set(win3, EINA_TRUE); |
1048 | fill(win3); | 1147 | fill(win3); |
1049 | // Odd, it needs to be resized twice? | 1148 | // Odd, it needs to be resized twice? |
diff --git a/ClientHamr/extantz/extantz.h b/ClientHamr/extantz/extantz.h index 5fec64c..4bce461 100644 --- a/ClientHamr/extantz/extantz.h +++ b/ClientHamr/extantz/extantz.h | |||
@@ -2,6 +2,7 @@ | |||
2 | #include <elm_widget_glview.h> | 2 | #include <elm_widget_glview.h> |
3 | #include <Evas_GL.h> | 3 | #include <Evas_GL.h> |
4 | #include <EPhysics.h> | 4 | #include <EPhysics.h> |
5 | #include "extantzCamera.h" | ||
5 | 6 | ||
6 | 7 | ||
7 | #ifdef GL_GLES | 8 | #ifdef GL_GLES |
@@ -44,6 +45,7 @@ extern "C"{ | |||
44 | typedef struct IrrlichtDevice IrrlichtDevice; | 45 | typedef struct IrrlichtDevice IrrlichtDevice; |
45 | typedef struct IVideoDriver IVideoDriver; | 46 | typedef struct IVideoDriver IVideoDriver; |
46 | typedef struct ISceneManager ISceneManager; | 47 | typedef struct ISceneManager ISceneManager; |
48 | typedef struct ICameraSceneNode ICameraSceneNode; | ||
47 | 49 | ||
48 | #endif | 50 | #endif |
49 | 51 | ||
@@ -143,13 +145,17 @@ struct _GLData | |||
143 | int useIrr : 1; | 145 | int useIrr : 1; |
144 | int doneIrr : 1; | 146 | int doneIrr : 1; |
145 | int resized : 1; | 147 | int resized : 1; |
148 | int camFocus : 1; | ||
146 | 149 | ||
147 | Evas_Object *bx, *r1; | 150 | Evas_Object *bx, *r1; |
148 | Ecore_Animator *animator; | 151 | Ecore_Animator *animator; |
149 | 152 | ||
150 | IrrlichtDevice *device; // IrrlichtDevice | 153 | IrrlichtDevice *device; |
151 | IVideoDriver *driver; // IVideoDriver | 154 | IVideoDriver *driver; |
152 | ISceneManager *smgr; // ISceneManager | 155 | ISceneManager *smgr; |
156 | ICameraSceneNode *camera; | ||
157 | |||
158 | cameraMove *move; | ||
153 | 159 | ||
154 | // Gear Stuff | 160 | // Gear Stuff |
155 | GLfloat view_rotx; | 161 | GLfloat view_rotx; |
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 |
diff --git a/ClientHamr/extantz/extantzCamera.h b/ClientHamr/extantz/extantzCamera.h index cfd4361..fe548d9 100644 --- a/ClientHamr/extantz/extantzCamera.h +++ b/ClientHamr/extantz/extantzCamera.h | |||
@@ -5,6 +5,8 @@ | |||
5 | #ifndef __EXTANTZ_CAMERA_H_INCLUDED__ | 5 | #ifndef __EXTANTZ_CAMERA_H_INCLUDED__ |
6 | #define __EXTANTZ_CAMERA_H_INCLUDED__ | 6 | #define __EXTANTZ_CAMERA_H_INCLUDED__ |
7 | 7 | ||
8 | |||
9 | #ifdef __cplusplus | ||
8 | #include <ISceneNodeAnimator.h> | 10 | #include <ISceneNodeAnimator.h> |
9 | #include <vector2d.h> | 11 | #include <vector2d.h> |
10 | #include <position2d.h> | 12 | #include <position2d.h> |
@@ -12,18 +14,38 @@ | |||
12 | #include <irrArray.h> | 14 | #include <irrArray.h> |
13 | #include <ICameraSceneNode.h> | 15 | #include <ICameraSceneNode.h> |
14 | 16 | ||
17 | using namespace irr; | ||
18 | using namespace scene; | ||
15 | 19 | ||
20 | extern "C"{ | ||
21 | #else | ||
22 | typedef struct extantzCamera extantzCamera; | ||
23 | typedef struct ICameraSceneNode ICameraSceneNode; | ||
24 | #endif | ||
16 | 25 | ||
17 | namespace irr | 26 | typedef struct |
18 | { | 27 | { |
19 | namespace gui | 28 | float x, y, z; |
20 | { | 29 | float r, s, t; |
21 | class ICursorControl; | 30 | float jump; |
31 | } cameraMove; | ||
32 | |||
33 | cameraMove *getCameraMove(ICameraSceneNode *camera); | ||
34 | |||
35 | #ifdef __cplusplus | ||
22 | } | 36 | } |
23 | 37 | ||
38 | |||
39 | //namespace irr::gui | ||
40 | //{ | ||
41 | // class ICursorControl; | ||
42 | //} | ||
43 | |||
44 | |||
45 | namespace irr | ||
46 | { | ||
24 | namespace scene | 47 | namespace scene |
25 | { | 48 | { |
26 | |||
27 | ICameraSceneNode *addExtantzCamera(ISceneManager* sm, ISceneNode* parent, f32 rotateSpeed, f32 moveSpeed, s32 id, bool noVerticalMovement, f32 jumpSpeed, bool invertMouseY, bool makeActive); | 49 | ICameraSceneNode *addExtantzCamera(ISceneManager* sm, ISceneNode* parent, f32 rotateSpeed, f32 moveSpeed, s32 id, bool noVerticalMovement, f32 jumpSpeed, bool invertMouseY, bool makeActive); |
28 | 50 | ||
29 | class extantzCamera : public ISceneNodeAnimator | 51 | class extantzCamera : public ISceneNodeAnimator |
@@ -31,7 +53,8 @@ namespace scene | |||
31 | public: | 53 | public: |
32 | 54 | ||
33 | //! Constructor | 55 | //! Constructor |
34 | extantzCamera(gui::ICursorControl* cursorControl, f32 rotateSpeed = 100.0f, f32 moveSpeed = .5f, f32 jumpSpeed=0.f, bool noVerticalMovement=false, bool invertY=false); | 56 | // extantzCamera(gui::ICursorControl* cursorControl, f32 rotateSpeed = 100.0f, f32 moveSpeed = .5f, f32 jumpSpeed=0.f, bool noVerticalMovement=false, bool invertY=false); |
57 | extantzCamera(f32 rotateSpeed = 100.0f, f32 moveSpeed = .5f, f32 jumpSpeed=0.f, bool noVerticalMovement=false, bool invertY=false); | ||
35 | 58 | ||
36 | //! Destructor | 59 | //! Destructor |
37 | virtual ~extantzCamera(); | 60 | virtual ~extantzCamera(); |
@@ -77,11 +100,9 @@ namespace scene | |||
77 | done with it. */ | 100 | done with it. */ |
78 | virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0); | 101 | virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0); |
79 | 102 | ||
80 | private: | 103 | cameraMove move; |
81 | void allKeysUp(); | ||
82 | |||
83 | gui::ICursorControl *CursorControl; | ||
84 | 104 | ||
105 | private: | ||
85 | f32 MaxVerticalAngle; | 106 | f32 MaxVerticalAngle; |
86 | 107 | ||
87 | f32 MoveSpeed; | 108 | f32 MoveSpeed; |
@@ -94,14 +115,13 @@ namespace scene | |||
94 | 115 | ||
95 | core::position2d<f32> CenterCursor, CursorPos; | 116 | core::position2d<f32> CenterCursor, CursorPos; |
96 | 117 | ||
97 | bool CursorKeys[EKA_COUNT]; | ||
98 | |||
99 | bool firstUpdate; | 118 | bool firstUpdate; |
100 | bool NoVerticalMovement; | 119 | bool NoVerticalMovement; |
101 | }; | 120 | }; |
121 | }; | ||
122 | }; | ||
123 | #endif | ||
102 | 124 | ||
103 | } // end namespace scene | ||
104 | } // end namespace irr | ||
105 | 125 | ||
106 | #endif // __EXTANTZ_CAMERA_H_INCLUDED__ | 126 | #endif // __EXTANTZ_CAMERA_H_INCLUDED__ |
107 | 127 | ||