Added idle func animation master
authorEleni Maria Stea <estea@igalia.com>
Sun, 19 Apr 2020 11:49:07 +0000 (14:49 +0300)
committerEleni Maria Stea <estea@igalia.com>
Sun, 19 Apr 2020 11:49:07 +0000 (14:49 +0300)
src/main.cc
src/tentacle.cc
src/tentacle.h

index c5ebc84..38ec59e 100644 (file)
@@ -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();
+}
index 7a69c29..ceb5e43 100644 (file)
@@ -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<cpoints.size(); i++) {
-               glVertex3f(cpoints[i].x, cpoints[i].y, cpoints[i].z);
+               float y = cpoints[i].y;
+               float offs = gph::noise(y, time * 0.0005 * y);
+               glVertex3f(cpoints[i].x + offs, y, cpoints[i].z + offs);
+
        }
        glEnd();
 
@@ -41,7 +44,9 @@ Tentacle::draw()
        glBegin(GL_POINTS);
        glColor3f(1.0, 0.0, 0.0);
        for(size_t i=0; i<cpoints.size(); i++) {
-               glVertex3f(cpoints[i].x, cpoints[i].y, 1.0);
+               float y = cpoints[i].y;
+               float offs = gph::noise(y, time * 0.0005 * y);
+               glVertex3f(cpoints[i].x + offs, y, cpoints[i].z + offs);
        }
        glEnd();
        glEnable(GL_DEPTH_TEST);
index cb07a35..1b83afd 100644 (file)
@@ -14,7 +14,7 @@ public:
 
        bool init();
        void add_control_point(const Vec3 &point);
-       void draw();
+       void draw(long time);
 };
 
 #endif // TENTACLE_H_