X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcontrol.c;h=31ec61cc7617679ce22037abbc0986835fffee12;hb=HEAD;hp=3ead1e2118a293660716592b802b20a615602b4e;hpb=fcc21bf22fb603e0073cef98dc4ff002bdb7cce7;p=geometrycompositor.git diff --git a/source/control.c b/source/control.c index 3ead1e2..31ec61c 100644 --- a/source/control.c +++ b/source/control.c @@ -11,7 +11,8 @@ typedef struct GeometryCorrection { char *monitor_name; float keystone_vertical; - float cylinder_depth; + int curvature_type; + float curvature_depth; float vertical_center; float perspective; } GeometryCorrection; @@ -31,10 +32,10 @@ typedef struct InteractiveView static unsigned short frustum_indices[] = { 2, 1, 3, 0, 1, 0xFFFF, 3, 4, 2, 0, 4, 0xFFFF }; static float view_matrix[] = { - 0.70711f, 0.40825f, -0.57735f, 0.0f, - 0.0f, 0.81650f, 0.57735f, 0.0f, - 0.70711f, -0.40725f, 0.57735f, 0.0f, - -0.2f, 0.0f, -2.5f, 1.0f + 0.70711f, 0.23570f, -0.66667f, 0.0f, + 0.0f, 0.94281f, 0.33333f, 0.0f, + 0.70711f, -0.23570f, 0.66667f, 0.0f, + -0.2f, 0.0f, -2.0f, 1.0f }; static float projection_matrix[] = { @@ -103,6 +104,15 @@ static const char *flat_fshader_src = "}\n"; +void reset_correction(GeometryCorrection *correction) +{ + correction->keystone_vertical = 0.0f; + correction->curvature_type = 1; + correction->curvature_depth = 0.0f; + correction->vertical_center = 0.5f; + correction->perspective = 1.0f; +} + GeometryCorrection *get_corrections(Display *display) { Window root; @@ -141,8 +151,8 @@ GeometryCorrection *get_corrections(Display *display) for(i=0; ivalues_length) - ncorrections = values_length/4; + if(ncorrections*5>values_length) + ncorrections = values_length/5; corrections = (GeometryCorrection *)malloc((ncorrections+1)*sizeof(GeometryCorrection)); name_ptr = names; @@ -154,10 +164,11 @@ GeometryCorrection *get_corrections(Display *display) corrections[i].monitor_name = (char *)malloc(namelen+1); strcpy(corrections[i].monitor_name, name_ptr); - corrections[i].keystone_vertical = values[i*4]/10000.0f; - corrections[i].cylinder_depth = values[i*4+1]/10000.0f; - corrections[i].vertical_center = values[i*4+2]/10000.0f; - corrections[i].perspective = values[i*4+3]/10000.0f; + corrections[i].keystone_vertical = values[i*5]/4096.0f; + corrections[i].curvature_type = values[i*5+1]; + corrections[i].curvature_depth = values[i*5+2]/4096.0f; + corrections[i].vertical_center = values[i*5+3]/4096.0f; + corrections[i].perspective = values[i*5+4]/4096.0f; name_ptr += namelen+1; } @@ -191,24 +202,25 @@ void set_corrections(Display *display, GeometryCorrection *corrections) } names = (char *)malloc(total_len+ncorrections); - values = (short *)malloc(ncorrections*4*sizeof(short)); + values = (short *)malloc(ncorrections*5*sizeof(short)); name_ptr = names; for(i=0; inelements = tessellation*((tessellation+1)*2+1)-1; @@ -380,9 +392,11 @@ int interactive(Display *display, GeometryCorrection *corrections, GeometryCorre { XEvent event; KeySym keysym; + int repaint; XNextEvent(display, &event); + repaint = 0; switch(event.type) { case KeyPress: @@ -399,9 +413,9 @@ int interactive(Display *display, GeometryCorrection *corrections, GeometryCorre else if(keysym==XK_a) target->keystone_vertical -= 1.0f/64; else if(keysym==XK_w) - target->cylinder_depth += 1.0f/256; + target->curvature_depth += 1.0f/256; else if(keysym==XK_s) - target->cylinder_depth -= 1.0f/256; + target->curvature_depth -= 1.0f/256; else if(keysym==XK_e) target->vertical_center += 1.0f/32; else if(keysym==XK_d) @@ -410,6 +424,10 @@ int interactive(Display *display, GeometryCorrection *corrections, GeometryCorre target->perspective += 1.0f/16; else if(keysym==XK_f) target->perspective -= 1.0f/16; + else if(keysym==XK_z) + target->curvature_type = target->curvature_type%2+1; + else if(keysym==XK_0) + reset_correction(target); else break; @@ -423,19 +441,23 @@ int interactive(Display *display, GeometryCorrection *corrections, GeometryCorre { update_view(display, &view, &event.xselection); update_pending = 0; + repaint = 1; } break; - default: - printf("event %d\n", event.type); + case Expose: + repaint = 1; break; } - glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); - glUseProgram(view.programs[0]); - glDrawElements(GL_TRIANGLE_STRIP, view.nelements, GL_UNSIGNED_SHORT, (void *)(12*sizeof(unsigned short))); - glUseProgram(view.programs[1]); - glDrawElements(GL_LINE_STRIP, 11, GL_UNSIGNED_SHORT, NULL); - glXSwapBuffers(display, view.glx_window); + if(repaint) + { + glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + glUseProgram(view.programs[0]); + glDrawElements(GL_TRIANGLE_STRIP, view.nelements, GL_UNSIGNED_SHORT, (void *)(12*sizeof(unsigned short))); + glUseProgram(view.programs[1]); + glDrawElements(GL_LINE_STRIP, 11, GL_UNSIGNED_SHORT, NULL); + glXSwapBuffers(display, view.glx_window); + } } return 0; @@ -447,9 +469,9 @@ int main(int argc, char **argv) GeometryCorrection *corrections; unsigned i; - if(argc!=2 && argc!=6) + if(argc!=2 && argc!=7) { - fprintf(stderr, "Usage: %s [ ]\n", argv[0]); + fprintf(stderr, "Usage: %s [ ]\n", argv[0]); return 1; } @@ -474,16 +496,26 @@ int main(int argc, char **argv) corrections[i].monitor_name = (char *)malloc(namelen+1); strcpy(corrections[i].monitor_name, argv[1]); corrections[i+1].monitor_name = NULL; + reset_correction(&corrections[i]); } if(argc==2) interactive(display, corrections, &corrections[i]); - else if(argc==6) + else if(argc==7) { + if(!strcmp(argv[3], "cylindrical")) + corrections[i].curvature_type = 1; + else if(!strcmp(argv[3], "spherical")) + corrections[i].curvature_type = 2; + else + { + fprintf(stderr, "Invalid curvature\n"); + return 1; + } corrections[i].keystone_vertical = strtod(argv[2], NULL); - corrections[i].cylinder_depth = strtod(argv[3], NULL); - corrections[i].vertical_center = strtod(argv[4], NULL); - corrections[i].perspective = strtod(argv[5], NULL); + corrections[i].curvature_depth = strtod(argv[4], NULL); + corrections[i].vertical_center = strtod(argv[5], NULL); + corrections[i].perspective = strtod(argv[6], NULL); set_corrections(display, corrections); }