2021-03-20 22:56:03 -04:00
|
|
|
#include "camera/Camera.h"
|
|
|
|
#include "Xml.h"
|
|
|
|
#include "Track.h"
|
2021-03-13 18:55:00 -05:00
|
|
|
|
2020-09-07 11:19:24 -04:00
|
|
|
#include <GL/glut.h>
|
|
|
|
|
|
|
|
#include <experimental/filesystem>
|
|
|
|
|
2021-03-20 22:56:03 -04:00
|
|
|
#include <syslog.h>
|
2020-09-07 11:19:24 -04:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
|
|
|
#include <math.h> // fmod
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 1.0}; /* Red diffuse light. */
|
|
|
|
GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0}; /* Infinite light location. */
|
|
|
|
|
2021-03-20 22:56:03 -04:00
|
|
|
Camera camera;
|
2021-03-13 18:55:00 -05:00
|
|
|
|
2020-09-07 11:19:24 -04:00
|
|
|
// TODO(dev):
|
|
|
|
// As per https://www.opengl.org/resources/libraries/glut/spec3/node11.html
|
|
|
|
// "Therefore, GLUT programs should not assume the window was created at the specified size or position.
|
|
|
|
// A GLUT program should use the window's reshape callback to determine the true size of the window."
|
|
|
|
|
2021-03-14 00:07:21 -05:00
|
|
|
void draw_origin()
|
|
|
|
{
|
|
|
|
// X:
|
2021-03-20 22:56:03 -04:00
|
|
|
glBegin(GL_LINE_STRIP);
|
|
|
|
glColor3d(0, 0, 0);
|
|
|
|
glVertex3f(-10.0f, 0.0f, 0.0f);
|
2021-03-14 00:07:21 -05:00
|
|
|
glColor3d(255, 0, 0);
|
2021-03-20 22:56:03 -04:00
|
|
|
glVertex3f(0.0f, 0.0f, 0.0f);
|
2021-03-14 00:07:21 -05:00
|
|
|
glColor3d(0, 0, 0);
|
|
|
|
glVertex3f(10.0f, 0.0f, 0.0f);
|
2021-03-20 22:56:03 -04:00
|
|
|
glEnd();
|
2021-03-14 00:07:21 -05:00
|
|
|
|
|
|
|
// Y:
|
2021-03-20 22:56:03 -04:00
|
|
|
glBegin(GL_LINE_STRIP);
|
|
|
|
glVertex3f(0.0f, -10.0f, 0.0f);
|
2021-03-14 00:07:21 -05:00
|
|
|
glColor3d(0, 255, 0);
|
2021-03-20 22:56:03 -04:00
|
|
|
glVertex3f(0.0f, 0.0f, 0.0f);
|
2021-03-14 00:07:21 -05:00
|
|
|
glColor3d(0, 0, 0);
|
|
|
|
glVertex3f(0.0f, 10.0f, 0.0f);
|
2021-03-20 22:56:03 -04:00
|
|
|
glEnd();
|
2021-03-14 00:07:21 -05:00
|
|
|
|
|
|
|
// Z:
|
2021-03-20 22:56:03 -04:00
|
|
|
glBegin(GL_LINE_STRIP);
|
2021-03-14 00:07:21 -05:00
|
|
|
glVertex3f(0.0f, 0.0f, -10.0f);
|
2021-03-20 22:56:03 -04:00
|
|
|
glColor3d(0, 0, 255);
|
|
|
|
glVertex3f(0.0f, 0.0f, 0.0f);
|
2021-03-14 00:07:21 -05:00
|
|
|
glColor3d(0, 0, 0);
|
|
|
|
glVertex3f(0.0f, 0.0f, 10.0f);
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2020-09-07 11:19:24 -04:00
|
|
|
void display()
|
|
|
|
{
|
2020-09-09 21:40:39 -04:00
|
|
|
// RESET:
|
2020-09-07 11:19:24 -04:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2020-09-09 21:40:39 -04:00
|
|
|
glLoadIdentity();
|
|
|
|
|
2021-03-20 22:56:03 -04:00
|
|
|
glLineWidth(1.0f);
|
|
|
|
|
|
|
|
//camera.RotateYaw(0.01);
|
|
|
|
|
2020-09-09 21:40:39 -04:00
|
|
|
static double asdf = -10.0;
|
2020-09-09 21:50:34 -04:00
|
|
|
asdf += 0.02;
|
|
|
|
if(asdf > 15.0)
|
|
|
|
asdf = -15.0;
|
2021-03-20 22:56:03 -04:00
|
|
|
gluLookAt(-15.0, 30.0, -asdf, /* eye is at */
|
|
|
|
0.0, 5.0, 0.0, /* center is at */
|
2020-09-09 21:40:39 -04:00
|
|
|
0.0, 1.0, 0.0); /* up is in positive Y direction */
|
|
|
|
|
2021-03-14 00:07:21 -05:00
|
|
|
draw_origin();
|
|
|
|
|
2020-09-09 21:40:39 -04:00
|
|
|
// DRAW TRACKS:
|
2020-09-07 11:19:24 -04:00
|
|
|
for(auto track : tracks)
|
|
|
|
draw(track);
|
2020-09-09 21:40:39 -04:00
|
|
|
|
2020-09-07 11:19:24 -04:00
|
|
|
glutSwapBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void init()
|
|
|
|
{
|
|
|
|
// dvereb:
|
|
|
|
srand(time(NULL));
|
|
|
|
|
2020-09-09 21:40:39 -04:00
|
|
|
glColor3d(1.0, 1.0, 1.0);
|
|
|
|
|
2020-09-07 11:19:24 -04:00
|
|
|
/* Enable a single OpenGL light. */
|
|
|
|
// glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
|
|
|
// glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
|
|
|
// glEnable(GL_LIGHT0);
|
|
|
|
// glEnable(GL_LIGHTING);
|
|
|
|
|
|
|
|
/* Use depth buffering for hidden surface elimination. */
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
|
|
|
|
/* Setup the view of the cube. */
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
gluPerspective( /* field of view in degree */ 70.0,
|
|
|
|
/* aspect ratio */ 1.0,
|
|
|
|
/* Z near */ 1.0, /* Z far */ 1000.0);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2020-09-09 21:40:39 -04:00
|
|
|
gluLookAt(-10.0, 25.0, -10.0, /* eye is at */
|
2020-09-07 11:19:24 -04:00
|
|
|
0.0, 0.0, 0.0, /* center is at */
|
2020-09-09 21:40:39 -04:00
|
|
|
0.0, 1.0, 0.0); /* up is in positive Y direction */
|
2020-09-07 11:19:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
if(argc != 2)
|
|
|
|
{
|
|
|
|
std::cerr << "You pust pass the folder which contains gpx files." << std::endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> files;
|
|
|
|
for(const auto& entry : std::experimental::filesystem::directory_iterator(argv[1]))
|
|
|
|
{
|
|
|
|
auto extension = entry.path().extension();
|
|
|
|
if(extension == ".gpx")
|
2021-03-14 00:07:21 -05:00
|
|
|
files.push_back(entry.path().string());
|
2020-09-07 11:19:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for(auto file : files)
|
2021-03-20 22:56:03 -04:00
|
|
|
ParseFile(tracks, file);
|
2020-09-07 11:19:24 -04:00
|
|
|
|
2021-03-20 22:56:03 -04:00
|
|
|
// NORMALIZE TRACKS TO VIEWPORT:
|
|
|
|
bool first = true;
|
|
|
|
float min_lat, min_lon, min_ele, max_lat, max_lon, max_ele;
|
|
|
|
for(auto &track : tracks)
|
|
|
|
{
|
|
|
|
for(auto &p : track.points)
|
|
|
|
{
|
|
|
|
if(first)
|
|
|
|
{
|
|
|
|
first = false;
|
|
|
|
min_lat = max_lat = p.lat;
|
|
|
|
min_lon = max_lon = p.lon;
|
|
|
|
min_ele = max_ele = p.ele;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(p.lat < min_lat)
|
|
|
|
min_lat = p.lat;
|
|
|
|
else if(p.lat > max_lat)
|
|
|
|
max_lat = p.lat;
|
|
|
|
if(p.lon < min_lon)
|
|
|
|
min_lon = p.lon;
|
|
|
|
else if(p.lon > max_lon)
|
|
|
|
max_lon = p.lon;
|
|
|
|
if(p.ele < min_ele)
|
|
|
|
min_ele = p.ele;
|
|
|
|
else if(p.ele > max_ele)
|
|
|
|
max_ele = p.ele;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto lat_diff = min_lat + ((max_lat - min_lat) / 2.0);
|
|
|
|
auto lon_diff = min_lon + ((max_lon - min_lon) / 2.0);
|
|
|
|
auto ele_diff = min_ele;
|
|
|
|
for(auto &track : tracks)
|
|
|
|
{
|
|
|
|
for(auto &p : track.points)
|
|
|
|
{
|
|
|
|
p.lat -= lat_diff;
|
|
|
|
p.lon -= lon_diff;
|
|
|
|
p.ele -= ele_diff;
|
|
|
|
}
|
2020-09-07 11:19:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA | GLUT_MULTISAMPLE);
|
|
|
|
glutInit(&argc, argv);
|
2021-03-20 22:56:03 -04:00
|
|
|
glutCreateWindow("3D GPX Viewer");
|
2020-09-07 11:19:24 -04:00
|
|
|
glutDisplayFunc(display);
|
|
|
|
|
|
|
|
// NOTE(dev): lmfao:
|
|
|
|
// glutSetCursor(GLUT_CURSOR_SPRAY);
|
|
|
|
glutSetCursor(GLUT_CURSOR_FULL_CROSSHAIR);
|
|
|
|
|
|
|
|
init();
|
2021-03-20 22:56:03 -04:00
|
|
|
camera.Init();
|
|
|
|
camera.Fly(50);
|
|
|
|
camera.RotatePitch(-89 * M_PI / 180.0);
|
2020-09-07 11:19:24 -04:00
|
|
|
glutMainLoop();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|