diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/camera.cc | 40 | ||||
-rw-r--r-- | src/client/input.cc | 101 | ||||
-rw-r--r-- | src/client/view.cc | 7 |
3 files changed, 114 insertions, 34 deletions
diff --git a/src/client/camera.cc b/src/client/camera.cc index 754cbad..585aafc 100644 --- a/src/client/camera.cc +++ b/src/client/camera.cc @@ -5,6 +5,7 @@ */ #include "math/mathlib.h" +#include "math/matrix4f.h" #include "core/core.h" #include "client/client.h" #include "client/camera.h" @@ -84,7 +85,9 @@ void set_mode(Mode newmode) { case Track: // switch camera to Track mode mode = Track; - yaw_target = core::localcontrol()->direction(); + // FIXME + //yaw_target = core::localcontrol()->direction(); + yaw_target = 0; yaw_current = yaw_target; pitch_target = pitch_track; pitch_current = pitch_target; @@ -93,7 +96,9 @@ void set_mode(Mode newmode) { case Free: // switch camera to Free mode mode = Free; - yaw_target = core::localcontrol()->direction(); + // FIXME + //yaw_target = core::localcontrol()->direction(); + yaw_target = 0; yaw_current = yaw_target; pitch_target = pitch_track; pitch_current = pitch_target; @@ -150,7 +155,9 @@ void draw(float elapsed) } if (mode == Track) { - yaw_target = core::localcontrol()->direction(); + // FIXME + //yaw_target = core::localcontrol()->direction(); + yaw_target = 0; } if ((mode == Free) || (mode == Track)) { @@ -167,21 +174,40 @@ void draw(float elapsed) gl::rotate(90.0f, 0, 1.0, 0); gl::rotate(-90.0f, 1.0f , 0, 0); + math::Matrix4f matrix; + // map camera coordinates to opengl coordinates switch (mode) { case Free: case Track: if (core::localcontrol()->model()) - distance = core::localcontrol()->model()->radius(); + distance = 1+core::localcontrol()->model()->radius(); else - distance = 0.5f; - + distance = 1.5f; + + target = core::localcontrol()->location(); + matrix = core::localcontrol()->axis(); + + // apply the transpose of the axis transformation (the axis is orhtonormal) + gl::multmatrix(matrix.transpose()); + + // match the camera with the current target + gl::translate(-1.0f * target); + + // draw the local camera transformation + gl::translate(distance * core::localcontrol()->axis().forward()); + gl::translate((distance-1)/-2.0f * core::localcontrol()->axis().up()); + + /* // draw the camera transformation gl::translate(0.0f, 0.0f, -3*distance/4); gl::translate(1.2+distance, 0.0f, 0.0f); gl::rotate(-pitch_current, 0.0f, 1.0f, 0.0f); gl::rotate(-yaw_current, 0.0f, 0.0f, 1.0f); - gl::translate(-1*target); + */ + + // reposition, the engine will draw relative to 0,0,0 + //gl::translate(-1 * target); break; case Overview: diff --git a/src/client/input.cc b/src/client/input.cc index 8d80a21..994e38b 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -26,6 +26,8 @@ namespace input // local offset to make turns float local_turn = 0.0f; +// local offset to change pitch +float local_pitch = 0.0f; // local thrust setting float local_thrust = 0.0f; @@ -39,6 +41,8 @@ int mouse_y = 0; // true if the mouse is in the deadzone bool mouse_deadzone = false; +const float thruster_offset = 0.05f; + void init() { con_print << "Initializing input..." << std::endl; @@ -60,9 +64,27 @@ void shutdown() void keyreleased(const SDL_keysym &keysym) { switch (keysym.sym) { + case SDLK_SPACE: camera::next_mode(); break; + + case SDLK_KP8: // down + local_pitch = 0.0f; + break; + + case SDLK_KP2: // up + local_pitch = 0.0f; + break; + + case SDLK_KP4: // left + local_turn = 0.0f; + break; + + case SDLK_KP6: // right + local_turn = 0.0f; + break; + default: break; } @@ -86,25 +108,37 @@ void keypressed(const SDL_keysym &keysym) case SDLK_DOWN: camera::key_down(); break; + case SDLK_KP_PLUS: - local_thrust += 0.015f; - if (local_thrust > 1.0f) - local_thrust = 1.0f; + local_thrust += thruster_offset; break; + case SDLK_KP_MINUS: - // TODO set core entity params - local_thrust -= 0.020f; - if (local_thrust < 0.0f) - local_thrust = 0.0f; + local_thrust -= 2.0f * thruster_offset; break; - case SDLK_KP4: - // TODO set core entity params - local_turn += 0.05; + + case SDLK_KP8: // down + local_pitch = -1.0f; break; - case SDLK_KP6: - // TODO set core entity params - local_turn -= 0.05; + + case SDLK_KP2: // up + local_pitch = 1.0f; + break; + + case SDLK_KP4: // left + local_turn = 1.0f; break; + + case SDLK_KP6: // right + local_turn = -1.0f; + break; + + case SDLK_KP5: + local_turn = 0; + local_pitch = 0; + break; + + default: break; } @@ -118,16 +152,11 @@ 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; - + local_thrust += thruster_offset; break; - case SDL_BUTTON_WHEELDOWN: - local_thrust -= 0.02f; - if (local_thrust < 0.0f) - local_thrust = 0.0f; + case SDL_BUTTON_WHEELDOWN: + local_thrust -= 2.0f * thruster_offset; break; } } @@ -199,19 +228,40 @@ void frame(float seconds) if (!console::visible() && core::application()->connected() && core::localcontrol()) { + if (local_thrust > 1.0f) + local_thrust = 1.0f; + else if (local_thrust < -2.0 * thruster_offset) + local_thrust = -2.0 * thruster_offset; + if (camera::mode == camera::Track && cl_mousecontrol->value()) { // mouse control when camera is in tracking mode + int deadzone_size = 24; + mouse_deadzone = true; + + // direction int l = mouse_x - (video::width >> 1); - if (abs(l) < ( CHARWIDTH >> 1 )) { + if (abs(l) < ( deadzone_size >> 1 )) { // dead zone local_turn = 0; - mouse_deadzone = true; } else { - l = (mouse_x - CHARWIDTH) - ((video::width - CHARWIDTH) >> 1); - local_turn = float (-l) / (float) ((video::width - CHARWIDTH) >> 1); + l = (mouse_x - deadzone_size) - ((video::width - deadzone_size) >> 1); + local_turn = float (-l) / (float) ((video::width - deadzone_size) >> 1); + mouse_deadzone = false; + } + + // pitch + int h = mouse_y - (video::height >> 1); + + if (abs(h) < ( deadzone_size >> 1 )) { + // dead zone + local_pitch = 0; + } else { + h = (mouse_y - deadzone_size) - ((video::height - deadzone_size) >> 1); + local_pitch = float (-h) / (float) ((video::height - deadzone_size) >> 1); mouse_deadzone = false; } + } else { if (local_turn > 1.0f) local_turn = 1.0f; @@ -222,6 +272,7 @@ void frame(float seconds) core::localcontrol()->set_thrust(local_thrust); core::localcontrol()->set_direction(local_turn); + core::localcontrol()->set_pitch(local_pitch); } } diff --git a/src/client/view.cc b/src/client/view.cc index 522526e..39cd351 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -184,8 +184,11 @@ void draw_status() // draw a basic HUD if (core::localcontrol()) { status.str(""); - status << " dir " << std::setfill('0') << std::setw(3) << roundf(core::localcontrol()->direction()) << - " speed " << std::setfill(' ') << std::setw(5) << std::fixed << std::setprecision(2) << core::localcontrol()->speed() << " - " << input::mouse_x << "+" << input::mouse_y; + status << "thrust " << std::setfill(' ') << std::setw(5) << std::fixed + << std::setprecision(2) << core::localcontrol()->thrust() << " "; + + status << "speed " << std::setfill(' ') << std::setw(5) << std::fixed + << std::setprecision(2) << core::localcontrol()->speed(); draw_text(CHARWIDTH, video::height - CHARHEIGHT -4, status); } |