diff options
author | SmallJoker <SmallJoker@users.noreply.github.com> | 2020-04-16 18:32:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-16 18:32:07 +0200 |
commit | 45999b74e610b13e8cda20c0c420e152b9837ea6 (patch) | |
tree | 5c82a99433496ce5cf15c24da30beb66bf7ff100 /src/client/game.cpp | |
parent | 5cbe8437a8f7efc9c76baf23de700e96ad96b385 (diff) | |
download | minetest-45999b74e610b13e8cda20c0c420e152b9837ea6.tar.gz minetest-45999b74e610b13e8cda20c0c420e152b9837ea6.tar.bz2 minetest-45999b74e610b13e8cda20c0c420e152b9837ea6.zip |
Camera: Fix shooting line offsets (#9681)
Removes duplicated offset calculations from Game and use whatever the Camera class returns.
This keeps the eye position nicely in sync, and gets rid of duplicated code.
Diffstat (limited to 'src/client/game.cpp')
-rw-r--r-- | src/client/game.cpp | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/src/client/game.cpp b/src/client/game.cpp index f7234eea6..4b2d7c652 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -3029,16 +3029,9 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) { LocalPlayer *player = client->getEnv().getLocalPlayer(); - v3f player_position = player->getPosition(); - v3f player_eye_position = player->getEyePosition(); - v3f camera_position = camera->getPosition(); - v3f camera_direction = camera->getDirection(); - v3s16 camera_offset = camera->getOffset(); - - if (camera->getCameraMode() == CAMERA_MODE_FIRST) - player_eye_position += player->eye_offset_first; - else - player_eye_position += player->eye_offset_third; + const v3f head_position = camera->getHeadPosition(); + const v3f camera_direction = camera->getDirection(); + const v3s16 camera_offset = camera->getOffset(); /* Calculate what block is the crosshair pointing to @@ -3053,11 +3046,11 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) core::line3d<f32> shootline; if (camera->getCameraMode() != CAMERA_MODE_THIRD_FRONT) { - shootline = core::line3d<f32>(player_eye_position, - player_eye_position + camera_direction * BS * d); + shootline = core::line3d<f32>(head_position, + head_position + camera_direction * BS * d); } else { // prevent player pointing anything in front-view - shootline = core::line3d<f32>(camera_position, camera_position); + shootline = core::line3d<f32>(head_position, head_position); } #ifdef HAVE_TOUCHSCREENGUI @@ -3145,6 +3138,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug) } else if (pointed.type == POINTEDTHING_NODE) { handlePointingAtNode(pointed, selected_item, hand_item, dtime); } else if (pointed.type == POINTEDTHING_OBJECT) { + v3f player_position = player->getPosition(); handlePointingAtObject(pointed, tool_item, player_position, show_debug); } else if (input->getLeftState()) { // When button is held down in air, show continuous animation |