From a1db9242ec491efdee70a7184aa61e861b17595a Mon Sep 17 00:00:00 2001 From: BlockMen Date: Wed, 8 Jan 2014 13:47:53 +0100 Subject: Add third person view --- src/game.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index f435a4d71..02308b65d 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -977,6 +977,8 @@ bool nodePlacementPrediction(Client &client, return false; } +bool is_third_person = false; + static void show_chat_menu(FormspecFormSource* current_formspec, TextDest* current_textdest, IWritableTextureSource* tsrc, IrrlichtDevice * device, Client* client, std::string text) @@ -1470,6 +1472,8 @@ void the_game(bool &kill, bool random_input, InputHandler *input, f32 camera_yaw = 0; // "right/left" f32 camera_pitch = 0; // "up/down" + int current_camera_mode = CAMERA_MODE_FIRST; // start in first-person view + /* Clouds */ @@ -2251,7 +2255,7 @@ void the_game(bool &kill, bool random_input, InputHandler *input, else{ s32 dx = input->getMousePos().X - displaycenter.X; s32 dy = input->getMousePos().Y - displaycenter.Y; - if(invert_mouse) + if(invert_mouse || player->camera_mode == CAMERA_MODE_THIRD_FRONT) dy = -dy; //infostream<<"window active, pos difference "<wasKeyDown(getKeySetting("keymap_camera_mode"))) { + + if (current_camera_mode == CAMERA_MODE_FIRST) + current_camera_mode = CAMERA_MODE_THIRD; + else if (current_camera_mode == CAMERA_MODE_THIRD) + current_camera_mode = CAMERA_MODE_THIRD_FRONT; + else + current_camera_mode = CAMERA_MODE_FIRST; + + } + player->camera_mode = current_camera_mode; tool_reload_ratio = MYMIN(tool_reload_ratio, 1.0); - camera.update(player, dtime, busytime, screensize, - tool_reload_ratio); + camera.update(player, dtime, busytime, screensize, tool_reload_ratio, + current_camera_mode, client.getEnv()); camera.step(dtime); v3f player_position = player->getPosition(); @@ -2717,6 +2733,10 @@ void the_game(bool &kill, bool random_input, InputHandler *input, core::line3d shootline(camera_position, camera_position + camera_direction * BS * (d+1)); + // prevent player pointing anything in front-view + if (current_camera_mode == CAMERA_MODE_THIRD_FRONT) + shootline = core::line3d(0,0,0,0,0,0); + ClientActiveObject *selected_object = NULL; PointedThing pointed = getPointedThing( @@ -3507,7 +3527,9 @@ void the_game(bool &kill, bool random_input, InputHandler *input, /* Wielded tool */ - if(show_hud && (player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE)) + if(show_hud && + (player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE) && + current_camera_mode < CAMERA_MODE_THIRD) { // Warning: This clears the Z buffer. camera.drawWieldedTool(); -- cgit v1.2.3