#include "periodic_updates.hpp" #include #include #include static Ball* _ball = nullptr; static std::chrono::time_point _last_time, _init_clocks; static bool is_paused = false; static double speed_factor = 1.; void init_periodic_static(Ball* ball) { _last_time = std::chrono::steady_clock::now(); _init_clocks = std::chrono::steady_clock::now(); _ball = ball; } double ellapsed_double( std::chrono::time_point beg, std::chrono::time_point end) { std::chrono::duration ellapsed_db = end - beg; return ellapsed_db.count(); } void periodic_update() { if(is_paused) return; printf("%lf\n", speed_factor); auto now = std::chrono::steady_clock::now(); _ball->update_pos(speed_factor * ellapsed_double(_last_time, now)); _last_time = now; glutPostRedisplay(); } void periodic_kb_handler(unsigned char key, int, int) { if(key == ' ') { if(is_paused) _last_time = std::chrono::steady_clock::now(); is_paused = !is_paused; } else if(key == '<') { speed_factor -= .1; if(speed_factor <= 0.05) speed_factor = .1; } else if(key == '>') { speed_factor += .1; } else if(key == '0') { speed_factor = 1.; } }