From 248050533e5c6f9d373ecedb78a295acea48923e Mon Sep 17 00:00:00 2001 From: Wojciech Graj Date: Sun, 19 Mar 2023 22:32:33 +0100 Subject: [PATCH] Implement jumping to selected satellite. --- res/ui/ui.glade | 59 +++++++++++++++++++++++++++++++++++++++++++++ src/ui/info.c | 38 ++++++++++++++++++++++++++++- util/README_WIN.txt | 2 +- 3 files changed, 97 insertions(+), 2 deletions(-) diff --git a/res/ui/ui.glade b/res/ui/ui.glade index cd749a5..b6a2847 100644 --- a/res/ui/ui.glade +++ b/res/ui/ui.glade @@ -708,6 +708,65 @@ 1 + + + True + False + 0 + none + + + True + False + 12 + + + True + False + + + Jump to + True + False + True + True + + + + False + True + 0 + + + + + True + False + + + True + True + 1 + + + + + + + + + True + False + Actions + + + + + False + True + 2 + + 1 diff --git a/src/ui/info.c b/src/ui/info.c index b1b34de..6ec23d5 100644 --- a/src/ui/info.c +++ b/src/ui/info.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Wojciech Graj + * Copyright (c) 2022-2023 Wojciech Graj * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -14,6 +14,7 @@ #include "info.h" +#include "camera.h" #include "phys.h" #include "type.h" @@ -21,6 +22,7 @@ #include "satcat_code.h" #include #include +#include #include #include @@ -71,6 +73,9 @@ static const char *info_item_ids[] = { [INFO_VELOCITY] = "info_velocity", }; +static GtkButton *jump_to_button; + +static void on_info_jump_to_clicked(GtkButton *button, gpointer user_data); static void fmt_scdate(gchar *buf, gulong n, struct SCDate *date); static void fmt_coords(gchar *buf, gulong n, double x, double y, double z); @@ -82,6 +87,33 @@ void info_init(GtkBuilder *builder) unsigned i; for (i = 0; i < NUM_INFO_ITEMS; i++) info_items[i] = GTK_LABEL(gtk_builder_get_object(builder, info_item_ids[i])); + gtk_builder_add_callback_symbols(builder, + "on_info_jump_to_clicked", G_CALLBACK(on_info_jump_to_clicked), + NULL); + jump_to_button = GTK_BUTTON(gtk_builder_get_object(builder, "info_jump_to")); +} + +void on_info_jump_to_clicked(GtkButton *button, gpointer user_data) +{ + (void)button; + (void)user_data; + + double r[3], v[3]; + getRVForDate(&satellite->tle, e_phys.epoch_ms, r, v); + + mat3 t; + glm_vec3_copy((vec3){ 0.f, 0.f, 1.f }, t[2]); + glm_vec3_copy((vec3){ (float)cos(e_phys.gmst), (float)-sin(e_phys.gmst), 0.f }, t[0]); + glm_vec3_cross(t[2], t[0], t[1]); + glm_vec3_norm(t[1]); + glm_mat3_scale(t, 1.05f / 6371.f); + + vec3 pos; + glm_mat3_mulv(t, (vec3){ r[0], r[1], r[2] }, pos); + float rad = glm_vec3_norm(pos); + e_camera.rad = glm_clamp(rad, 1.1f, 10.f); + glm_vec3_scale(pos, e_camera.rad / rad, e_camera.pos); + camera_view_update(&e_camera); } void fmt_scdate(gchar *buf, gulong n, struct SCDate *date) @@ -118,6 +150,8 @@ void info_show(struct Satellite *sat) gtk_label_set_text(info_items[INFO_PERIGEE], buf); g_snprintf(buf, 11, "%08.4f", satellite->satcat.radar_cs); gtk_label_set_text(info_items[INFO_RADAR_CS], buf); + + gtk_widget_set_sensitive(GTK_WIDGET(jump_to_button), TRUE); } void info_hide(void) @@ -126,6 +160,8 @@ void info_hide(void) unsigned i; for (i = 0; i < NUM_INFO_ITEMS; i++) gtk_label_set_text(info_items[i], ""); + + gtk_widget_set_sensitive(GTK_WIDGET(jump_to_button), FALSE); } void fmt_coords(gchar *buf, gulong n, double x, double y, double z) diff --git a/util/README_WIN.txt b/util/README_WIN.txt index 1ffd5fa..4ba7866 100644 --- a/util/README_WIN.txt +++ b/util/README_WIN.txt @@ -1,6 +1,6 @@ To run the program, execute bin/orbvis.exe . A shortcut to this file can safely be created, but the executable cannot be removed from the surrounding directory structure. -Copyright (c) 2022 Wojciech Graj +Copyright (c) 2022-2023 Wojciech Graj This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License