/* Rotate about x-axis when "x" typed; rotate about y-axis when "y" typed; "i" returns torus to original view */ void keyboard(unsigned char key, int x, int y) { const float delta = 1.3f; const float rot_delta = 2.0f; vec3f_t& ref = object; switch (key) { case 27: exit(0); break; case 'z': ref.z -= delta; break; case 'Z': ref.z += delta; break; case 'x': ref.x -= delta; break; case 'X': ref.x += delta; break; case 'y': ref.y -= delta; break; case 'Y': ref.y += delta; break; case '1': rot_vec.x += rot_delta; break; case '2': rot_vec.x -= rot_delta; break; case '3': rot_vec.y += rot_delta; break; case '4': rot_vec.y -= rot_delta; break; case ' ': object.x = object.y = object.z = 0; rot_vec.x = rot_vec.y = rot_vec.z = 0; break; case 'f': glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); break; case 'F': glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); break; default: break; } glutPostRedisplay(); }
void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; case 'a': printf("%d, %d\n",x,y); break; case 'y': eixoy = (eixoy + 5) % 360; glutPostRedisplay(); break; case 'Y': eixoy = (eixoy - 5) % 360; glutPostRedisplay(); break; case 'x': eixox = (eixox + 5) % 360; glutPostRedisplay(); break; case 'X': eixox = (eixox - 5) % 360; glutPostRedisplay(); break; case 'p': glLoadIdentity(); gluPerspective(65.0, (GLfloat) largura/(GLfloat) altura, 20.0, 120.0); gluLookAt(0, 0, -90, 0, 0, 0, 0, 1, 0); glutPostRedisplay(); break; case 'o': glLoadIdentity(); glOrtho (-50, 50, -50, 50, -50 , 50); glutPostRedisplay(); break; case 't': eixoy = 0 % 360; eixox = 90 % 360; glutPostRedisplay(); break; case 'f': eixoy = 0 % 360; eixox = 270 % 360; glutPostRedisplay(); break; case 'T': eixoy = 0 % 360; eixox = 180 % 360; glutPostRedisplay(); break; case 'F': eixoy = 0 % 360; eixox = 0 % 360; glutPostRedisplay(); break; case 'e': eixoy = 90 % 360; eixox = 0 % 360; glutPostRedisplay(); break; case 'd': eixoy = 270 % 360; eixox = 0 % 360; glutPostRedisplay(); break; } }
// Переисовка кадра в отсутствии других сообщений void idle_func() { glutPostRedisplay(); }
// react to mouse motions with pressed buttons void motion(int x, int y) { mgr->mouseMove(x, y); glutPostRedisplay(); }
void _KeyboardFunc(unsigned char ubKey, int iX, int iY) { switch(ubKey) { case 's': compute_streamlines(); glutPostRedisplay(); break; case 'h': { int iHalo; cLineRenderer._GetInteger(CLineRenderer::ENABLE_HALO, &iHalo); iHalo = !iHalo; cLineRenderer._SetInteger(CLineRenderer::ENABLE_HALO, iHalo); } glutPostRedisplay(); break; case 'l': { int iLighting; cLineRenderer._GetInteger(CLineRenderer::ENABLE_LIGHTING, &iLighting); iLighting = !iLighting; cLineRenderer._SetInteger(CLineRenderer::ENABLE_LIGHTING, iLighting); } glutPostRedisplay(); break; // ADD-BY-LEETEN 09/29/2012-BEGIN case 'S': { VECTOR3 v3Min, v3Max; osuflow->Boundary(v3Min, v3Max); float pfDomainMin[4]; float pfDomainMax[4]; for(size_t d = 0; d < 3; d++) { pfDomainMin[d] = v3Min[d]; pfDomainMax[d] = v3Max[d]; } pfDomainMin[3] = 0.0f; pfDomainMax[3] = 0.0f; char szFilename[1024]; strcpy(szFilename, szVecFilePath); strcat(szFilename, ".trace"); OSUFlow::WriteFlowlines( pfDomainMin, pfDomainMax, &sl_list, NULL, szFilename); LOG(printf("Save the streamlines to %s", szFilename)); } break; // ADD-BY-LEETEN 09/29/2012-END } }
void myKeyHandler(unsigned char ch, int x, int y) { int i; static int subdiv=0; struct point_t *slice; struct point_t *linecur; struct point_t *cur; struct point_t *new_points; struct slice_t *cur_slice,*cur2_slice; struct point_t *cur2; struct point_t points[5]; double a,b,c; GLfloat v1[3],v2[3],v3[3]; double deginc; // struct slice_t *cur_slice; switch(ch) { case 'q': endSubdiv(0); break; case 'z': mode=(~mode)&1; printf("%s\n",mode?"3D mode":"2D mode"); switch(mode) { case 0: resetCamera(); break; case 1: reset3DCamera(); break; } break; case 'k': /* test phong stuff */ cur_slice = slices; cur2_slice = slices->n; //while(cur_slice!=NULL) { cur = cur_slice->line; cur2 = cur2_slice->line; //while(cur->n!=NULL) { /* right vertex */ add_vec(&(cur->nx),&(cur->n->nx),&(points[0].nx)); normalize(&(points[0].nx)); sub_vec(&(cur->n->x),&(cur->x),v1); v1[0] /= 2; v1[1] /= 2; v1[2] /= 2; add_vec(&(cur->x),v1,&(points[0].x)); /* top vertex */ add_vec(&(cur->nx),&(cur2->nx),&(points[1].nx)); normalize(&(points[1].nx)); sub_vec(&(cur2->x),&(cur->x),v1); v1[0] /= 2; v1[1] /= 2; v1[2] /= 2; add_vec(&(cur->x),v1,&(points[1].x)); /* left vertex */ add_vec(&(cur2->nx),&(cur2->n->nx),&(points[2].nx)); normalize(&(points[2].nx)); sub_vec(&(cur2->n->x),&(cur2->x),v1); v1[0] /= 2; v1[1] /= 2; v1[2] /= 2; add_vec(&(cur2->x),v1,&(points[2].x)); /* bottom vertex */ add_vec(&(cur2->n->nx),&(cur->n->nx),&(points[3].nx)); normalize(&(points[3].nx)); sub_vec(&(cur->n->x),&(cur2->n->x),v1); v1[0] /= 2; v1[1] /= 2; v1[2] /= 2; add_vec(&(cur2->n->x),v1,&(points[3].x)); /* center vertex */ add_vec(&(points[0].nx),&(points[1].nx),v1); add_vec(&(points[2].nx),&(points[3].nx),v2); add_vec(v1,v2,&(points[4].nx)); normalize(&(points[4].nx)); sub_vec(&(points[3].x),&(cur2->n->x),v1); sub_vec(&(points[2].x),&(cur2->n->x),v2); add_vec(v1,v2,v3); normalize(v3); a=sqrt(v1[0]*v1[0]+v1[1]*v1[1]+v1[2]*v1[2]); b=sqrt(v2[0]*v2[0]+v2[1]*v2[1]+v2[2]*v2[2]); c=sqrt(a*a+b*b); v3[0] *= c; v3[1] *= c; v3[2] *= c; add_vec(&(cur2->n->x),v3,&(points[4].x)); printf("v2[0]=%f,v2[1]=%f,v2[2]=%f\nv3[0]=%f,v3[1]=%f,v3[2]=%f\n",v2[0],v2[1],v2[2],v3[0],v3[1],v3[2]); for(i=0; i<5; i++) printf("points[%d]->x=%f,points[%d]->y=%f,points[%d]->z=%f\n", i,points[i].x,i,points[i].y,i,points[i].z); printf("cur->x=%f,cur->y=%f,cur->z=%f\ncur->n->x=%f,cur->n->y=%f,cur->n->z=%f\n", cur->x,cur->y,cur->z,cur->n->x,cur->n->y,cur->n->z); printf("cur2->x=%f,cur2->y=%f,cur2->z=%f\ncur2->n->x=%f,cur2->n->y=%f,cur2->n->z=%f\n", cur2->x,cur2->y,cur2->z,cur2->n->x,cur2->n->y,cur2->n->z); cur = cur->n; cur2 = cur2->n; } cur_slice = cur_slice->n; cur2_slice = cur2_slice->n != NULL ? cur2_slice->n : slices; /* circle around */ } break; case 'n': normals=(~normals)&1; printf("Normal mode %s\n",normals?"on":"off"); break; case 'e': solid=(~solid)&1; printf("%s\n",solid?"Solid mode":"Wireframe mode"); switch(solid) { case 0: glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); break; case 1: glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); break; } break; case 'r': faces=(~faces)&1; printf("%s\n",faces?"Faces mode":"Control points mode"); break; case 'w': /* calculate initial 3d object */ if(num<5) printf("There must be at least 5 control points.\n"); else if(!mode) { mode=(~mode)&1; printf("%s\n",mode?"3D mode":"2D mode"); switch(mode) { case 0: resetCamera(); break; case 1: reset3DCamera(); break; } freeModel(); subdiv_v = 0; subdiv_h = NUMSLICES; /* the radius of the circle for each of the points is x */ for(i=0;i<subdiv_h;i++) { ALLOC_POINT(slice); cur=slice; linecur=line; while(linecur!=NULL) { cur->z = linecur->x*sin(DEGINC*i); cur->x = linecur->x*cos(DEGINC*i); cur->y = linecur->y; linecur = linecur->n; if(linecur!=NULL) { ALLOC_POINT(cur->n); cur = cur->n; } } addSlice(slice); } } recompute_normals(); break; case 's': /* horizontal subdivision */ if(!mode || slices==NULL) break; /* backup the original slice */ new_points = duplicate_slice(slices->line); freeModel(); subdiv_h<<=1; subdiv++; printf("Horizontal subdivision level %d\n",subdiv); deginc = 2*M_PI/subdiv_h; for(i=0;i<subdiv_h;i++) { ALLOC_POINT(slice); cur=slice; linecur=new_points; while(linecur!=NULL) { cur->z = linecur->x*sin(deginc*i); cur->x = linecur->x*cos(deginc*i); cur->y = linecur->y; linecur = linecur->n; if(linecur!=NULL) { ALLOC_POINT(cur->n); cur = cur->n; } } addSlice(slice); } recompute_normals(); break; case 'a': /* vertical subdivision */ if(!mode || slices==NULL) break; cur_slice=slices; subdiv_v++; printf("Vertical subdivision level %d\n",subdiv_v); linecur = cur_slice->line; /* calc the first point */ cur = new_points = calc_point(linecur,linecur,linecur->n,linecur->n->n); /* calc middle and last points */ while(linecur->n->n!=NULL) { if(linecur->n->n->n!=NULL) /* middle points */ cur->n = calc_point(linecur,linecur->n,linecur->n->n,linecur->n->n->n); else cur->n = calc_point(linecur,linecur->n,linecur->n->n,linecur->n->n); cur = cur->n; linecur = linecur->n; } interleave(cur_slice->line,new_points); new_points = duplicate_slice(cur_slice->line); deginc = 2*M_PI/subdiv_h; freeModel(); for(i=0;i<subdiv_h;i++) { ALLOC_POINT(slice); cur=slice; linecur=new_points; while(linecur!=NULL) { cur->z = linecur->x*sin(deginc*i); cur->x = linecur->x*cos(deginc*i); cur->y = linecur->y; linecur = linecur->n; if(linecur!=NULL) { ALLOC_POINT(cur->n); cur = cur->n; } } addSlice(slice); } recompute_normals(); break; case 'd': shading=(~shading)&1; printf("%s shading\n",shading?"Phong":"Gouraud"); break; case '<': if(mode) { glMatrixMode(GL_MODELVIEW); glRotatef(1,0.0,1.0,0.0); } break; case '>': if(mode) { glMatrixMode(GL_MODELVIEW); glRotatef(-1,0.0,1.0,0.0); } break; default: /* Unrecognized keypress */ return; } glutPostRedisplay(); return; }
void MainWindow::callback_mouse(int button, int state, int x, int y) { // Re-route mouse callback MainWindow::master->mousePressed(button, state, x, y); glutPostRedisplay(); }
void tock(int value) { updateBoidPos(); glutPostRedisplay(); glutTimerFunc(TIMER_DELAY, tock, 0); }
void MainWindow::callback_keyUp(unsigned char key, int x, int y) { // Re-route key callback MainWindow::master->keyUp(key, x, y); glutPostRedisplay(); }
void MainWindow::callback_specialkeyUp(int key, int x, int y) { // Re-route special key callback MainWindow::master->specialkeyUp(key, x, y); glutPostRedisplay(); }
void IdleFunction(void){ glutPostRedisplay(); }
void idle() { glutPostRedisplay(); }
void display(void) { struct timeval time1, time2; double total_time, rate, pixel_rate; const unsigned pixel_size = formats[cur_format].num_comp * types[cur_type].byte_size / types[cur_type].num_comp; const unsigned buf_size = align_size(screen_width * pixel_size, ALIGNMENT) * screen_height; unsigned char* buf = (unsigned char*) malloc(buf_size); assert(buf); if (stabilizing_rounds) printf("Stabilizing round %i\n", stabilizing_rounds); glPixelStorei(GL_PACK_ALIGNMENT, ALIGNMENT); gettimeofday(&time1, NULL); for (int i = 0; i < NUM_READBACKS; ++i) { glReadPixels(0, 0, screen_width, screen_height, formats[cur_format].format, types[cur_type].type, buf); } gettimeofday(&time2, NULL); total_time = (time2.tv_sec + 1e-6 * time2.tv_usec - time1.tv_sec - 1e-6 * time1.tv_usec); rate = 1e-6 * NUM_READBACKS * buf_size / total_time; pixel_rate = 1e-6 * NUM_READBACKS * screen_width * screen_height / total_time; if (stabilizing_rounds) { --stabilizing_rounds; } else { results[cur_type * NUM_FORMATS + cur_format].type = cur_type; results[cur_type * NUM_FORMATS + cur_format].format = cur_format; results[cur_type * NUM_FORMATS + cur_format].rate = rate; results[cur_type * NUM_FORMATS + cur_format].pixel_rate = pixel_rate; printf("%s %s %g MB/s %g Mp/s\n", formats[cur_format].desc, types[cur_type].desc, rate, pixel_rate); /* Find the next type that is compatible with the current format */ do { ++cur_type; } while (!compatible(formats[cur_format], types[cur_type]) && cur_type < NUM_TYPES); /* Go to the next type/format */ if (cur_type == NUM_TYPES) { cur_type = 0; if (++cur_format == NUM_FORMATS) { printf("\nSorted by data rate:\n"); qsort(results, NUM_FORMATS * NUM_TYPES, sizeof(result_t), compare_data_rate); for (int i = 0; i < NUM_FORMATS * NUM_TYPES; ++i) { if (results[i].rate >= 0) printf("%s %s %g MB/s\n", formats[results[i].format].desc, types[results[i].type].desc, results[i].rate); } printf("\nSorted by pixel rate:\n"); qsort(results, NUM_FORMATS * NUM_TYPES, sizeof(result_t), compare_pixel_rate); for (int i = 0; i < NUM_FORMATS * NUM_TYPES; ++i) { if (results[i].rate >= 0) printf("%s %s %g Mp/s\n", formats[results[i].format].desc, types[results[i].type].desc, results[i].pixel_rate); } exit(0); } } } free(buf); glutReportErrors(); glutPostRedisplay(); }
/* * motion state machine -- idle loop */ void idle(void) { static int over_clicks; int rc; char next_move[3]; if (spinning) click++; if (motion) { switch(state) { case ST_READNEXT: /* * read an instruction from the hanoi engine */ rc = read(engine_fd, next_move, 3); if (rc == 3 && next_move[0] == 'M') { /* choose poles/disks to move */ old_pole = next_move[1]; c_pole = next_move[2]; c_disk = disks_on_poles[old_pole].disks[disks_on_poles[old_pole].num_disks - 1]; state = ST_UP; disk_incr[Z] = CYL_HEIGHT / (float)UP_CLICKS; } else if (rc == 3 && next_move[0] == 'D') { state = ST_IDLE; } else if (rc != 0) { fprintf(stderr,"bad read; %d, [%d%d%d]\n", rc, next_move[0], next_move[1], next_move[2]); exit(1); } /* if rc == 0, do nothing this frame */ break; case ST_UP: disk_offset[c_disk][Z] += disk_incr[Z]; if (disk_offset[c_disk][Z] >= (CYL_HEIGHT+0.1)) { state = ST_TO_1; over_clicks = OVER_CLICKS; disk_incr[X] = (pole_offset[c_pole][X] - pole_offset[old_pole][X]) / (float)(over_clicks-1); disk_incr[Y] = (pole_offset[c_pole][Y] - pole_offset[old_pole][Y]) / (float)(over_clicks-1); disk_incr[Z] = 0.0; } break; case ST_DOWN: disk_offset[c_disk][Z] -= disk_incr[Z]; if (disk_offset[c_disk][Z] <= (disks_on_poles[c_pole].num_disks*0.2+disk_incr[Z])) { disk_offset[c_disk][Z] = disks_on_poles[c_pole].num_disks*0.2; disks_on_poles[old_pole].num_disks --; disks_on_poles[c_pole].disks[disks_on_poles[c_pole].num_disks ++] = c_disk; state = ST_READNEXT; } break; case ST_TO_1: case ST_TO_2: disk_offset[c_disk][X] += disk_incr[X]; disk_offset[c_disk][Y] += disk_incr[Y]; over_clicks --; if (over_clicks == 0) { state = ST_DOWN; disk_incr[X] = 0.0; disk_incr[Y] = 0.0; disk_incr[Z] = CYL_HEIGHT / (float)UP_CLICKS; disk_offset[c_disk][X] = pole_offset[c_pole][X]; /* paranoia */ disk_offset[c_disk][Y] = pole_offset[c_pole][Y]; } break; case ST_IDLE: break; } } glutPostRedisplay(); }
void MainWindow::callback_motion(int x, int y) { // Re-route motion callback MainWindow::master->mouseMoved(x, y); glutPostRedisplay(); }
void idle() { // animation du personnage ici glutPostRedisplay(); }
void MainWindow::callback_timer (int value) { glutPostRedisplay(); glutTimerFunc(15, callback_timer, 0); }
void MiroWindow::keyboard(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; case 'i': case 'I': { char str[1024]; sprintf(str, "miro_%d.ppm", time(0)); if (g_camera->isOpenGL()) { unsigned char* buf = new unsigned char[g_image->width()*g_image->height()*3]; glReadPixels(0, 0, g_image->width(), g_image->height(), GL_RGB, GL_UNSIGNED_BYTE, buf); g_image->writePPM(str, buf, g_image->width(), g_image->height()); } else { g_image->writePPM(str); } break; } case 'r': case 'R': g_camera->setRenderer(Camera::RENDER_RAYTRACE); break; case 'g': case 'G': g_camera->setRenderer(Camera::RENDER_OPENGL); break; case '+': m_scaleFact *= 1.5; break; case '-': m_scaleFact /= 1.5; break; case 'w': case 'W': g_camera->setEye(g_camera->eye() + m_scaleFact*g_camera->viewDir()); break; case 's': case 'S': g_camera->setEye(g_camera->eye() - m_scaleFact*g_camera->viewDir()); break; case 'q': case 'Q': g_camera->setEye(g_camera->eye() + m_scaleFact*g_camera->up()); break; case 'z': case 'Z': g_camera->setEye(g_camera->eye() - m_scaleFact*g_camera->up()); break; case 'v': case 'V': g_scene->togglePDraw(); break; case 'b': case 'B': g_scene->toggleDraw(); break; case 'a': case 'A': { Vector3 vRight = cross(g_camera->viewDir(), g_camera->up()); g_camera->setEye(g_camera->eye() - m_scaleFact*vRight); break; } case 'd': case 'D': { Vector3 vRight = cross(g_camera->viewDir(), g_camera->up()); g_camera->setEye(g_camera->eye() + m_scaleFact*vRight); break; } break; default: break; } glutPostRedisplay(); }
void update(void) { glutPostRedisplay(); }
void onTimer(int value) { glutPostRedisplay(); glutTimerFunc(5, &onTimer, value); }
// react to size changes void reshape(int w, int h) { mgr->resize(w, h); glutPostRedisplay(); }
void GLUTKeyboard(unsigned char key, int x, int y) { // Process keyboard button event switch (key) { case '~': { // Dump screen shot to file iX.jpg static char buffer[64]; static int image_count = 1; sprintf(buffer, "i%d.jpg", image_count++); screenshot_image_name = buffer; break; } case 'B': case 'b': show_bboxes = !show_bboxes; break; case 'C': case 'c': show_camera = !show_camera; break; case 'L': case 'l': show_lights = !show_lights; break; case 'R': case 'r': show_rays = !show_rays; break; case '1': case '!': show_global_samples = !show_global_samples; break; case '2': case '@': show_caustic_samples = !show_caustic_samples; break; case 'P': case 'p': show_photons = !show_photons; break; case 'S': case 's': show_shapes = !show_shapes; break; case 'T': case 't': show_frame_rate = !show_frame_rate; break; case ' ': viewer->SetCamera(scene->Camera()); break; case '-': case '_': viewer->ScaleWorld(center, 0.8); break; case '+': case '=': viewer->ScaleWorld(center, 1.25); break; case 27: // ESCAPE GLUTStop(); break; } // Remember mouse position GLUTmouse[0] = x; GLUTmouse[1] = GLUTwindow_height - y; // Remember modifiers GLUTmodifiers = glutGetModifiers(); // Redraw glutPostRedisplay(); }
static void timer(int value) { glutTimerFunc(30, timer, 1); glutPostRedisplay(); }