/******************************************************************* * Function: char moveTrackLight(void) * Input Variables: void * Output Return: char * Overview: Tracks the light using only light lover behavior. When it is right infront of the light, it outputs a unique flag value that suppresses this behavior and inhibits the moveRetreat behavior. ********************************************************************/ char moveTrackLight(void) { // make a variable that keeps track of the light tracking behavior char isTracking = 0; // check to see if there is too much light (is the robot in front of the light?) if((leftLightVolt >= LIGHT_L_MAX)&&(rightLightVolt >= LIGHT_R_MAX)) { // set global flags to 1 lightFlagStatus = 1; retreatFlagStatus = 1; // Act as a docking robot LCD_printf("Arkin = Docked.\nPreparing to retreat.\n\n"); TMRSRVC_delay(3000);//wait 3 seconds LCD_clear; } // else run moveLight(Lover) behavior else { // inhibit LOVER behavior of move light isTracking = moveLight(LIGHT_LOVER); } return isTracking; }
/* * slowAnimate * ------ * step through the animation process */ void slowAnimate() { moveLight(); moveTowerTops(); moveShots(); checkCollisions(); moveMinions(); checkCollisions(); checkTowerRange(); }
/* * timer * ------ * game animation logic turned on or off here */ void timer(int toggle) { if (gameStarted) { if (gamePaused != DEF_GAME_PAUSED) { moveLight(); moveTowerTops(); moveShots(); checkCollisions(); moveMinions(); checkCollisions(); checkTowerRange(); } glutTimerFunc(50,timer,0); } redisplayAll(); }
void idle(){ previousTime = currentTime; currentTime = clock(); float timeInterval = (double)(currentTime - previousTime) / CLOCKS_PER_SEC; if (keyLeft || leftButton){ moveCamera(timeInterval * cameraRotationPerSec); } if (keyRight || rightButton){ moveCamera(-timeInterval * cameraRotationPerSec); } moveLight(-timeInterval * lightRotationPerSec); glutPostRedisplay(); }
void Window::handleKeyDown(SDL_keysym keySym) { bool topView; string v; switch (keySym.sym) { case SDLK_ESCAPE: quit = true; break; case SDLK_LEFT: moveLight(SDLK_LEFT); break; case SDLK_RIGHT: moveLight(SDLK_RIGHT); break; case SDLK_UP: moveLight(SDLK_UP); break; case SDLK_DOWN: moveLight(SDLK_DOWN); break; case SDLK_PAGEUP: moveLight(SDLK_PAGEUP); break; case SDLK_PAGEDOWN: moveLight(SDLK_PAGEDOWN); break; case SDLK_PLUS: pressedKeys[KEY_PLUS] = true; break; case SDLK_MINUS: pressedKeys[KEY_MINUS] = true; break; case SDLK_a: pressedKeys[KEY_a] = true; break; case SDLK_b: pressedKeys[KEY_b] = true; break; case SDLK_d: pressedKeys[KEY_d] = true; break; case SDLK_f: SDL_WM_ToggleFullScreen(sdlSurface); break; case SDLK_n: pressedKeys[KEY_n] = true; break; case SDLK_p: pressedKeys[KEY_p] = true; break; case SDLK_s: pressedKeys[KEY_s] = true; break; case SDLK_v: topView = toggleView(); v = topView ? "Enabled" : "Disabled"; cout << "Topview: " << v << endl; break; case SDLK_w: pressedKeys[KEY_w] = true; break; } }
void renderScene(void) { //Set up Viewport 1 scene // Use the Projection Matrix glMatrixMode(GL_PROJECTION); // Reset Matrix glLoadIdentity(); glScissor(0, 0, (GLsizei) windowWidth, (GLsizei) windowHeight*0.9); glEnable(GL_SCISSOR_TEST); glClearDepth(1.0); glClearColor(0.49f, 0.75f, 0.93f, 1.0f); // Set the viewport to be the entire window glViewport (0, 0, (GLsizei) windowWidth, (GLsizei) windowHeight*0.9); // Set the correct perspective. if (viewMode == PERSPECTIVE) gluPerspective(45.0f*zoom, ratio, 1.0f, 1000.0f); else if (viewMode == ORTHOGRAPHIC) glOrtho((-windowWidth/50)*zoom, (windowWidth/50)*zoom, (-windowHeight/50)*zoom, (windowHeight/50)*zoom, 1.0f, 1000); // Get Back to the Modelview glMatrixMode(GL_MODELVIEW); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Decide if wire frame or shaded if (polygonMode == WIREFRAME) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); else if (polygonMode == SHADED) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glLoadIdentity(); moveCamera(); lx = (sin(heliRot+PI)); lz = (cos(heliRot+PI)); float camX = curX + lx * 10.0f; float camZ = curZ + lz * 10.0f; //Set camera if (viewPerson == THIRD) { gluLookAt(eyeX+curX, eyeY, eyeZ+curZ, curX, 0.0f, curZ, upX, upY, upZ); } else if (viewPerson == FIRST) { gluLookAt(camX, 1.5f, camZ, camX+lx, 1.5f, camZ+lz, 0.0f, 1.0f, 0.0f); } glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); // smooth out lighting glEnable(GL_NORMALIZE); // normalize lighting GLfloat mat_specular[] = {0.3, 0.3, 0.3, 1.0}; GLfloat mat_shininess[] = { 10.0 }; glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); if (lightingEnabled) { glEnable(GL_LIGHTING); if (sunlight) { setSunlight(); } else { glDisable(GL_LIGHT0); } if (thirdPersonLight) { setThirdPersonLight(); } else { glDisable(GL_LIGHT3); } } else { glDisable(GL_LIGHTING); } glPushMatrix(); glTranslatef(0.0f, -10, 0.0f); drawGround(250, 100); glPopMatrix(); glPushMatrix(); glTranslatef(0.0f, -9.9, 0.0f); drawTrack(100.0, 100.0); glPopMatrix(); glPushMatrix(); moveHelicopter(); glRotatef(heliRot/PI*180, 0.0f, 1.0f, 0.0f); drawHelicopter(); if (lightingEnabled) { if (circleLight) { moveLight(); setCircularLight(); } else { glDisable(GL_LIGHT2); } } glPopMatrix(); //Set up Viewport 2 scene // Use the Projection Matrix glMatrixMode(GL_PROJECTION); // Reset Matrix glLoadIdentity(); glScissor(0, windowHeight*0.9, (GLsizei) windowWidth, (GLsizei) windowHeight*0.1); glEnable(GL_SCISSOR_TEST); glClearDepth(1.0); glClearColor(1, 1, 1, 1); // Set the viewport to be the entire window glViewport (0, windowHeight*0.9, (GLsizei) windowWidth, (GLsizei) windowHeight*0.1); // Set the correct perspective. // Get Back to the Modelview glMatrixMode(GL_MODELVIEW); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); frame++; time=glutGet(GLUT_ELAPSED_TIME); if (time - timebase > 1000) { sprintf(s,"FPS:%4.2f", frame*1000.0/(time-timebase)); timebase = time; frame = 0; } glColor3f(0.0f,0.0f,0.0f); glPushMatrix(); glLoadIdentity(); setOrthographicProjection(); glTranslatef(100.0f, 150, 0.0f); renderBitmapString(5,30,0,GLUT_BITMAP_HELVETICA_18,s); glPopMatrix(); restorePerspectiveProjection(); glutSwapBuffers(); }