From 36ce28a7557c4b2b73316621471558354024ca54 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 1 May 2008 21:08:40 +0000 Subject: roll control --- src/client/camera.cc | 60 +++++++++++++++++++++++++++++++++++----------------- src/client/camera.h | 3 +++ src/client/input.cc | 24 +++++++++++++++++++-- 3 files changed, 66 insertions(+), 21 deletions(-) (limited to 'src/client') diff --git a/src/client/camera.cc b/src/client/camera.cc index e2dbacf..c2bbc83 100644 --- a/src/client/camera.cc +++ b/src/client/camera.cc @@ -43,6 +43,11 @@ float yaw_current; // current pitch, angle in XY, positive is looking up float pitch_current; +// current direction rotation speed +float current_direction_speed; +// current pitcj rotation speed +float current_pitch_speed; + // default pitch in mode::Overview float pitch_overview; @@ -55,6 +60,8 @@ float rotate_offset_inc; // default translate offset increase/decrease const float translate_offset_inc = 0.1; +void set_mode(Mode newmode); + void init() { rotate_offset_inc = 5.0f; @@ -67,7 +74,8 @@ void init() distance = 0.4f; - mode = Track; + set_mode(Track); + } void shutdown() @@ -75,25 +83,24 @@ void shutdown() } void set_mode(Mode newmode) { + + current_direction_speed = 0; + current_pitch_speed = 0; + yaw_target = 0; + yaw_current = yaw_target; + pitch_target = pitch_track; + pitch_current = pitch_target; + distance = 0.4f; + switch(newmode) { case Track: // switch camera to Track mode mode = Track; - yaw_target = 0; - yaw_current = yaw_target; - pitch_target = pitch_track; - pitch_current = pitch_target; - distance = 0.4f; break; case Free: // switch camera to Free mode mode = Free; - yaw_target = 0; - yaw_current = yaw_target; - pitch_target = pitch_track; - pitch_current = pitch_target; - distance = 0.4f; break; case Overview: @@ -128,7 +135,7 @@ void next_mode() } } -void draw(float elapsed) +void draw(float seconds) { math::Matrix4f matrix; @@ -153,25 +160,34 @@ void draw(float elapsed) set_mode(Track); target.assign(core::localcontrol()->location()); - - axis.assign(core::localcontrol()->axis()); - + if (core::localcontrol()->model()) + target += core::localcontrol()->model()->maxbbox().z * core::localcontrol()->axis().up(); + if (mode == Track) { // make the camera swing while turning yaw_target = -25.0f * core::localcontrol()->target_direction; pitch_target = pitch_track - 25 * core::localcontrol()->target_pitch; - } + /* + d = -math::dotproduct(axis.forward(), core::localcontrol()->axis().forward()) + 1; + axis.change_direction(360.0f * d * seconds); + + //d = -math::dotproduct(axis.left(), core::localcontrol()->axis().left()) + 1; + // axis.change_pitch(360.0f * d * seconds); + */ + } + + axis.assign(core::localcontrol()->axis()); // adjust direction d = degrees180f(yaw_current - yaw_target); - yaw_current = degrees360f( yaw_current - d * elapsed); + yaw_current = degrees360f( yaw_current - d * seconds); axis.change_direction(yaw_current); // adjust pitch target d = degrees180f(pitch_current - pitch_target); - pitch_current = degrees360f(pitch_current - d *elapsed); + pitch_current = degrees360f(pitch_current - d *seconds); axis.change_pitch(pitch_current); - + if (core::localcontrol()->model()) distance = 1+core::localcontrol()->model()->radius(); else @@ -228,6 +244,12 @@ void key_up() } } + +void reset() +{ + set_mode(mode); +} + } // namespace camera } // namespace client diff --git a/src/client/camera.h b/src/client/camera.h index 25e179d..751ff02 100644 --- a/src/client/camera.h +++ b/src/client/camera.h @@ -41,6 +41,9 @@ namespace camera /// switch to next camera mode void next_mode(); + /// reset the current mode + void reset(); + /// gameworld coordinates of the camera target extern math::Vector3f target; diff --git a/src/client/input.cc b/src/client/input.cc index d10c8bc..87492c4 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -27,8 +27,8 @@ namespace input // local controls float local_turn = 0.0f; float local_pitch = 0.0f; -float local_roll = 0.0f; float local_thrust = 0.0f; +float local_roll = 0.0f; // last controlled entity unsigned int last_control = 0; @@ -84,6 +84,14 @@ void keyreleased(const SDL_keysym &keysym) local_turn = 0.0f; break; + case SDLK_KP_DIVIDE: // roll left + local_roll = 0.0f; + break; + + case SDLK_KP_MULTIPLY: // roll light + local_roll = 0.0f; + break; + default: break; } @@ -132,9 +140,18 @@ void keypressed(const SDL_keysym &keysym) local_turn = -1.0f; break; - case SDLK_KP5: + case SDLK_KP5: // level local_turn = 0; local_pitch = 0; + local_roll = 0; + break; + + case SDLK_KP_DIVIDE: // roll left + local_roll = 1.0f; + break; + + case SDLK_KP_MULTIPLY: // roll light + local_roll = -1.0f; break; @@ -165,8 +182,10 @@ void frame(float seconds) if (core::localcontrol() && (last_control != core::localcontrol()->id())) { local_turn = 0.0f; local_pitch = 0.0f; + local_roll = 0.0f; local_thrust = core::localcontrol()->thrust(); last_control = core::localcontrol()->id(); + camera::reset(); } SDL_Event event; @@ -281,6 +300,7 @@ void frame(float seconds) core::localcontrol()->set_thrust(local_thrust); core::localcontrol()->set_direction(local_turn); core::localcontrol()->set_pitch(local_pitch / video::aspect ); + core::localcontrol()->set_roll(local_roll); } } -- cgit v1.2.3