diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/camera.cc | 135 | ||||
-rw-r--r-- | src/client/input.cc | 76 | ||||
-rw-r--r-- | src/client/view.cc | 2 |
3 files changed, 90 insertions, 123 deletions
diff --git a/src/client/camera.cc b/src/client/camera.cc index 585aafc..c66a933 100644 --- a/src/client/camera.cc +++ b/src/client/camera.cc @@ -22,11 +22,8 @@ namespace client namespace camera { -// public variables - // gameworld coordinates of the camera target math::Vector3f target; -// gameworld coordinates of the camera eye math::Vector3f eye; // target yaw, angle in XZ plane, positive is looking left @@ -48,16 +45,12 @@ float pitch_current; // default pitch in mode::Overview float pitch_overview; - -// current x offset -float x_offset; -// current z offset -float z_offset; - // default pitch in mode::Track -const float pitch_track = 0.0f; // 15.0f; +const float pitch_track = 15.0f; + // default rotate offset increase/decrease float rotate_offset_inc; + // default translate offset increase/decrease const float translate_offset_inc = 0.1; @@ -85,31 +78,27 @@ void set_mode(Mode newmode) { case Track: // switch camera to Track mode mode = Track; - // FIXME - //yaw_target = core::localcontrol()->direction(); 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; - // FIXME - //yaw_target = core::localcontrol()->direction(); yaw_target = 0; yaw_current = yaw_target; pitch_target = pitch_track; pitch_current = pitch_target; distance = 0.4f; break; + case Overview: // switch camera to Overview mode mode = Overview; - x_offset = 0; - z_offset = 0; - distance = 20.0f; + default: break; } @@ -140,97 +129,73 @@ void next_mode() void draw(float elapsed) { + math::Matrix4f matrix; + math::Axis axis; + + float d = 0; + if (!core::localcontrol()) { - // switch the camera to Overview of the player is not controling anything + if (mode != Overview) { set_mode(Overview); - - camera::target = math::Vector3f(0,0,0); } + + target.clear(); + axis.clear(); + pitch_current = -75.0f; + axis.change_pitch(pitch_current); + + distance = 20.0f; + } else { + if (mode == Overview) set_mode(Track); - camera::target = core::localcontrol()->location(); - } + target.assign(core::localcontrol()->location()); + + axis.assign(core::localcontrol()->axis()); - if (mode == Track) { - // FIXME - //yaw_target = core::localcontrol()->direction(); - yaw_target = 0; - } + // adjust direction + d = degrees180f(yaw_current - yaw_target); + yaw_current = degrees360f( yaw_current - d * elapsed); + axis.change_direction(yaw_current); - if ((mode == Free) || (mode == Track)) { - // adjust yaw - float d = degrees180f(yaw_current - yaw_target); - yaw_current = degrees360f( yaw_current - d * elapsed) ; - // adjust pitch target d = degrees180f(pitch_current - pitch_target); - pitch_current = degrees360f( pitch_current - d *elapsed); - } + pitch_current = degrees360f(pitch_current - d *elapsed); + axis.change_pitch(pitch_current); - // map world coordinates to opengl coordinates - 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 = 1+core::localcontrol()->model()->radius(); else distance = 1.5f; + } - target = core::localcontrol()->location(); - matrix = core::localcontrol()->axis(); + // map world coordinates to opengl coordinates + gl::rotate(90.0f, 0, 1.0, 0); + gl::rotate(-90.0f, 1.0f , 0, 0); - // apply the transpose of the axis transformation (the axis is orhtonormal) - gl::multmatrix(matrix.transpose()); + // assign transformation matrix + matrix.assign(axis); - // 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); - */ - - // reposition, the engine will draw relative to 0,0,0 - //gl::translate(-1 * target); - break; - - case Overview: + // apply the transpose of the axis transformation (the axis is orhtonormal) + gl::multmatrix(matrix.transpose()); - eye = target; - eye.z = eye.z + distance-1; + // match the camera with the current target + gl::translate(-1.0f * target); + + // apply camera offset + gl::translate((1.0f+distance) * axis.forward()); - gl::rotate(-75.0f, 0.0f, 1.0f, 0.0f); - gl::translate(0.0f, 0.0f, -distance); - //gl::translate(x_offset, 0.0f, z_offset); - gl::translate(-1*target); - break; - default: - break; - } + // calculate eye position + eye = target - ((1.0f+distance) * axis.forward()); } void key_right() { if (mode == Free) { yaw_target = degrees360f( yaw_target + rotate_offset_inc); - } else if (mode == Overview) { - z_offset += translate_offset_inc; } } @@ -238,28 +203,22 @@ void key_left() { if (mode == Free) { yaw_target = degrees360f( yaw_target - rotate_offset_inc); - } else if (mode == Overview) { - z_offset -= translate_offset_inc; } } -void key_up() +void key_down() { if (mode == Free) { pitch_target = pitch_target + rotate_offset_inc; if (pitch_target > 90.0f) pitch_target = 90.0f; - } else if (mode == Overview) { - x_offset += translate_offset_inc; } } -void key_down() +void key_up() { if (mode == Free) { pitch_target = pitch_target - rotate_offset_inc; if (pitch_target < -90.0f) pitch_target = -90.0f; - } else if (mode == Overview) { - x_offset -= translate_offset_inc; } } diff --git a/src/client/input.cc b/src/client/input.cc index 994e38b..99fe638 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -24,12 +24,10 @@ core::Cvar *cl_mousecontrol = 0; namespace input { -// local offset to make turns +// local controls float local_turn = 0.0f; -// local offset to change pitch float local_pitch = 0.0f; - -// local thrust setting +float local_roll = 0.0f; float local_thrust = 0.0f; // last controlled entity @@ -38,6 +36,7 @@ unsigned int last_control = 0; // mouse cursor position int mouse_x = 0; int mouse_y = 0; + // true if the mouse is in the deadzone bool mouse_deadzone = false; @@ -165,6 +164,7 @@ void frame(float seconds) { if (core::localcontrol() && (last_control != core::localcontrol()->id())) { local_turn = 0.0f; + local_pitch = 0.0f; local_thrust = core::localcontrol()->thrust(); last_control = core::localcontrol()->id(); } @@ -233,41 +233,49 @@ void frame(float seconds) 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 (camera::mode == camera::Track) { + if (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) < ( deadzone_size >> 1 )) { + // dead zone + local_turn = 0; + } else { + 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; + } - if (abs(l) < ( deadzone_size >> 1 )) { - // dead zone - local_turn = 0; } else { - l = (mouse_x - deadzone_size) - ((video::width - deadzone_size) >> 1); - local_turn = float (-l) / (float) ((video::width - deadzone_size) >> 1); - mouse_deadzone = false; - } + if (local_turn > 1.0f) + local_turn = 1.0f; + else if (local_turn < -1.0f) + local_turn = -1.0f; - // pitch - int h = mouse_y - (video::height >> 1); + if (local_pitch > 1.0f) + local_pitch = 1.0f; + else if (local_pitch < -1.0f) + local_pitch = -1.0f; - 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; - else if (local_turn < -1.0f) - local_turn = -1.0f; - mouse_deadzone = false; + } } core::localcontrol()->set_thrust(local_thrust); diff --git a/src/client/view.cc b/src/client/view.cc index 39cd351..e8ec5e8 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -268,7 +268,7 @@ void frame(float seconds) camera::draw(seconds); // draw the current camera transformation - render::draw(camera::eye, camera::target, seconds); // draw the world + render::draw(camera::target, seconds); // draw the world } |