24 lines
475 B
C++
24 lines
475 B
C++
#include "periodic_updates.hpp"
|
|
|
|
#include <ctime>
|
|
#include <GL/glut.h>
|
|
|
|
static Ball* _ball = nullptr;
|
|
static clock_t _last_time = 0;
|
|
|
|
double time_of_clocks(clock_t time) {
|
|
return ((double)time) / ((double)CLOCKS_PER_SEC);
|
|
}
|
|
|
|
void init_periodic_static(Ball* ball) {
|
|
_last_time = clock();
|
|
_ball = ball;
|
|
}
|
|
|
|
void periodic_update() {
|
|
clock_t now = clock();
|
|
_ball->update_pos(time_of_clocks(now - _last_time));
|
|
_last_time = now;
|
|
|
|
glutPostRedisplay();
|
|
}
|