#include "periodic_updates.hpp" #include #include #include static Ball* _ball = nullptr; static std::chrono::time_point _last_time, _init_clocks; 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() { auto now = std::chrono::steady_clock::now(); _ball->update_pos(ellapsed_double(_last_time, now)); fprintf(stderr, "dt = %lf, tot = %lf; center: %.2lf, %.2lf, %.2lf\n", ellapsed_double(_last_time, now), ellapsed_double(_init_clocks, now), _ball->getCenter().x, _ball->getCenter().y, _ball->getCenter().z); _last_time = now; glutPostRedisplay(); }