draw aircraft
This commit is contained in:
@@ -4,3 +4,4 @@ constexpr char* user_agent = "p-rad/0.1";
|
||||
|
||||
|
||||
|
||||
#define ARRAY_LENGHT(arr) sizeof(arr) / sizeof(arr[0])
|
||||
@@ -0,0 +1,16 @@
|
||||
#include <GeographicLib/Geodesic.hpp>
|
||||
#include <cmath>
|
||||
#include <tuple>
|
||||
#include "global.hpp"
|
||||
std::tuple<float, float> get_offset_from_station(double lat, double lon) {
|
||||
const GeographicLib::Geodesic &geod = GeographicLib::Geodesic::WGS84();
|
||||
|
||||
double distance, azi1, azi2;
|
||||
geod.Inverse(receiver_lat, receiver_lon, lat, lon, distance, azi1,
|
||||
azi2);
|
||||
|
||||
double azi_rad = azi1 * M_PI / 180.0;
|
||||
|
||||
|
||||
return {static_cast<float>(distance * std::sin(azi_rad)),static_cast<float>(-distance * std::cos(azi_rad))};
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
#include <tuple>
|
||||
std::tuple<float, float> get_offset_from_station(double lat, double lon);
|
||||
@@ -0,0 +1,2 @@
|
||||
float receiver_lat;
|
||||
float receiver_lon;
|
||||
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
extern float receiver_lat;
|
||||
extern float receiver_lon;
|
||||
@@ -18,4 +18,5 @@ struct rect_t {
|
||||
void pixel(const uint16_t x, const uint16_t y, const color_t color);
|
||||
void filled_rect(const rect_t* rect, const color_t color);
|
||||
void circle(const uint16_t x_center, const uint16_t y_center,const uint16_t radius, const color_t color);
|
||||
void rhombus(const uint16_t x_center, const uint16_t y_center,const uint16_t radius, const color_t color);
|
||||
}
|
||||
@@ -142,6 +142,13 @@ void circle(const uint16_t x_center, const uint16_t y_center,const uint16_t radi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rhombus(const uint16_t x_center, const uint16_t y_center,const uint16_t radius, const color_t color) {
|
||||
SDL_SetRenderDrawColor(main_sdl_session.renderer, color.r, color.g, color.b,
|
||||
0xff);
|
||||
const SDL_FPoint points[] = {{static_cast<float>(x_center+radius),static_cast<float>(y_center)},{static_cast<float>(x_center),static_cast<float>(y_center+radius)},{static_cast<float>(x_center-radius),static_cast<float>(y_center)},{static_cast<float>(x_center),static_cast<float>(y_center-radius)},{static_cast<float>(x_center+radius),static_cast<float>(y_center)}};
|
||||
SDL_RenderLines(main_sdl_session.renderer, points, ARRAY_LENGHT(points));
|
||||
}
|
||||
} // namespace draw
|
||||
|
||||
namespace net {
|
||||
|
||||
+23
-2
@@ -10,6 +10,8 @@
|
||||
#include <cstdio>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include "core/global.hpp"
|
||||
#include "core/geo.hpp"
|
||||
|
||||
int main() {
|
||||
if (hal::init() != 0) {
|
||||
@@ -24,8 +26,6 @@ int main() {
|
||||
|
||||
const uint16_t middle_x = (screen_w / 2);
|
||||
const uint16_t middle_y = (screen_h / 2);
|
||||
float receiver_lat;
|
||||
float receiver_lon;
|
||||
{
|
||||
nlohmann::json receiver =
|
||||
net::http_get_json(std::format("{}/receiver.json", base_url));
|
||||
@@ -72,6 +72,27 @@ int main() {
|
||||
}
|
||||
}
|
||||
|
||||
{ // draw planes
|
||||
nlohmann::json aircraft = net::http_get_json(std::format("{}/aircraft.json", base_url));
|
||||
if (aircraft!= nullptr) {
|
||||
for(nlohmann::json &craft : aircraft["aircraft"]) {
|
||||
try {
|
||||
const auto [x_offset,y_offset] = get_offset_from_station(craft["lat"].get<double>(), craft["lon"].get<double>());
|
||||
const uint16_t x_center = middle_x+((x_offset/1000)*pixels_per_km);
|
||||
const uint16_t y_center = middle_y+((y_offset/1000)*pixels_per_km);
|
||||
draw::pixel(x_center, y_center, {0xff,0x68,0x00});
|
||||
draw::rhombus(x_center, y_center, 8/*TODO: remove magic*/,{0xff,0x68,0x00});
|
||||
} catch(...) {
|
||||
std::clog << YELLOW"[WARNING]" RESET " aircraft with no lat/lon data detected!\n";
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
// TODO draw vizual error
|
||||
std::cerr << RED"[ERROR]" RESET " failed to get aircraft\n";
|
||||
}
|
||||
}
|
||||
|
||||
hal::end_frame();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user