From ff092b42b596fe15a0e1122beb4fc5c8ae032b7c Mon Sep 17 00:00:00 2001 From: Eleni Maria Stea Date: Sun, 19 Apr 2020 14:49:07 +0300 Subject: [PATCH] Added idle func animation --- src/main.cc | 9 ++++++++- src/tentacle.cc | 11 ++++++++--- src/tentacle.h | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main.cc b/src/main.cc index c5ebc84..38ec59e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -9,6 +9,7 @@ static void cleanup(); static void display(); static void keyboard(unsigned char key, int x, int y); +static void idle(); /* XXX FIXME */ static Tentacle tentacle; @@ -22,6 +23,7 @@ int main(int argc, char **argv) glutCreateWindow("ludu mice"); glutDisplayFunc(display); glutKeyboardFunc(keyboard); + glutIdleFunc(idle); if (!init()) exit(1); @@ -56,7 +58,7 @@ static void display() glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - tentacle.draw(); + tentacle.draw(glutGet(GLUT_ELAPSED_TIME)); glutSwapBuffers(); } @@ -70,3 +72,8 @@ static void keyboard(unsigned char key, int x, int y) break; } } + +static void idle() +{ + glutPostRedisplay(); +} diff --git a/src/tentacle.cc b/src/tentacle.cc index 7a69c29..ceb5e43 100644 --- a/src/tentacle.cc +++ b/src/tentacle.cc @@ -25,13 +25,16 @@ Tentacle::add_control_point(const Vec3 &point) } void -Tentacle::draw() +Tentacle::draw(long time) { glLineWidth(2.0); glBegin(GL_LINE_STRIP); glColor3f(0.0, 0.0, 1.0); for(size_t i=0; i