trying stuff
This commit is contained in:
26
src/coords.c
26
src/coords.c
@@ -33,19 +33,39 @@ void compute_decimal_coords(struct IGC_DataPoint* dp)
|
||||
dp->lat.decimal = lat;
|
||||
dp->lon.decimal = lon;
|
||||
|
||||
printf("DEBUG: %lf, %lf\n", dp->lat.decimal, dp->lon.decimal);
|
||||
//printf("DEBUG: %lf, %lf\n", dp->lat.decimal, dp->lon.decimal);
|
||||
}
|
||||
|
||||
void compute_cartesian_coords(struct IGC_DataPoint* dp)
|
||||
{
|
||||
double rad_lat = dp->lat.decimal*(M_PI/180.0);
|
||||
double rad_lon = dp->lon.decimal*(M_PI/180.0);
|
||||
printf("DEBUG: %lf, %lf\n", rad_lat, rad_lon);
|
||||
//printf("DEBUG: %lf, %lf\n", rad_lat, rad_lon);
|
||||
|
||||
double x = EARTH_RADIUS * cos(rad_lat) * cos(rad_lon);
|
||||
double y = EARTH_RADIUS * cos(rad_lat) * sin(rad_lon);
|
||||
|
||||
dp->lon.meters = x;
|
||||
dp->lat.meters = y;
|
||||
printf("DEBUG: x=%lf, y=%lf\n", x, y);
|
||||
//printf("DEBUG: x=%lf, y=%lf\n", x, y);
|
||||
}
|
||||
|
||||
void compute_world_coords(struct IGC_DataPoint* first, struct IGC_DataPoint* dp)
|
||||
{
|
||||
// Get base point (1st element)
|
||||
// All other coords will be derived according to the base point which will be mapped to pos (0,0,0)
|
||||
double base_y = first->lat.meters;
|
||||
double base_x = first->lon.meters;
|
||||
double base_z = first->gps_alt;
|
||||
|
||||
// Get datapoint cartesian coords
|
||||
double x = dp->lon.meters;
|
||||
double y = dp->lat.meters;
|
||||
double z = dp->gps_alt;
|
||||
|
||||
// Compute current datapoint world coords as offset from base point
|
||||
Vector3 current = {x-base_x, y-base_y, z-base_z};
|
||||
dp->w_coords = current;
|
||||
printf("DEBUG: dp->w_coords = {x=%lf, y=%lf, z=%lf}; dp->meters = {lon=%lf, lat=%lf, gps_alt=%d\n", dp->w_coords.x, dp->w_coords.y, dp->w_coords.z, dp->lon.meters, dp->lat.meters, dp->gps_alt);
|
||||
|
||||
}
|
||||
|
||||
@@ -14,5 +14,6 @@
|
||||
|
||||
void compute_decimal_coords(struct IGC_DataPoint* dp);
|
||||
void compute_cartesian_coords(struct IGC_DataPoint* dp);
|
||||
void compute_world_coords(struct IGC_DataPoint* first, struct IGC_DataPoint* dp);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
*/
|
||||
|
||||
#include "raylib.h"
|
||||
#include "igc.h"
|
||||
|
||||
void start_graphics()
|
||||
void start_graphics(struct dp_node* list)
|
||||
{
|
||||
SetTraceLogLevel(4);
|
||||
const int screenWidth = 800;
|
||||
@@ -43,7 +44,8 @@ void start_graphics()
|
||||
|
||||
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
||||
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
|
||||
DrawGrid(10, 1.0f);
|
||||
|
||||
DrawGrid(1000, 1.0f);
|
||||
|
||||
EndMode3D();
|
||||
DrawText("3rd Dimension", 10, 40, 20, DARKGRAY);
|
||||
|
||||
@@ -12,6 +12,6 @@
|
||||
#ifndef GRAPHICS_H
|
||||
#define GRAPHICS_H
|
||||
|
||||
void start_graphics();
|
||||
void start_graphics(struct dp_node* list);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -59,8 +59,6 @@ struct IGC_DataPoint* parse_datapoint(char* line)
|
||||
void show_datapoint(struct IGC_DataPoint* dp)
|
||||
{
|
||||
printf("Data point: %02d:%02d:%02d | %d°%d'%d\"%c %d°%d'%d\"%c | Baro: %dm GPS: %dm\n", dp->hour, dp->minute, dp->second, dp->lat.deg, dp->lat.min, dp->lat.sec, dp->lat.cardinal, dp->lon.deg, dp->lon.min, dp->lon.sec, dp->lon.cardinal, dp->baro_alt, dp->gps_alt);
|
||||
compute_decimal_coords(dp);
|
||||
compute_cartesian_coords(dp);
|
||||
}
|
||||
|
||||
void show_header_info(struct IGC_Header* hdr)
|
||||
@@ -131,6 +129,8 @@ void parse_igc_file(FILE* fp, struct IGC_Header* hdr, struct dp_node* list)
|
||||
struct IGC_DataPoint* dp = parse_datapoint(line);
|
||||
//show_datapoint(dp);
|
||||
// Doubly linked list of points (so theyre joined in chronological order; opens possibilities for analysis later)
|
||||
compute_decimal_coords(dp);
|
||||
compute_cartesian_coords(dp);
|
||||
append_datapoint(list, dp);
|
||||
break;
|
||||
case HEADER:
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include "linkage.h"
|
||||
#include "raylib.h"
|
||||
|
||||
enum IGC_RecordType
|
||||
{
|
||||
@@ -89,6 +90,9 @@ struct IGC_DataPoint
|
||||
// altitude
|
||||
int baro_alt;
|
||||
int gps_alt;
|
||||
|
||||
// world coordinates (Raylib world units)
|
||||
Vector3 w_coords;
|
||||
};
|
||||
|
||||
void parse_igc_file(FILE* fp, struct IGC_Header* hdr, struct dp_node* list);
|
||||
|
||||
11
src/main.c
11
src/main.c
@@ -16,6 +16,7 @@
|
||||
#include "igc.h"
|
||||
#include "linkage.h"
|
||||
#include "graphics.h"
|
||||
#include "coords.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
@@ -42,7 +43,15 @@ int main(int argc, char* argv[])
|
||||
|
||||
print_datapoint_list(head);
|
||||
|
||||
start_graphics();
|
||||
struct dp_node* base = head->next;
|
||||
struct dp_node* current = head->next;
|
||||
while (current->next != NULL)
|
||||
{
|
||||
compute_world_coords(base->data, current->data);
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
start_graphics(head);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user