Better 3d visualization.

This commit is contained in:
David Vereb 2020-09-09 21:40:39 -04:00
parent 941d8f96d8
commit 79cdfeb4a6

View File

@ -15,6 +15,7 @@ GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0}; /* Infinite light location. */
struct Point { struct Point {
float lat; float lat;
float lon; float lon;
float ele;
}; };
static std::vector<std::vector<Point> > tracks; static std::vector<std::vector<Point> > tracks;
@ -26,16 +27,16 @@ static std::vector<std::vector<Point> > tracks;
void draw(const std::vector<Point> &points) void draw(const std::vector<Point> &points)
{ {
static float rot=0.0; glLineWidth(1.0f);
rot += 0.1f;
glLineWidth(0.5f); // Draw bike path
glColor3d(1.0,1.0,1.0);
// Draw Sun:
glBegin(GL_LINE_STRIP); glBegin(GL_LINE_STRIP);
for(auto p : points) for(auto p : points)
glVertex3f(p.lat, p.lon, 0.0); {
auto val = (50 + (p.ele * 10)) / 180.0;
glColor3d(val, val, val);
glVertex3f(p.lat, p.ele, p.lon);
}
glEnd(); glEnd();
// usleep(100000); // usleep(100000);
@ -45,9 +46,22 @@ void draw(const std::vector<Point> &points)
void display() void display()
{ {
// RESET:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
static double asdf = -10.0;
asdf += 0.03;
if(asdf > 30.0)
asdf = -30.0;
gluLookAt(-asdf, 12.0, -30, /* eye is at */
0.0, 0.0, 0.0, /* center is at */
0.0, 1.0, 0.0); /* up is in positive Y direction */
// DRAW TRACKS:
for(auto track : tracks) for(auto track : tracks)
draw(track); draw(track);
glutSwapBuffers(); glutSwapBuffers();
} }
@ -56,6 +70,8 @@ void init()
// dvereb: // dvereb:
srand(time(NULL)); srand(time(NULL));
glColor3d(1.0, 1.0, 1.0);
/* Enable a single OpenGL light. */ /* Enable a single OpenGL light. */
// glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); // glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
// glLightfv(GL_LIGHT0, GL_POSITION, light_position); // glLightfv(GL_LIGHT0, GL_POSITION, light_position);
@ -71,9 +87,9 @@ void init()
/* aspect ratio */ 1.0, /* aspect ratio */ 1.0,
/* Z near */ 1.0, /* Z far */ 1000.0); /* Z near */ 1.0, /* Z far */ 1000.0);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
gluLookAt(0.0, 0.0, 20.0, /* eye is at */ gluLookAt(-10.0, 25.0, -10.0, /* eye is at */
0.0, 0.0, 0.0, /* center is at */ 0.0, 0.0, 0.0, /* center is at */
0.0, 1.0, 0.); /* up is in positive Y direction */ 0.0, 1.0, 0.0); /* up is in positive Y direction */
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -92,6 +108,8 @@ int main(int argc, char *argv[])
files.push_back(entry.path().filename()); files.push_back(entry.path().filename());
} }
float file_diff_lat = -8;
float file_diff_lon = -8;
for(auto file : files) for(auto file : files)
{ {
std::ifstream ifs(file); std::ifstream ifs(file);
@ -103,30 +121,40 @@ int main(int argc, char *argv[])
std::string line = ""; std::string line = "";
bool first = true; bool first = true;
float diff_lat, diff_lon; float diff_lat, diff_lon, diff_ele;
std::vector<Point> track; std::vector<Point> track;
while(std::getline(ifs, line)) while(std::getline(ifs, line))
{ {
// get starting position of field NAMES // get starting position of field NAME
auto lat = line.find("lat=\""); auto lat = line.find("lat=\"");
if(lat == std::string::npos) if(lat == std::string::npos)
continue; continue;
auto lon = line.find("lon=\"");
if(lon == std::string::npos)
continue;
// get ending position of field DATA // get ending position of field DATA
auto lat_to = line.find("\"", lat); auto lat_to = line.find("\"", lat);
if(lat_to == std::string::npos) if(lat_to == std::string::npos)
continue; continue;
// get starting position of field NAME
auto lon = line.find("lon=\"", lat_to);
if(lon == std::string::npos)
continue;
// get ending position of field DATA
auto lon_to = line.find("\"", lon); auto lon_to = line.find("\"", lon);
if(lon_to == std::string::npos) if(lon_to == std::string::npos)
continue; continue;
auto ele = line.find("<ele>", lon_to);
if(ele == std::string::npos)
continue;
auto ele_to = line.find("</ele>", ele);
if(ele_to == std::string::npos)
continue;
Point p; Point p;
try { try {
p.lat = std::atof(line.substr(lat + 5, lat_to).c_str()) * 500; p.lat = std::atof(line.substr(lat + 5, lat_to).c_str()) * 200;
p.lon = std::atof(line.substr(lon + 5, lon_to).c_str()) * 500; p.lon = std::atof(line.substr(lon + 5, lon_to).c_str()) * 200;
p.ele = std::atof(line.substr(ele + 5, ele_to).c_str()) * 0.1;
} catch (const std::exception &e) { } catch (const std::exception &e) {
std::cerr << "Error in file " << file << ", line \"" << line << "\"." << std::endl; std::cerr << "Error in file " << file << ", line \"" << line << "\"." << std::endl;
continue; continue;
@ -137,13 +165,21 @@ int main(int argc, char *argv[])
first = false; first = false;
diff_lat = p.lat; diff_lat = p.lat;
diff_lon = p.lon; diff_lon = p.lon;
diff_ele = p.ele;
} }
p.lat -= diff_lat; p.lat -= diff_lat + file_diff_lat;
p.lon -= diff_lon; p.lon -= diff_lon + file_diff_lon;
p.ele -= diff_ele;
track.push_back(p); track.push_back(p);
} }
tracks.push_back(track); tracks.push_back(track);
file_diff_lat += 4;
if(file_diff_lat > 5)
{
file_diff_lat = -8;
file_diff_lon += 4;
}
ifs.close(); ifs.close();
} }