From 4e7f79dadc97453c818bb3a840b730f7e358086c Mon Sep 17 00:00:00 2001 From: Diogo Cruz Diniz Date: Thu, 23 Apr 2026 22:49:05 +0100 Subject: [PATCH] feat: More info drawn --- src/dxd_math.cpp | 5 +++++ src/dxd_math.hpp | 1 + src/main.cpp | 6 +++--- src/renderer.hpp | 21 ++++++++++++++++++--- src/sim/af_spawner.cpp | 2 +- src/sim/aircraft.cpp | 11 +++++++++-- src/sim/aircraft.hpp | 3 ++- src/sim/aircraft_trail.cpp | 2 +- src/sim/airfield.cpp | 4 ++-- 9 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/dxd_math.cpp b/src/dxd_math.cpp index ed38a93..96f88a9 100644 --- a/src/dxd_math.cpp +++ b/src/dxd_math.cpp @@ -122,6 +122,11 @@ float normalize_angle_diff(const float diff) return d; } +float angle_to_heading(float const angle) +{ + return normalize_angle(angle) * 180.0f / M_PIf; +} + int rand_int(int const min, int const max) { return SDL_rand(max - min) + min; diff --git a/src/dxd_math.hpp b/src/dxd_math.hpp index 186644c..8046713 100644 --- a/src/dxd_math.hpp +++ b/src/dxd_math.hpp @@ -47,6 +47,7 @@ vec2 v2i_to_v2(vec2i const v); // Angle functions float normalize_angle(float const angle); float normalize_angle_diff(float const diff); +float angle_to_heading(float const angle); // Random generation functions int rand_int(int const min, int const max); diff --git a/src/main.cpp b/src/main.cpp index 6eed697..2f0d525 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) if (key_states[SDL_SCANCODE_E]) renderer.zoom_camera(-zoom_spd * (1.0f / 60.0f)); // Clear - renderer.color(0, 0, 0, 255); + renderer.color(0, 0, 0); SDL_RenderClear(sdl_renderer); // World draw @@ -80,14 +80,14 @@ int main(int argc, char *argv[]) world.tick(1.0f / 60.0f); // World axis - renderer.color(32, 32, 32, 255); + renderer.color(32, 32, 32); renderer.line(-vec2_unity * 2000, vec2_unity * 2000); renderer.line(-vec2_unitx * 2000, vec2_unitx * 2000); // Scale and position vec2 center = renderer.get_camera_pos(); float zoom = 100.0f/renderer.get_zoom(); - renderer.color(128, 128, 255, 255); + renderer.color(128, 128, 255); renderer.dbg_txt(0, 0, "(%0.1f, %0.1f) @%0.2f", center.x, center.y, zoom); SDL_RenderPresent(sdl_renderer); diff --git a/src/renderer.hpp b/src/renderer.hpp index 2e890e1..00f15b3 100644 --- a/src/renderer.hpp +++ b/src/renderer.hpp @@ -70,9 +70,9 @@ public: return 1.0f / _scale; } - void color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) + void color(uint8_t r, uint8_t g, uint8_t b) { - SDL_SetRenderDrawColor(_sdl, r, g, b, a); + SDL_SetRenderDrawColor(_sdl, r, g, b, 255); } void line(vec2 a, vec2 b) @@ -126,7 +126,7 @@ public: SDL_RenderLines(_sdl, points, 5); } - void dbg_txt(float x, float y, const char *fmt, ...) + void dbg_txt(float const x, float const y, const char *fmt, ...) { va_list args; va_start(args, fmt); @@ -135,6 +135,21 @@ public: va_end(args); } + + void txt(vec2 const pos, const char *fmt, ...) + { + va_list args; + va_start(args, fmt); + + char buf[128]; + + vsnprintf(buf, sizeof(buf), fmt, args); + + vec2 p = to_screenv2(to_viewv2(pos)); + SDL_RenderDebugText(_sdl, p.x, p.y, buf); + + va_end(args); + } }; } // namespace dxd diff --git a/src/sim/af_spawner.cpp b/src/sim/af_spawner.cpp index 72961a6..13532f1 100644 --- a/src/sim/af_spawner.cpp +++ b/src/sim/af_spawner.cpp @@ -27,6 +27,6 @@ void dxd::sim::AFSpawner::tick(float timestep, World *world) void dxd::sim::AFSpawner::draw(Renderer *rend) { - rend->color(0, 127, 0, 255); + rend->color(0, 127, 0); rend->rect(vec2_zero, _SPAWN_BOUNDS*2); } diff --git a/src/sim/aircraft.cpp b/src/sim/aircraft.cpp index 146f3e0..7f26a4b 100644 --- a/src/sim/aircraft.cpp +++ b/src/sim/aircraft.cpp @@ -23,10 +23,17 @@ void dxd::sim::Aircraft::tick(float timestep, World *world) void dxd::sim::Aircraft::draw(Renderer *rend) { - rend->color(255, 255, 255, 255); + // Indicator + rend->color(255, 255, 255); rend->box(_position, 1); rend->line(_position, _position + polar_to_vec2(_direction, 3)); - rend->color(255, 64, 64, 255); + // Status + rend->color(0, 255, 0); + rend->txt(_position - vec2_unity, "%03.0f", angle_to_heading(_direction)); + rend->txt(_position - vec2_unity*2.5f, "%03.0f", _speed * _SPD_TO_KTS); + + // Target + rend->color(255, 64, 64); rend->diamond(_target, 1); } diff --git a/src/sim/aircraft.hpp b/src/sim/aircraft.hpp index 4bb08a7..520dc15 100644 --- a/src/sim/aircraft.hpp +++ b/src/sim/aircraft.hpp @@ -15,9 +15,10 @@ private: vec2 _target; int _trail_cooldown; - const int _TRAIL_DELAY = 60; + const int _TRAIL_DELAY = 120; const int _TRAIL_DURATION = 420; const float _MAX_TURN_RATE = 0.3f; + const float _SPD_TO_KTS = 60.0f; public: Aircraft(vec2 position, float direction, float speed, vec2 target) diff --git a/src/sim/aircraft_trail.cpp b/src/sim/aircraft_trail.cpp index 54a6a2b..c6b4fcc 100644 --- a/src/sim/aircraft_trail.cpp +++ b/src/sim/aircraft_trail.cpp @@ -13,6 +13,6 @@ void dxd::sim::AircraftTrail::tick(float timestep, World *world) void dxd::sim::AircraftTrail::draw(Renderer *rend) { - rend->color(128, 128, 128, 255); + rend->color(128, 128, 128); rend->box(_position, .5); } diff --git a/src/sim/airfield.cpp b/src/sim/airfield.cpp index 0b90370..977c2d3 100644 --- a/src/sim/airfield.cpp +++ b/src/sim/airfield.cpp @@ -23,11 +23,11 @@ void dxd::sim::Airfield::tick(float timestep, World *world) void dxd::sim::Airfield::draw(Renderer *rend) { - rend->color(127, 127, 127, 255); + rend->color(127, 127, 127); rend->rect(_position, 5); rend->diamond(_position, 5); - rend->color(64, 64, 255, 255); + rend->color(64, 64, 255); vec2 a = _position + polar_to_vec2(_rw_heading, +_WR_LENGTH); vec2 b = _position + polar_to_vec2(_rw_heading, -_WR_LENGTH); rend->line(a, b);