]> git.lizzy.rs Git - dragonblocks_alpha.git/commitdiff
Add position display
authorElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 16 Jul 2021 17:37:30 +0000 (19:37 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Fri, 16 Jul 2021 17:37:30 +0000 (19:37 +0200)
src/client/client_player.c
src/client/client_player.h

index e4a3a6c744d98a9b65c75c62f7053d52ae4154dd..0fdd10223b9cd543821142e299f63efd851b8eb5 100644 (file)
@@ -1,3 +1,4 @@
+#include <stdio.h>
 #include "client/camera.h"
 #include "client/client.h"
 #include "client/client_player.h"
@@ -13,6 +14,11 @@ static void update_pos()
 
        client_player.obj->pos = client_player.pos;
        object_transform(client_player.obj);
+
+       char pos_text[BUFSIZ];
+       sprintf(pos_text, "(%.1f %.1f %.1f)", client_player.pos.x, client_player.pos.y, client_player.pos.z);
+
+       hud_change_text(client_player.pos_display, pos_text);
 }
 
 void client_player_init(Map *map)
@@ -41,6 +47,18 @@ void client_player_add_to_scene()
                }
        }
 
+       client_player.pos_display = hud_add((HUDElementDefinition) {
+               .type = HUD_TEXT,
+               .pos = {-1.0f, -1.0f, 0.0f},
+               .offset = {2, 2 + 16 + 2 + 16 + 2},
+               .type_def = {
+                       .text = {
+                               .text = "",
+                               .color = {1.0f, 1.0f, 1.0f},
+                       },
+               },
+       });
+
        update_pos();
 }
 
index 890ff2dc72a5d1531125ba6447ed9fc1b22094d4..9d5d16f1aa776b4b549c2e0b99e05a3cfedb07bd 100644 (file)
@@ -2,6 +2,7 @@
 #define _CLIENT_PLAYER_H_
 
 #include "client/client.h"
+#include "client/hud.h"
 #include "client/object.h"
 #include "types.h"
 
@@ -14,6 +15,7 @@ extern struct ClientPlayer
        f32 eye_height;
        Object *obj;
        Map *map;
+       HUDElement *pos_display;
 } client_player;
 
 void client_player_init(Map *map);