diff options
Diffstat (limited to 'src/client/camera.cc')
-rw-r--r-- | src/client/camera.cc | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/src/client/camera.cc b/src/client/camera.cc index 2def781..85929cc 100644 --- a/src/client/camera.cc +++ b/src/client/camera.cc @@ -4,10 +4,11 @@ the terms and conditions of the GNU General Public License version 2 */ +#include "math/mathlib.h" +#include "core/player.h" #include "client/client.h" #include "client/camera.h" #include "render/render.h" -#include "math/mathlib.h" using math::degrees360f; using math::degrees180f; @@ -78,18 +79,32 @@ void shutdown() void draw(float elapsed) { - // TODO camera needs to get this from selected core entity + if (!core::localplayer.controled) { + // switch the camera to Overview of the player is not controling anything + if (mode != Overview) { + mode = Overview; + target = math::Vector3f(0,0,0); + x_offset = 0; + z_offset = 0; + distance = 20.0f; + } + } else { + camera::target = core::localplayer.controled->location; + } + if (mode == Track) { - yaw_target = game.ship->yaw(); + yaw_target = core::localplayer.controled->direction; } - // adjust yaw - float d = degrees180f(yaw_current - yaw_target); - yaw_current = degrees360f( yaw_current - d * elapsed) ; + 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); + // adjust pitch target + d = degrees180f(pitch_current - pitch_target); + pitch_current = degrees360f( pitch_current - d *elapsed); + } switch (mode) { case Free: @@ -154,11 +169,20 @@ void key_down() } void next_mode() { + + if (!core::localplayer.controled) { + mode = Overview; + target = math::Vector3f(0,0,0); + x_offset = 0; + z_offset = 0; + distance = 20.0f; + } + switch(mode) { case Overview: // switch camera to Track mode mode = Track; - yaw_target = game.ship->yaw(); + yaw_target = core::localplayer.controled->direction; yaw_current = yaw_target; pitch_target = pitch_track; pitch_current = pitch_target; @@ -167,7 +191,7 @@ void next_mode() { case Track: // switch camera to Free mode mode = Free; - yaw_target = game.ship->yaw(); + yaw_target = core::localplayer.controled->direction; yaw_current = yaw_target; pitch_target = pitch_track; pitch_current = pitch_target; |