/* The main event Loop */ int sdlLoop() { bool quit=false; bool redraw_needed = false; // true whan a scene needs a redraw SDL_Event event; while( !quit ) { SDL_WaitEvent(&event); switch( event.type ) { case SDL_QUIT: quit = true; break; case SDL_VIDEORESIZE : myReshapeFunc(event.resize.w,event.resize.h); break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_ESCAPE: exit(0); break; case SDLK_F1: drawMode= (drawMode+1)%5; printf("Current Mode %i\n",drawMode); break; case SDLK_HOME: track.Reset(); break; case SDLK_SPACE: trackballMode= (trackballMode+1)%2; printf("Trackball Mode %i\n",drawMode); SetTrackball(trackballMode); break; default: track.ButtonDown( SDL2VCG( event.key.keysym.sym) ); } redraw_needed = true; break; case SDL_KEYUP: track.ButtonUp( SDL2VCG( event.key.keysym.sym) ); break; case SDL_MOUSEBUTTONDOWN: switch(event.button.button) { case SDL_BUTTON_WHEELUP: track.MouseWheel( 1); redraw_needed = true; break; case SDL_BUTTON_WHEELDOWN: track.MouseWheel(-1); redraw_needed = true; break; default: track.MouseDown(event.button.x, (height - event.button.y), SDL2VCG(event.button.button) ); break; } break; case SDL_MOUSEBUTTONUP: track.MouseUp(event.button.x, (height - event.button.y), SDL2VCG(event.button.button) ); break; break; case SDL_MOUSEMOTION: while(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_MOUSEMOTIONMASK)); track.MouseMove(event.button.x, (height - event.button.y)); redraw_needed = true; break; case SDL_TIMER: if (onTimer()) redraw_needed = true; if (redraw_needed) sendRedraw(); // justs sends a redraw event! redraw_needed = false; break; case SDL_VIDEOEXPOSE: // any rendering is done ONLY here. display(); drainRedrawEvents(); break; default: break; } } SDL_Quit(); return -1; }
/* Sets the trackball in a new mode: standard mode (rotate object in front of camera) or Navigation mode (navigate around/inside object) */ void SetTrackball(int mode){ // we define all possible trackModes that we could be using (static) static vcg::PolarMode polarMode; static vcg::SphereMode sphereMode; static vcg::NavigatorWasdMode navigatorMode; static vcg::InactiveMode inactiveMode; static vcg::ScaleMode scaleMode; static vcg::PanMode panMode; static vcg::ZMode zMode; // customize navigation mode... navigatorMode.SetTopSpeedsAndAcc(1.2f,0.6f,6); // this adds a neat human stepping effect navigatorMode.SetStepOnWalk(0.5f,0.015f); track.modes.clear(); track.Reset(); switch (mode) { case 1: // switch to navigator mode track.modes[vcg::Trackball::BUTTON_NONE] = NULL; track.modes[vcg::Trackball::WHEEL] = track.modes[vcg::Trackball::BUTTON_LEFT] = track.idle_and_keys_mode = &navigatorMode; track.inactive_mode = NULL; // nothing to draw when inactive track.SetPosition( observerPos ); break; default: // sweitch to default trackmode -- this is equivalent to a call to track->SetDefault() track.modes[vcg::Trackball::BUTTON_NONE] = NULL; track.modes[vcg::Trackball::BUTTON_LEFT] = &sphereMode; track.modes[vcg::Trackball::BUTTON_LEFT | vcg::Trackball::KEY_CTRL] = track.modes[vcg::Trackball::BUTTON_MIDDLE] = &panMode; track.modes[vcg::Trackball::WHEEL] = track.modes[vcg::Trackball::BUTTON_LEFT | vcg::Trackball::KEY_SHIFT] = &scaleMode; track.modes[vcg::Trackball::BUTTON_LEFT | vcg::Trackball::KEY_ALT] = &zMode; track.modes[vcg::Trackball::BUTTON_MIDDLE | vcg::Trackball::KEY_ALT] = track.idle_and_keys_mode = &sphereMode; track.inactive_mode = &inactiveMode; // draw a sphere when inactive track.SetPosition( objectPos ); } }