From 7492187ad2e16c7398ca4ed812a57045c3d42d68 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sat, 3 Feb 2018 22:42:25 +0500 Subject: Block selection implemented with mouse-look --- src/GameState.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/GameState.cpp') diff --git a/src/GameState.cpp b/src/GameState.cpp index 20926e0..650cd6f 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -27,7 +27,16 @@ void GameState::Update(float deltaTime) { PUSH_EVENT("SendPacket",packet); } - selectedBlock = Vector(Vector(player->pos.x,player->pos.y,player->pos.z) - Vector(-1,0,0)); + + double playerYaw = Entity::DecodeYaw(player->yaw); + double playerPitch = Entity::DecodePitch(player->pitch); + + glm::vec3 direction; + direction.x = cos(glm::radians(playerYaw)) * cos(glm::radians(playerPitch)); + direction.y = sin(glm::radians(playerPitch)); + direction.z = sin(glm::radians(playerYaw)) * cos(glm::radians(playerPitch)); + + selectedBlock = world.Raycast(player->pos + player->EyeOffset, direction, distanceToSelectedBlock); } } @@ -404,7 +413,7 @@ void GameState::HandleMovement(GameState::Direction direction, float deltaTime) const double playerSpeed = 43; float velocity = playerSpeed * deltaTime; - + double playerYaw = Entity::DecodeYaw(player->yaw); double playerPitch = Entity::DecodePitch(player->pitch); -- cgit v1.2.3