void hugWallL(int16 wallDistance){ if((wallDistance > (DIST_THRESHOLD_L - SENSOR_NOISE)) && (wallDistance < (DIST_THRESHOLD_L + SENSOR_NOISE))){ resetSpeed(); moveForward(10); } if(wallDistance > (DIST_THRESHOLD_L + SENSOR_NOISE)){ accelerateLeft(100); moveForward(10); } if(wallDistance < (DIST_THRESHOLD_L - SENSOR_NOISE)){ accelerateRight(100); moveForward(10); } return; }
bool Camera::pollEvent( SDL_Event *event ) // This should be called at regular intervals to avoid key-response lag { if( !SDL_PollEvent(event) ) { if( event->type==SDL_QUIT ) exit(0); if( event->type!=SDL_KEYDOWN ) { step(); return false; } } switch( event->key.keysym.sym ) { case SDLK_LEFT: if( event->key.keysym.mod & KMOD_SHIFT ) revolveLeft(); else if( event->key.keysym.mod & KMOD_CTRL ) rotateCW(); else if( event->key.keysym.mod & KMOD_ALT ) accelerateLeft(accInc); else panLeft(); break; case SDLK_RIGHT: if( event->key.keysym.mod & KMOD_SHIFT ) revolveRight(); else if( event->key.keysym.mod & KMOD_CTRL ) rotateCCW(); else if( event->key.keysym.mod & KMOD_ALT ) accelerateRight(accInc); else panRight(); break; case SDLK_UP: if( event->key.keysym.mod & KMOD_SHIFT ) revolveUp(); else if( event->key.keysym.mod & KMOD_ALT ) accelerateUp(accInc); else panUp(); break; case SDLK_DOWN: if( event->key.keysym.mod & KMOD_SHIFT ) revolveDown(); else if( event->key.keysym.mod & KMOD_ALT ) accelerateDown(accInc); else panDown(); break; case SDLK_f: case SDLK_PERIOD: accelerate(accInc); break; case SDLK_b: case SDLK_COMMA: accelerate(-accInc); break; case SDLK_SPACE: stop(); break; case SDLK_F1: accInc = accel[0]; break; case SDLK_F2: accInc = accel[1]; break; case SDLK_F3: accInc = accel[2]; break; case SDLK_F4: accInc = accel[3]; break; case SDLK_F5: accInc = accel[4]; break; case SDLK_F6: accInc = accel[5]; break; case SDLK_F7: accInc = accel[6]; break; case SDLK_F8: accInc = accel[7]; break; case SDLK_F9: accInc = accel[8]; break; case SDLK_ESCAPE: exit(0); break; case SDLK_TAB: if( event->key.keysym.mod & KMOD_SHIFT ) storeCamera(camStore); else restoreCamera(camStore); stop(); break; default: break; } step(); return true; }