Added idle func animation
[ludumice] / src / tentacle.cc
1 #include <GL/gl.h>
2 #include "tentacle.h"
3
4 Tentacle::Tentacle()
5 {
6 }
7
8 Tentacle::~Tentacle()
9 {
10 }
11
12 bool
13 Tentacle::init()
14 {
15         for (int i=0; i<5; i++) {
16                 add_control_point(Vec3(0.5, i / 10.0, 0.0));
17         }
18         return true;
19 }
20
21 void
22 Tentacle::add_control_point(const Vec3 &point)
23 {
24         cpoints.push_back(point);
25 }
26
27 void
28 Tentacle::draw(long time)
29 {
30         glLineWidth(2.0);
31         glBegin(GL_LINE_STRIP);
32         glColor3f(0.0, 0.0, 1.0);
33         for(size_t i=0; i<cpoints.size(); i++) {
34                 float y = cpoints[i].y;
35                 float offs = gph::noise(y, time * 0.0005 * y);
36                 glVertex3f(cpoints[i].x + offs, y, cpoints[i].z + offs);
37
38         }
39         glEnd();
40
41         // XXX DEBUG
42         glDisable(GL_DEPTH_TEST);
43         glPointSize(5.0);
44         glBegin(GL_POINTS);
45         glColor3f(1.0, 0.0, 0.0);
46         for(size_t i=0; i<cpoints.size(); i++) {
47                 float y = cpoints[i].y;
48                 float offs = gph::noise(y, time * 0.0005 * y);
49                 glVertex3f(cpoints[i].x + offs, y, cpoints[i].z + offs);
50         }
51         glEnd();
52         glEnable(GL_DEPTH_TEST);
53 }