X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fui%2Fui.cpp;h=048aed1ac81559e21e2eee740d90a195bf5df22b;hb=7f15e27277382f0176a23dd21702f9d113581763;hp=e7e6b0c7725a36264222a08633119d4f443ba6d2;hpb=75172fd735e34082c34b47ae7c194445b53038d9;p=blank.git diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index e7e6b0c..048aed1 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -37,8 +37,6 @@ PlayerController::PlayerController(World &world, Player &player) : world(world) , player(player) , move_dir(0.0f) -, pitch(0.0f) -, yaw(0.0f) , dirty(true) , aim_world() , aim_entity() { @@ -55,19 +53,15 @@ void PlayerController::SetMovement(const glm::vec3 &m) noexcept { } void PlayerController::TurnHead(float dp, float dy) noexcept { - pitch += dp; - if (pitch > PI / 2) { - pitch = PI / 2; - } else if (pitch < -PI / 2) { - pitch = -PI / 2; - } - yaw += dy; - if (yaw > PI) { - yaw -= PI * 2; - } else if (yaw < -PI) { - yaw += PI * 2; - } - Invalidate(); + player.GetEntity().TurnHead(dp, dy); +} + +float PlayerController::GetPitch() const noexcept { + return player.GetEntity().Pitch(); +} + +float PlayerController::GetYaw() const noexcept { + return player.GetEntity().Yaw(); } void PlayerController::SelectInventory(int i) noexcept { @@ -85,9 +79,7 @@ void PlayerController::Invalidate() noexcept { void PlayerController::UpdatePlayer() noexcept { constexpr float max_vel = 5.0f; // in m/s if (dirty) { - player.GetEntity().Orientation(glm::quat(glm::vec3(0.0f, yaw, 0.0f))); - player.GetEntity().GetModel().EyesState().orientation = glm::quat(glm::vec3(pitch, 0.0f, 0.0f)); - player.GetEntity().TargetVelocity(glm::rotateY(move_dir * max_vel, yaw)); + player.GetEntity().TargetVelocity(glm::rotateY(move_dir * max_vel, player.GetEntity().Yaw())); Ray aim = player.Aim(); if (!world.Intersection(aim, glm::mat4(1.0f), player.GetEntity().ChunkCoords(), aim_world)) { @@ -212,8 +204,11 @@ HUD::HUD(Environment &env, Config &config, const Player &player) // message box , messages(env.assets.small_ui_font) , msg_timer(5000) +, msg_keep(false) // crosshair , crosshair() { + const float ls = env.assets.small_ui_font.LineSkip(); + // "inventory" block_transform = glm::translate(block_transform, glm::vec3(50.0f, 50.0f, 0.0f)); block_transform = glm::scale(block_transform, glm::vec3(50.0f)); @@ -231,23 +226,23 @@ HUD::HUD(Environment &env, Config &config, const Player &player) counter_text.Position(glm::vec3(-25.0f, 25.0f, 0.0f), Gravity::NORTH_EAST); counter_text.Foreground(glm::vec4(1.0f)); counter_text.Background(glm::vec4(0.5f)); - position_text.Position(glm::vec3(-25.0f, 25.0f + env.assets.small_ui_font.LineSkip(), 0.0f), Gravity::NORTH_EAST); + position_text.Position(glm::vec3(-25.0f, 25.0f + ls, 0.0f), Gravity::NORTH_EAST); position_text.Foreground(glm::vec4(1.0f)); position_text.Background(glm::vec4(0.5f)); - orientation_text.Position(glm::vec3(-25.0f, 25.0f + 2 * env.assets.small_ui_font.LineSkip(), 0.0f), Gravity::NORTH_EAST); + orientation_text.Position(glm::vec3(-25.0f, 25.0f + 2 * ls, 0.0f), Gravity::NORTH_EAST); orientation_text.Foreground(glm::vec4(1.0f)); orientation_text.Background(glm::vec4(0.5f)); - block_text.Position(glm::vec3(-25.0f, 25.0f + 4 * env.assets.small_ui_font.LineSkip(), 0.0f), Gravity::NORTH_EAST); + block_text.Position(glm::vec3(-25.0f, 25.0f + 4 * ls, 0.0f), Gravity::NORTH_EAST); block_text.Foreground(glm::vec4(1.0f)); block_text.Background(glm::vec4(0.5f)); block_text.Set(env.assets.small_ui_font, "Block: none"); - entity_text.Position(glm::vec3(-25.0f, 25.0f + 4 * env.assets.small_ui_font.LineSkip(), 0.0f), Gravity::NORTH_EAST); + entity_text.Position(glm::vec3(-25.0f, 25.0f + 4 * ls, 0.0f), Gravity::NORTH_EAST); entity_text.Foreground(glm::vec4(1.0f)); entity_text.Background(glm::vec4(0.5f)); entity_text.Set(env.assets.small_ui_font, "Entity: none"); // message box - messages.Position(glm::vec3(25.0f, -25.0f, 0.0f), Gravity::SOUTH_WEST); + messages.Position(glm::vec3(25.0f, -25.0f - 2 * ls, 0.0f), Gravity::SOUTH_WEST); messages.Foreground(glm::vec4(1.0f)); messages.Background(glm::vec4(0.5f)); @@ -400,7 +395,7 @@ void HUD::Render(Viewport &viewport) noexcept { } // message box - if (msg_timer.Running()) { + if (msg_keep || msg_timer.Running()) { messages.Render(viewport); }