diff options
author | Stijn Buys <ingar@osirion.org> | 2008-04-06 15:36:51 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-04-06 15:36:51 +0000 |
commit | c5e90960fc333c2b1d2b3e961da439928b2ac872 (patch) | |
tree | 6b6a4fbda96458db97ec880e346e347ee5c7a2c8 /src | |
parent | f36e9bd8190c377836463bdeaf553671d34e8e98 (diff) |
mouse control
Diffstat (limited to 'src')
-rw-r--r-- | src/client/camera.h | 3 | ||||
-rw-r--r-- | src/client/console.cc | 2 | ||||
-rw-r--r-- | src/client/input.cc | 62 |
3 files changed, 61 insertions, 6 deletions
diff --git a/src/client/camera.h b/src/client/camera.h index 08adfaa..2a79fda 100644 --- a/src/client/camera.h +++ b/src/client/camera.h @@ -47,6 +47,9 @@ namespace camera /// gameworld coordinates of the camera eye extern math::Vector3f eye; + /// current camera mode + extern Mode mode; + } // namespace camera } // namespace client diff --git a/src/client/console.cc b/src/client/console.cc index ca84384..04f896f 100644 --- a/src/client/console.cc +++ b/src/client/console.cc @@ -216,8 +216,10 @@ void toggle() (*history_pos).clear(); SDL_WM_GrabInput(SDL_GRAB_OFF); + SDL_ShowCursor(SDL_ENABLE); } else { SDL_WM_GrabInput(SDL_GRAB_ON); + SDL_ShowCursor(SDL_DISABLE); } setkeyboardmode(console::visible()); diff --git a/src/client/input.cc b/src/client/input.cc index 0650119..c7c751e 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -12,6 +12,7 @@ #include "client/camera.h" #include "client/keyboard.h" #include "client/video.h" +#include "render/text.h" #include "SDL/SDL.h" @@ -34,12 +35,17 @@ unsigned int last_control = 0; int mouse_x = 0; int mouse_y = 0; +core::Cvar *cl_mousecontrol = 0; + void init() { con_print << "Initializing input..." << std::endl; client::setkeyboardmode(false); + SDL_ShowCursor(SDL_DISABLE); SDL_WM_GrabInput(SDL_GRAB_ON); // SDL_EnableUNICODE(1); + cl_mousecontrol = core::Cvar::get("cl_mousecontrol", "0", core::Cvar::Archive); + cl_mousecontrol->set_info("[bool] mouse control"); } void shutdown() @@ -61,6 +67,8 @@ void keyreleased(const SDL_keysym &keysym) } // handle key press events for the game world + +// http://docs.mandragor.org/files/Common_libs_documentation/SDL/SDL_Documentation_project_en/sdlkey.html void keypressed(const SDL_keysym &keysym) { switch (keysym.sym) { @@ -77,7 +85,6 @@ void keypressed(const SDL_keysym &keysym) camera::key_down(); break; case SDLK_KP_PLUS: - // TODO set core entity params local_thrust += 0.015f; if (local_thrust > 1.0f) local_thrust = 1.0f; @@ -102,6 +109,27 @@ void keypressed(const SDL_keysym &keysym) } +// handle mouse button events for the game world + +// http://docs.mandragor.org/files/Common_libs_documentation/SDL/SDL_Documentation_project_en/sdlmousebuttonevent.html +void mousebuttonpressed(const SDL_MouseButtonEvent &button) +{ + switch (button.button) { + case SDL_BUTTON_WHEELUP: + local_thrust += 0.015f; + if (local_thrust > 1.0f) + local_thrust = 1.0f; + + break; + case SDL_BUTTON_WHEELDOWN: + local_thrust -= 0.02f; + if (local_thrust < 0.0f) + local_thrust = 0.0f; + + break; + } +} + void frame(float seconds) { if (core::localcontrol() && (last_control != core::localcontrol()->id())) { @@ -119,7 +147,11 @@ void frame(float seconds) mouse_x = event.motion.x; mouse_y = event.motion.y; break; + case SDL_MOUSEBUTTONDOWN: + if (!console::visible() && core::application()->connected() && core::localcontrol()) + mousebuttonpressed(event.button); + break; case SDL_KEYUP: if (event.key.keysym.sym == SDLK_PRINT) { video::screenshot(); @@ -162,12 +194,30 @@ void frame(float seconds) } } - + if (!console::visible() && core::application()->connected() && core::localcontrol()) { - if (local_turn > 1.0f) - local_turn = 1.0f; - else if (local_turn < -1.0f) - local_turn = -1.0f; + + if (cl_mousecontrol->value()) { + // mouse control when camera is in tracking mode + if (camera::mode == camera::Track) { + int l = mouse_x - (video::width >> 1); + + if (abs(l) < ( CHARWIDTH >> 1 )) // dead zone + local_turn = 0; + else { + l = (mouse_x - CHARWIDTH) - ((video::width - CHARWIDTH) >> 1); + local_turn = float (-l) / (float) ((video::width - CHARWIDTH) >> 1); + } + } else { + local_turn = 0; + } + + } else { + if (local_turn > 1.0f) + local_turn = 1.0f; + else if (local_turn < -1.0f) + local_turn = -1.0f; + } core::localcontrol()->set_thrust(local_thrust); core::localcontrol()->set_direction(local_turn); |