shell mesh
[meshfrac] / main.c
diff --git a/main.c b/main.c
index 724fd70..2218f45 100644 (file)
--- a/main.c
+++ b/main.c
@@ -8,6 +8,7 @@
 #include "meshgen.h"
 #include "frac.h"
 #include "sdr.h"
+#include "dynarr.h"
 
 static const char *vsdr_src =
        "varying vec3 v_norm, v_ldir, v_vdir;\n"
@@ -57,7 +58,8 @@ static unsigned int sdr;
 
 static int cur, pending;
 static int show_orig = 1;
-static int show_points;
+static int show_points, show_planes, show_shell;
+static int cur_cell;
 
 
 int main(int argc, char **argv)
@@ -135,7 +137,8 @@ static void update(void)
        if(pending > cur) {
                switch(cur) {
                case 0:
-                       if(frac_gen_points(&frac, 16) == -1) {
+                       printf("Generate points...\n");
+                       if(frac_gen_points(&frac, 16) != -1) {
                                cur++;
                        } else {
                                pending = cur;
@@ -144,22 +147,28 @@ static void update(void)
                        break;
 
                case 1:
+                       printf("Build cells...\n");
                        if(frac_build_cells(&frac) != -1) {
                                cur++;
                        } else {
                                pending = cur;
                        }
+                       show_planes = 1;
                        break;
 
                case 2:
+                       printf("Construct shell...\n");
                        if(frac_build_shell(&frac) != -1) {
                                cur++;
                        } else {
                                pending = cur;
                        }
+                       show_orig = 0;
+                       show_shell = 1;
                        break;
 
                case 3:
+                       printf("Construct walls...\n");
                        if(frac_build_walls(&frac) != -1) {
                                cur++;
                        } else {
@@ -176,7 +185,8 @@ static void update(void)
 
 static void display(void)
 {
-       int i, num;
+       int i, j, num;
+       struct poly *poly;
 
        update();
 
@@ -198,15 +208,19 @@ static void display(void)
                bind_program(0);
 
                glPushAttrib(GL_ENABLE_BIT);
-               glDisable(GL_DEPTH_TEST);
                glDisable(GL_LIGHTING);
+               glDisable(GL_DEPTH_TEST);
                glEnable(GL_BLEND);
                glBlendFunc(GL_ONE, GL_ONE);
 
                glPointSize(2.0f);
                glBegin(GL_POINTS);
-               glColor3f(0.1, 0.8, 0.1);
                for(i=0; i<num; i++) {
+                       if(cur_cell == i) {
+                               glColor3f(0.8, 1, 0.1);
+                       } else {
+                               glColor3f(0.1, 0.8, 0.1);
+                       }
                        glVertex3fv(&frac.cells[i].pt.x);
                }
                glEnd();
@@ -214,6 +228,31 @@ static void display(void)
                glPopAttrib();
        }
 
+       if(show_planes) {
+               bind_program(0);
+
+               glPushAttrib(GL_ENABLE_BIT);
+               glDisable(GL_LIGHTING);
+
+               poly = frac.cells[cur_cell].polys;
+               for(i=0; i<frac.cells[cur_cell].num_polys; i++) {
+                       glBegin(GL_LINE_LOOP);
+                       glColor3f(0.5, 0.5, 0);
+                       for(j=0; j<dynarr_size(poly->verts); j++) {
+                               glVertex3fv(&poly->verts[j].pos.x);
+                       }
+                       glEnd();
+                       poly++;
+               }
+
+               glPopAttrib();
+       }
+
+       if(show_shell) {
+               bind_program(sdr);
+               cmesh_draw(frac.cells[cur_cell].mesh);
+       }
+
        assert(glGetError() == GL_NO_ERROR);
        glutSwapBuffers();
 }
@@ -247,6 +286,25 @@ static void keydown(unsigned char key, int x, int y)
                glutPostRedisplay();
                break;
 
+       case 'P':
+               show_planes ^= 1;
+               glutPostRedisplay();
+               break;
+
+       case ']':
+               cur_cell = (cur_cell + 1) % frac_num_cells(&frac);
+               printf("current cell: %d\n", cur_cell);
+               glutPostRedisplay();
+               break;
+
+       case '[':
+               if(--cur_cell < 0) {
+                       cur_cell = frac_num_cells(&frac) - 1;
+                       printf("current cell: %d\n", cur_cell);
+                       glutPostRedisplay();
+               }
+               break;
+
        default:
                if(key >= '1' && key <= '4') {
                        n = key - '0';