]> git.localhorst.tv Git - blank.git/blobdiff - src/ui/ui.cpp
show player orientation in debug overlay
[blank.git] / src / ui / ui.cpp
index 0c89a2f3a554ab6c0347ed669bdd71d801dea22a..6dfe5160dd87417204037e4dad75ca8c5903e658 100644 (file)
@@ -72,17 +72,18 @@ void HUD::Display(const Block &b) {
 void HUD::Render(Viewport &viewport) noexcept {
        viewport.ClearDepth();
 
-       DirectionalLighting &world_prog = viewport.HUDProgram();
-       world_prog.SetLightDirection({ 1.0f, 3.0f, 5.0f });
-       // disable distance fog
-       world_prog.SetFogDensity(0.0f);
-
+       PlainColor &outline_prog = viewport.HUDOutlineProgram();
        viewport.EnableInvertBlending();
        viewport.SetCursor(glm::vec3(0.0f), Gravity::CENTER);
-       world_prog.SetM(viewport.Cursor());
+       outline_prog.SetM(viewport.Cursor());
        crosshair.Draw();
 
        if (block_visible) {
+               DirectionalLighting &world_prog = viewport.HUDProgram();
+               world_prog.SetLightDirection({ 1.0f, 3.0f, 5.0f });
+               // disable distance fog
+               world_prog.SetFogDensity(0.0f);
+
                viewport.DisableBlending();
                world_prog.SetM(block_transform);
                block.Draw();
@@ -98,8 +99,7 @@ Interface::Interface(
 : env(env)
 , world(world)
 , ctrl(world.Player())
-, font(env.assets.LoadFont("DejaVuSans", 16))
-, hud(world.BlockTypes(), font)
+, hud(world.BlockTypes(), env.assets.small_ui_font)
 , aim{{ 0, 0, 0 }, { 0, 0, -1 }}
 , aim_chunk(nullptr)
 , aim_block(0)
@@ -107,7 +107,9 @@ Interface::Interface(
 , outline()
 , outline_transform(1.0f)
 , counter_text()
-, messages(font)
+, position_text()
+, orientation_text()
+, messages(env.assets.small_ui_font)
 , msg_timer(5000)
 , config(config)
 , place_timer(256)
@@ -117,15 +119,17 @@ Interface::Interface(
 , place_sound(env.assets.LoadSound("thump"))
 , remove_sound(env.assets.LoadSound("plop"))
 , fwd(0)
-, rev(0) {
-       counter_text.Hide();
+, rev(0)
+, debug(false) {
        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.Hide();
-       position_text.Position(glm::vec3(-25.0f, 25.0f + font.LineSkip(), 0.0f), Gravity::NORTH_EAST);
+       position_text.Position(glm::vec3(-25.0f, 25.0f + env.assets.small_ui_font.LineSkip(), 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.Foreground(glm::vec4(1.0f));
+       orientation_text.Background(glm::vec4(0.5f));
        messages.Position(glm::vec3(25.0f, -25.0f, 0.0f), Gravity::SOUTH_WEST);
        messages.Foreground(glm::vec4(1.0f));
        messages.Background(glm::vec4(0.5f));
@@ -341,11 +345,11 @@ void Interface::ToggleVisual() {
 }
 
 void Interface::ToggleDebug() {
-       counter_text.Toggle();
-       position_text.Toggle();
-       if (counter_text.Visible()) {
+       debug = !debug;
+       if (debug) {
                UpdateCounter();
                UpdatePosition();
+               UpdateOrientation();
        }
 }
 
@@ -355,13 +359,20 @@ void Interface::UpdateCounter() {
                "avg: " << env.counter.Average().running << "ms, "
                "peak: " << env.counter.Peak().running << "ms";
        std::string text = s.str();
-       counter_text.Set(font, text);
+       counter_text.Set(env.assets.small_ui_font, text);
 }
 
 void Interface::UpdatePosition() {
        std::stringstream s;
        s << std::setprecision(3) << "pos: " << ctrl.Controlled().AbsolutePosition();
-       position_text.Set(font, s.str());
+       position_text.Set(env.assets.small_ui_font, s.str());
+}
+
+void Interface::UpdateOrientation() {
+       std::stringstream s;
+       s << std::setprecision(3) << "pitch: " << rad2deg(ctrl.Pitch())
+               << ", yaw: " << rad2deg(ctrl.Yaw());
+       orientation_text.Set(env.assets.small_ui_font, s.str());
 }
 
 
@@ -492,11 +503,12 @@ void Interface::Update(int dt) {
                CheckAim();
        }
 
-       if (counter_text.Visible() && env.counter.Changed()) {
-               UpdateCounter();
-       }
-       if (position_text.Visible()) {
+       if (debug) {
+               if (env.counter.Changed()) {
+                       UpdateCounter();
+               }
                UpdatePosition();
+               UpdateOrientation();
        }
 }
 
@@ -512,9 +524,9 @@ void Interface::CheckAim() {
                outl_buf.Clear();
                aim_chunk->Type(aim_chunk->BlockAt(aim_block)).FillOutlineModel(outl_buf);
                outline.Update(outl_buf);
-               outline_transform = glm::scale(glm::vec3(1.0002f));
-               outline_transform *= aim_chunk->Transform(world.Player().ChunkCoords());
+               outline_transform = aim_chunk->Transform(world.Player().ChunkCoords());
                outline_transform *= aim_chunk->ToTransform(Chunk::ToPos(aim_block), aim_block);
+               outline_transform *= glm::scale(glm::vec3(1.005f));
        } else {
                aim_chunk = nullptr;
        }
@@ -525,16 +537,15 @@ void Interface::Render(Viewport &viewport) noexcept {
        if (config.visual_disabled) return;
 
        if (aim_chunk) {
-               DirectionalLighting &world_prog = viewport.EntityProgram();
-               world_prog.SetM(outline_transform);
+               PlainColor &outline_prog = viewport.WorldOutlineProgram();
+               outline_prog.SetM(outline_transform);
                outline.Draw();
        }
 
-       if (counter_text.Visible()) {
+       if (debug) {
                counter_text.Render(viewport);
-       }
-       if (position_text.Visible()) {
                position_text.Render(viewport);
+               orientation_text.Render(viewport);
        }
 
        if (msg_timer.Running()) {