Skip to content
Snippets Groups Projects
Commit dcfc336f authored by florian.burgener's avatar florian.burgener
Browse files

Add simulation speed control

parent 5464edb2
Branches
Tags
No related merge requests found
......@@ -146,7 +146,7 @@ void planetary_system_draw(PlanetarySystem *planetary_system) {
uint32_t color = object->drawing_color;
glColor3ub((color & 0xFF0000) >> 16, (color & 0x00FF00) >> 8, (color & 0x0000FF) >> 0);
draw_disc(scaled_position, object->drawing_disc_radius);
draw_disc(scaled_position, object->drawing_disc_radius * planetary_system->zoom_factor);
if (i != 5) {
glLineWidth(4.0);
......
......@@ -2,6 +2,7 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "PlanetarySystem.h"
......@@ -23,8 +24,9 @@
#endif
PlanetarySystem *planetary_system;
uint32_t elapsed_time = 0;
uint32_t true_time_shift = 0;
int32_t elapsed_time = 0;
int32_t true_time_shift = 0;
int32_t time_elasping_per_second = TIME_ELASPING_PER_SECOND;
void draw_timer() {
glutPostRedisplay();
......@@ -36,7 +38,7 @@ void update_timer() {
true_time_shift = time(NULL) % 1000;
elapsed_time += 1;
for (uint32_t i = 0; i < TIME_ELASPING_PER_SECOND / REFRESH_RATE / TIME_ELASPING_PER_UPDATE; i += 1) {
for (int32_t i = 0; i < time_elasping_per_second / REFRESH_RATE / TIME_ELASPING_PER_UPDATE; i += 1) {
planetary_system_update(planetary_system, TIME_ELASPING_PER_UPDATE);
}
......@@ -55,6 +57,14 @@ void draw() {
planetary_system_draw(planetary_system);
glColor3f(1.0, 1.0, 1.0);
glRasterPos2f(8, 32);
char text[100];
sprintf(text, "Simulation Speed : %d days per second", time_elasping_per_second / 86400);
for (int32_t i = 0; i < (int32_t)strlen(text); i++) {
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, text[i]);
}
glFlush();
}
......@@ -77,6 +87,22 @@ void handle_special_keyboard_input(int key, int UNUSED(x), int UNUSED(y)) {
planetary_system->reference_frame_object_index += 1;
planetary_system->reference_frame_object_index %= planetary_system->objects_length;
}
if (key == GLUT_KEY_UP) {
time_elasping_per_second += 86400;
if (time_elasping_per_second > 86400 * 300) {
time_elasping_per_second = 86400 * 300;
}
}
if (key == GLUT_KEY_DOWN) {
time_elasping_per_second -= 86400;
if (time_elasping_per_second < 0) {
time_elasping_per_second = 0;
}
}
}
void handle_mouse_input(int button, int state, int UNUSED(x), int UNUSED(y)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment