/* client/camera.cc This file is part of the Osirion project and is distributed under the terms and conditions of the GNU General Public License version 2 */ #include "camera.h" #include "gl/osiriongl.h" #include "game/game.h" #include "common/functions.h" using namespace common; namespace client { Camera::Mode Camera::mode = Camera::Track; const float Camera::track_pitch = -15.0f; // default tracking pitch const float Camera::offset_inc = 5.0f; // default offset increment float Camera::yaw = 0; // current yaw, angle in XZ plane, positive is looking left float Camera::yaw_target = 0; // target yaw float Camera::pitch = -45.0f; // current pitch, angle in XY, positive is looking up float Camera::pitch_target = Camera::track_pitch; // target pitch float Camera::distance = 0.4f; // distance from the eye to the target void Camera::draw(float elapsed) { if (mode == Track) { yaw_target = game::ship.yaw; } // adjust yaw float d = degreesf(yaw - yaw_target); yaw = degreesf( yaw - d * elapsed) ; // adjust pitch target d = degreesf(pitch - pitch_target); pitch = degreesf( pitch - d *elapsed); switch (mode) { case Free: gl::translate(1.0f+distance, -distance, 0.0f); gl::rotate(-pitch, 0, 0, 1.0f); gl::rotate(-yaw, 0, 1.0f, 0); break; case Track: gl::translate(1.0f+distance, -distance , 0.0f); gl::rotate(-pitch, 0, 0, 1.0f); gl::rotate(-yaw, 0, 1.0f, 0); break; default: break; } } void Camera::rotate_right() { if (mode == Free ) { yaw_target = degreesf( yaw_target + offset_inc); } } void Camera::rotate_left() { if (mode == Free ) { yaw_target = degreesf( yaw_target - offset_inc); } } void Camera::rotate_up() { if (mode == Free ) { pitch_target = pitch_target - offset_inc; if (pitch_target < -90.0f) pitch_target = -90.0f; } } void Camera::rotate_down() { if (mode == Free ) { pitch_target = pitch_target + offset_inc; if (pitch_target > 90.0f) pitch_target = 90.0f; } } void Camera::nextmode() { switch(mode) { case Free: // switch camera to Track mode mode = Track; yaw_target = game::ship.yaw; yaw = yaw_target; pitch_target = track_pitch; pitch = pitch_target; break; case Track: // switch camera to Free mode mode = Free; yaw_target = game::ship.yaw; yaw = yaw_target; pitch_target = track_pitch; pitch = pitch_target; break; default: break; } } } //namespace camera