Skip to content

Commit

Permalink
Implement jumping to selected satellite.
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciech-graj committed Mar 19, 2023
1 parent fa3e362 commit 2480505
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 2 deletions.
59 changes: 59 additions & 0 deletions res/ui/ui.glade
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,65 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label-xalign">0</property>
<property name="shadow-type">none</property>
<child>
<object class="GtkAlignment">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="left-padding">12</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkButton" id="info_jump_to">
<property name="label" translatable="yes">Jump to</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="on_info_jump_to_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Actions</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
Expand Down
38 changes: 37 additions & 1 deletion src/ui/info.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,13 +14,15 @@

#include "info.h"

#include "camera.h"
#include "phys.h"
#include "type.h"

#include "TLE.h"
#include "satcat_code.h"
#include <cglm/mat3.h>
#include <cglm/mat4.h>
#include <cglm/util.h>
#include <cglm/vec2.h>
#include <cglm/vec3.h>

Expand Down Expand Up @@ -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);

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion util/README_WIN.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 2480505

Please sign in to comment.