initial commit: a line and 5 points
authorEleni Maria Stea <estea@igalia.com>
Sat, 18 Apr 2020 17:05:18 +0000 (20:05 +0300)
committerEleni Maria Stea <estea@igalia.com>
Sat, 18 Apr 2020 17:05:18 +0000 (20:05 +0300)
Makefile [new file with mode: 0755]
src/main.cc [new file with mode: 0644]
src/tentacle.cc [new file with mode: 0644]
src/tentacle.h [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100755 (executable)
index 0000000..f2fc953
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,24 @@
+src = $(wildcard src/*.cc)
+obj = $(src:.cc=.o)
+dep = $(obj:.o=.d)
+bin = splines 
+
+dbg = -g
+opt = -O0
+inc = -Isrc
+
+CXX = g++
+CXXFLAGS = -pedantic -Wall $(dbg) $(opt) $(inc)
+LDFLAGS = -lGL -lGLU -lglut -lGLEW -limago -lgmath
+
+$(bin): $(obj)
+       $(CXX) -o $@ $(obj) $(LDFLAGS)
+
+-include $(dep)
+
+%.d: %.cc
+       @$(CPP) $(CXXFLAGS) $< -MM -MT $(@:.d=.o) >$@
+
+.PHONY: clean
+clean:
+       rm -f $(obj) $(bin) $(dep)
diff --git a/src/main.cc b/src/main.cc
new file mode 100644 (file)
index 0000000..c5ebc84
--- /dev/null
@@ -0,0 +1,72 @@
+#include <GL/glew.h>
+#include <GL/glut.h>
+#include <stdio.h>
+
+#include "tentacle.h"
+
+static bool init();
+static void cleanup();
+
+static void display();
+static void keyboard(unsigned char key, int x, int y);
+
+/* XXX FIXME */
+static Tentacle tentacle;
+
+int main(int argc, char **argv)
+{
+       glutInit(&argc, argv);
+       glutInitWindowSize(800, 600);
+       glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
+
+       glutCreateWindow("ludu mice");
+       glutDisplayFunc(display);
+       glutKeyboardFunc(keyboard);
+
+       if (!init())
+               exit(1);
+
+       atexit(cleanup);
+
+       glutMainLoop();
+}
+
+static bool init()
+{
+       glewInit();
+       glClearColor(1.0, 1.0, 0.0, 1.0);
+
+       if (!tentacle.init()) {
+               fprintf(stderr, "Failed to initialize tentacle control points.\n");
+               return false;
+       }
+
+       return true;
+}
+
+static void cleanup()
+{
+}
+
+static void display()
+{
+       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+       //XXX FIXME
+       glMatrixMode(GL_MODELVIEW);
+       glLoadIdentity();
+
+       tentacle.draw();
+
+       glutSwapBuffers();
+}
+
+static void keyboard(unsigned char key, int x, int y)
+{
+       switch(key) {
+       case 27:
+               exit(0);
+       default:
+               break;
+       }
+}
diff --git a/src/tentacle.cc b/src/tentacle.cc
new file mode 100644 (file)
index 0000000..7a69c29
--- /dev/null
@@ -0,0 +1,48 @@
+#include <GL/gl.h>
+#include "tentacle.h"
+
+Tentacle::Tentacle()
+{
+}
+
+Tentacle::~Tentacle()
+{
+}
+
+bool
+Tentacle::init()
+{
+       for (int i=0; i<5; i++) {
+               add_control_point(Vec3(0.5, i / 10.0, 0.0));
+       }
+       return true;
+}
+
+void
+Tentacle::add_control_point(const Vec3 &point)
+{
+       cpoints.push_back(point);
+}
+
+void
+Tentacle::draw()
+{
+       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);
+       }
+       glEnd();
+
+       // XXX DEBUG
+       glDisable(GL_DEPTH_TEST);
+       glPointSize(5.0);
+       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);
+       }
+       glEnd();
+       glEnable(GL_DEPTH_TEST);
+}
diff --git a/src/tentacle.h b/src/tentacle.h
new file mode 100644 (file)
index 0000000..cb07a35
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef TENTACLE_H_
+#define TENTACLE_H_
+
+#include <vector>
+#include <gmath/gmath.h>
+
+class Tentacle {
+private:
+       std::vector<Vec3> cpoints;
+
+public:
+       Tentacle();
+       ~Tentacle();
+
+       bool init();
+       void add_control_point(const Vec3 &point);
+       void draw();
+};
+
+#endif // TENTACLE_H_