X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=meshfrac;a=blobdiff_plain;f=main.c;h=724fd70e5c1394e14183e68c5e698bdf978d4d5b;hp=07e67c309bbc6f6dc2227a6ac85af863c748ec88;hb=0b9d8564e9c3785a69829a8faa67f5169185d8fd;hpb=3266468aa891bea6bda03f64ecba7da2a29d09c3 diff --git a/main.c b/main.c index 07e67c3..724fd70 100644 --- a/main.c +++ b/main.c @@ -6,6 +6,7 @@ #include #include "cmesh.h" #include "meshgen.h" +#include "frac.h" #include "sdr.h" static const char *vsdr_src = @@ -50,9 +51,15 @@ static float proj_mat[16], view_mat[16]; static int bnstate[8]; static int mx, my; +static struct fracture frac; static struct cmesh *mesh; static unsigned int sdr; +static int cur, pending; +static int show_orig = 1; +static int show_points; + + int main(int argc, char **argv) { glutInit(&argc, argv); @@ -106,11 +113,14 @@ static int init(void) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 60); - bind_program(sdr); - mesh = cmesh_alloc(); gen_torus(mesh, 2, 0.8, 24, 12, 1, 1); + if(frac_init(&frac) == -1) { + return -1; + } + frac_mesh(&frac, mesh); + return 0; } @@ -120,8 +130,56 @@ static void cleanup(void) free_program(sdr); } +static void update(void) +{ + if(pending > cur) { + switch(cur) { + case 0: + if(frac_gen_points(&frac, 16) == -1) { + cur++; + } else { + pending = cur; + } + show_points = 1; + break; + + case 1: + if(frac_build_cells(&frac) != -1) { + cur++; + } else { + pending = cur; + } + break; + + case 2: + if(frac_build_shell(&frac) != -1) { + cur++; + } else { + pending = cur; + } + break; + + case 3: + if(frac_build_walls(&frac) != -1) { + cur++; + } else { + pending = cur; + } + break; + + default: + break; + } + if(pending > cur) glutPostRedisplay(); + } +} + static void display(void) { + int i, num; + + update(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); cgm_mtranslation(view_mat, 0, 0, -view_dist); @@ -131,7 +189,30 @@ static void display(void) glMatrixMode(GL_MODELVIEW); glLoadMatrixf(view_mat); - cmesh_draw(mesh); + if(show_orig) { + bind_program(sdr); + cmesh_draw(mesh); + } + if(show_points) { + num = frac_num_cells(&frac); + bind_program(0); + + glPushAttrib(GL_ENABLE_BIT); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + 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= '1' && key <= '4') { + n = key - '0'; + if(cur < n) { + pending = n; + glutPostRedisplay(); + } + } } }