From 2624827ee680b0a721c408da690721b28e8f2427 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 27 Jan 2013 09:26:52 +1000 Subject: Get the new camera actually working. Still some bugs to be ironed out. --- ClientHamr/extantz/CDemo.cpp | 13 ++-- ClientHamr/extantz/CDemo.h | 2 +- ClientHamr/extantz/crappisspuke.cpp | 2 +- ClientHamr/extantz/extantz.c | 121 +++++++++++++++++++++++++++++++---- ClientHamr/extantz/extantz.h | 12 +++- ClientHamr/extantz/extantzCamera.cpp | 115 ++++++++++++++++----------------- 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 @@ CDemo::CDemo(GLData *gld, bool a) : additive(a), device(gld->device), - currentScene(0), + currentScene(2), quakeLevelMesh(0), quakeLevelNode(0), skyboxNode(0), model1(0), model2(0), campFire(0), metaSelector(0), mapSelector(0), sceneStartTime(0), timeForThisScene(0) @@ -53,7 +53,7 @@ void CDemo::setup(GLData *gld) void CDemo::preDraw(GLData *gld, u32 now) { if (((now - sceneStartTime) > timeForThisScene) && (timeForThisScene != -1)) - switchToNextScene(); + switchToNextScene(gld); createParticleImpacts(); } @@ -80,7 +80,7 @@ bool CDemo::OnEvent(const SEvent& event) } -void CDemo::switchToNextScene() +void CDemo::switchToNextScene(GLData *gld) { currentScene++; if (currentScene > 3) @@ -191,12 +191,15 @@ void CDemo::switchToNextScene() } timeForThisScene = -1; - camera = addExtantzCamera(sm, 0, 100.0f, .4f, -1, false, 3.f, false, true); + gld->camera = addExtantzCamera(sm, 0, 100.0f, .4f, -1, false, 3.f, false, true); + camera = gld->camera; camera->setPosition(core::vector3df(150, 170, -160)); camera->setFarValue(5000.0f); + gld->move = getCameraMove(gld->camera); scene::ISceneNodeAnimatorCollisionResponse* collider = - 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); +// 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); + 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); camera->addAnimator(collider); collider->drop(); } 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: void createLoadingScreen(); void loadSceneData(); - void switchToNextScene(); + void switchToNextScene(GLData *gld); void shoot(); void createParticleImpacts(); 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; IAnimatedMeshSceneNode *node; CDemo *myDemo; -// This is the movemen speed in units per second. +// This is the movement speed in units per second. const f32 MOVEMENT_SPEED = 5.f; // In order to do framerate independent movement, we have to know // 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) return shader; } +static void _cb_mouse_down_GL(void *data, Evas *evas, Evas_Object *obj, void *event_info) +{ + GLData *gld = data; + Evas_Event_Mouse_Down *ev = event_info; + + if (1 == ev->button) + { + gld->camFocus = 1; + printf("Background GL object focused.\n"); + } +} + +static void _cb_mouse_down_elm(void *data, Evas *evas, Evas_Object *obj, void *event_info) +{ + GLData *gld = data; + Evas_Event_Mouse_Down *ev = event_info; + + if (1 == ev->button) + { + gld->camFocus = 0; + // TODO - Yes we really DO need to figure out what was clicked on and set focus to it. sigh + // For now, we only got one window, focus on it's box. + elm_object_focus_set(gld->bx, EINA_TRUE); + printf("ELM object focused.\n"); + } +} + +static Eina_Bool _on_camera_input(void *data, Evas_Object *obj, Evas_Object *src, Evas_Callback_Type type, void *event_info) +{ + GLData *gld = data; + + if (gld->camFocus) + { + if (gld->move) + { + // 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. + Evas_Event_Key_Down *ev = event_info; + + // Yes, we are dealing with the horrid Evas keyboard handling FUCKING STRING COMPARES! Soooo ... + // TODO - make this a hash lookup dammit. + // TODO - these are not working, coz Elm is grabbing the Left, Right, Up, and Down KEY_DOWNs. + if (EVAS_CALLBACK_KEY_DOWN == type) + { + if (0 == strcmp(ev->keyname, "Escape")) + { + } + else if (0 == strcmp(ev->key, "Left")) + gld->move->y = 1.0; + else if (0 == strcmp(ev->key, "Right")) + gld->move->y = -1.0; + else if (0 == strcmp(ev->key, "Up")) + gld->move->x = 1.0; + else if (0 == strcmp(ev->key, "Down")) + gld->move->x = -1.0; + else if (0 == strcmp(ev->key, "Prior")) + gld->move->x = 1.0; + else if (0 == strcmp(ev->key, "Next")) + gld->move->x = -1.0; + else if (0 == strcmp(ev->key, "Home")) + gld->move->y = 1.0; + else if (0 == strcmp(ev->key, "End")) + gld->move->y = -1.0; + else if (0 == strcmp(ev->key, "space")) + gld->move->jump = 1.0; + else + printf("Unexpected down keystroke - %s\n", ev->key); + } + else if (EVAS_CALLBACK_KEY_UP == type) + { + if (0 == strcmp(ev->keyname, "Escape")) + { + } + else if (0 == strcmp(ev->key, "Left")) + gld->move->y = 0.0; + else if (0 == strcmp(ev->key, "Right")) + gld->move->y = 0.0; + else if (0 == strcmp(ev->key, "Up")) + gld->move->x = 0.0; + else if (0 == strcmp(ev->key, "Down")) + gld->move->x = 0.0; + else if (0 == strcmp(ev->key, "Prior")) + gld->move->x = 0.0; + else if (0 == strcmp(ev->key, "Next")) + gld->move->x = 0.0; + else if (0 == strcmp(ev->key, "Home")) + gld->move->y = 0.0; + else if (0 == strcmp(ev->key, "End")) + gld->move->y = 0.0; + else if (0 == strcmp(ev->key, "space")) + gld->move->jump = 0.0; + else + printf("Unexpected up keystroke - %s\n", ev->key); + } + } + else + printf("Camera input not ready\n"); + } + + return EINA_FALSE; // TRUE = event was processed here, don't propagate. FALSE = propagate event, not processed here. +} + static void _resize(GLData *gld) { Evas_GL_API *gl = gld->glapi; @@ -441,6 +542,7 @@ on_del(void *data, Evas *e, Evas_Object *obj, void *event_info) if (!gld) return; Evas_GL_API *gl = gld->glapi; + elm_object_event_callback_del(gld->r1, _on_camera_input, gld); ecore_animator_del(gld->animator); if (gld->useEGL) @@ -635,6 +737,11 @@ static void init_evas_gl(GLData *gld, int w, int h) // ecore_animator_frametime_set(1.0); gld->animator = ecore_animator_add(doFrame, gld); // This animator will be called every frame tick, which defaults to 1/30 seconds. + // In this code, we are making our own camera, so grab it's input when we are focused. + elm_object_event_callback_add(gld->win, _on_camera_input, gld); + evas_object_event_callback_add(gld->r1, EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_GL, gld); + gld->camFocus = 1; // Start with the GL camera focused. + return; } @@ -752,7 +859,8 @@ static void _grid_sel_cb(void *data, Evas_Object *obj, void *event_info) // sprintf(buf, "dillo -f -g '%dx%d+%d+%d' %s &", w - (w / 5), h - 30, w / 5, y, thisGrid->splashPage); sprintf(buf, "uzbl -g '%dx%d+%d+%d' -u %s &", w - (w / 5), h - 30, w / 5, y, thisGrid->splashPage); printf("%s ### genlist obj [%p], item pointer [%p]\n", buf, obj, event_info); - system(buf); +// comment this out for now, busy dealing with input stuff, don't want to trigger this multiple times. +// system(buf); } static void @@ -902,15 +1010,6 @@ fill(Evas_Object *win) evas_object_show(bx); } - -static void -cb_mouse_down(void *data, Evas *evas, Evas_Object *obj, void *event_info) -{ - Evas_Event_Mouse_Down *ev = event_info; - - if (ev->button == 1) elm_object_focus_set(obj, EINA_TRUE); -} - static void cb_mouse_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) { @@ -1043,7 +1142,7 @@ EAPI_MAIN int elm_main(int argc, char **argv) win3 = elm_win_add(gld->win, "inlined", ELM_WIN_INLINED_IMAGE); elm_win_title_set(win3, "world manager"); - evas_object_event_callback_add(elm_win_inlined_image_object_get(win3), EVAS_CALLBACK_MOUSE_DOWN, cb_mouse_down, NULL); + evas_object_event_callback_add(elm_win_inlined_image_object_get(win3), EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_elm, gld); elm_win_alpha_set(win3, EINA_TRUE); fill(win3); // 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 @@ #include #include #include +#include "extantzCamera.h" #ifdef GL_GLES @@ -44,6 +45,7 @@ extern "C"{ typedef struct IrrlichtDevice IrrlichtDevice; typedef struct IVideoDriver IVideoDriver; typedef struct ISceneManager ISceneManager; +typedef struct ICameraSceneNode ICameraSceneNode; #endif @@ -143,13 +145,17 @@ struct _GLData int useIrr : 1; int doneIrr : 1; int resized : 1; + int camFocus : 1; Evas_Object *bx, *r1; Ecore_Animator *animator; - IrrlichtDevice *device; // IrrlichtDevice - IVideoDriver *driver; // IVideoDriver - ISceneManager *smgr; // ISceneManager + IrrlichtDevice *device; + IVideoDriver *driver; + ISceneManager *smgr; + ICameraSceneNode *camera; + + cameraMove *move; // Gear Stuff 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 if (node) { // ISceneNodeAnimator* anm = new extantzCamera(CursorControl, rotateSpeed, moveSpeed, jumpSpeed, noVerticalMovement, invertMouseY); - ISceneNodeAnimator* anm = new extantzCamera(NULL, rotateSpeed, moveSpeed, jumpSpeed, noVerticalMovement, invertMouseY); + ISceneNodeAnimator* anm = new extantzCamera(rotateSpeed, moveSpeed, jumpSpeed, noVerticalMovement, invertMouseY); // Bind the node's rotation to its target. This is consistent with 1.4.2 and below. node->bindTargetAndRotation(true); @@ -46,8 +46,10 @@ ICameraSceneNode *addExtantzCamera(ISceneManager* sm, ISceneNode* parent, f32 ro //! constructor -extantzCamera::extantzCamera(gui::ICursorControl* cursorControl, f32 rotateSpeed, f32 moveSpeed, f32 jumpSpeed, bool noVerticalMovement, bool invertY) - : CursorControl(cursorControl), MaxVerticalAngle(88.0f), MoveSpeed(moveSpeed), RotateSpeed(rotateSpeed), JumpSpeed(jumpSpeed), +//extantzCamera::extantzCamera(gui::ICursorControl* cursorControl, f32 rotateSpeed, f32 moveSpeed, f32 jumpSpeed, bool noVerticalMovement, bool invertY) +// : CursorControl(cursorControl), MaxVerticalAngle(88.0f), MoveSpeed(moveSpeed), RotateSpeed(rotateSpeed), JumpSpeed(jumpSpeed), +extantzCamera::extantzCamera(f32 rotateSpeed, f32 moveSpeed, f32 jumpSpeed, bool noVerticalMovement, bool invertY) + : MaxVerticalAngle(88.0f), MoveSpeed(moveSpeed), RotateSpeed(rotateSpeed), JumpSpeed(jumpSpeed), MouseYDirection(invertY ? -1.0f : 1.0f), LastAnimationTime(0), firstUpdate(true), NoVerticalMovement(noVerticalMovement) { #ifdef _DEBUG @@ -56,8 +58,6 @@ extantzCamera::extantzCamera(gui::ICursorControl* cursorControl, f32 rotateSpeed // if (CursorControl) // CursorControl->grab(); - - allKeysUp(); } @@ -69,39 +69,16 @@ extantzCamera::~extantzCamera() } -#if 0 -// TODO - get rid of this, it's an Irrlicht callback, and I'm replacing it all with EFL. -// Leaving it here for the moment as an example. -bool extantzCamera::OnEvent(const SEvent& evt) -{ - switch(evt.EventType) - { - case EET_KEY_INPUT_EVENT: - for (u32 i=0; igetRelativePosition(); - return true; - } - break; - - default: - break; - } - - return false; -} -#endif +/* Have a moveRotate array of floats. + * X, Y, Z, and whatever the usual letters are for rotations. lol + * Each one means "move or rotate this much in this direction". + * Where 1.0 means "what ever the standard move is if that key is held down". + * So a keyboard move would just change it's part to 1.0 or -1.0 on key down, + * and back to 0.0 on key up. Or 2.0 / -2.0 if in run mode. + * Which would even work in fly mode. + * A joystick could be set to range over -2.0 to 2.0, and just set it's part directly. + * A mouse look rotate, well will come to that when we need to. B-) + */ void extantzCamera::animateNode(ISceneNode* node, u32 timeMs) { @@ -127,8 +104,7 @@ void extantzCamera::animateNode(ISceneNode* node, u32 timeMs) // If the camera isn't the active camera, and receiving input, then don't process it. if(!camera->isInputReceiverEnabled()) { - allKeysUp(); - return; +// return; } scene::ISceneManager * smgr = camera->getSceneManager(); @@ -216,15 +192,10 @@ void extantzCamera::animateNode(ISceneNode* node, u32 timeMs) movedir.normalize(); - // 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. - if (CursorKeys[EKA_MOVE_FORWARD]) - pos += movedir * timeDiff * MoveSpeed; - - if (CursorKeys[EKA_MOVE_BACKWARD]) - pos -= movedir * timeDiff * MoveSpeed; + // 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. + pos += movedir * timeDiff * MoveSpeed * move.x; // strafing - core::vector3df strafevect = target; strafevect = strafevect.crossProduct(camera->getUpVector()); @@ -233,15 +204,11 @@ void extantzCamera::animateNode(ISceneNode* node, u32 timeMs) strafevect.normalize(); - if (CursorKeys[EKA_STRAFE_LEFT]) - pos += strafevect * timeDiff * MoveSpeed; - - if (CursorKeys[EKA_STRAFE_RIGHT]) - pos -= strafevect * timeDiff * MoveSpeed; + pos += strafevect * timeDiff * MoveSpeed * move.y; // For jumping, we find the collision response animator attached to our camera // and if it's not falling, we tell it to jump. - if (CursorKeys[EKA_JUMP_UP]) + if (0.0 < move.jump) { const ISceneNodeAnimatorList& animators = camera->getAnimators(); ISceneNodeAnimatorList::ConstIterator it = animators.begin(); @@ -269,13 +236,6 @@ void extantzCamera::animateNode(ISceneNode* node, u32 timeMs) } -void extantzCamera::allKeysUp() -{ - for (u32 i=0; igetAnimators(); + ISceneNodeAnimatorList::ConstIterator it = animators.begin(); + while(it != animators.end()) + { + // TODO - We assume FPS == extantzCamera, coz Irrlicht hard codes the camera types in an enum, which is a pain to add to from outside. + if(ESNAT_CAMERA_FPS == (*it)->getType()) + { + extantzCamera *ec = static_cast(*it); + + cm = &(ec->move); + } + + it++; + } + } + return cm; +} + +#ifdef __cplusplus +} +#endif + } // namespace scene } // 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 @@ #ifndef __EXTANTZ_CAMERA_H_INCLUDED__ #define __EXTANTZ_CAMERA_H_INCLUDED__ + +#ifdef __cplusplus #include #include #include @@ -12,18 +14,38 @@ #include #include +using namespace irr; +using namespace scene; +extern "C"{ +#else +typedef struct extantzCamera extantzCamera; +typedef struct ICameraSceneNode ICameraSceneNode; +#endif -namespace irr +typedef struct { -namespace gui -{ - class ICursorControl; + float x, y, z; + float r, s, t; + float jump; +} cameraMove; + +cameraMove *getCameraMove(ICameraSceneNode *camera); + +#ifdef __cplusplus } + +//namespace irr::gui +//{ +// class ICursorControl; +//} + + +namespace irr +{ namespace scene { - ICameraSceneNode *addExtantzCamera(ISceneManager* sm, ISceneNode* parent, f32 rotateSpeed, f32 moveSpeed, s32 id, bool noVerticalMovement, f32 jumpSpeed, bool invertMouseY, bool makeActive); class extantzCamera : public ISceneNodeAnimator @@ -31,7 +53,8 @@ namespace scene public: //! Constructor - extantzCamera(gui::ICursorControl* cursorControl, f32 rotateSpeed = 100.0f, f32 moveSpeed = .5f, f32 jumpSpeed=0.f, bool noVerticalMovement=false, bool invertY=false); +// extantzCamera(gui::ICursorControl* cursorControl, f32 rotateSpeed = 100.0f, f32 moveSpeed = .5f, f32 jumpSpeed=0.f, bool noVerticalMovement=false, bool invertY=false); + extantzCamera(f32 rotateSpeed = 100.0f, f32 moveSpeed = .5f, f32 jumpSpeed=0.f, bool noVerticalMovement=false, bool invertY=false); //! Destructor virtual ~extantzCamera(); @@ -77,11 +100,9 @@ namespace scene done with it. */ virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0); - private: - void allKeysUp(); - - gui::ICursorControl *CursorControl; + cameraMove move; + private: f32 MaxVerticalAngle; f32 MoveSpeed; @@ -94,14 +115,13 @@ namespace scene core::position2d CenterCursor, CursorPos; - bool CursorKeys[EKA_COUNT]; - bool firstUpdate; bool NoVerticalMovement; }; +}; +}; +#endif -} // end namespace scene -} // end namespace irr #endif // __EXTANTZ_CAMERA_H_INCLUDED__ -- cgit v1.1