void Logic::HandleEvent(const SDL_Event& event) { if( pieces_.get_matches() >= layout_.total()) { // do nothing } else if( event.type == SDL_MOUSEBUTTONDOWN ) { cursor_.position = layout_.ScreenToGame(event.button.x, event.button.y); if(event.button.button == SDL_BUTTON_LEFT/* && !rightdrag*/) { leftDown(); } else if(event.button.button == SDL_BUTTON_RIGHT) { rightDown(); } } else if( event.type == SDL_MOUSEBUTTONUP ) { cursor_.position = layout_.ScreenToGame(event.button.x, event.button.y); if(event.button.button == SDL_BUTTON_LEFT/* && rect_up*/) { leftUp(); } else if(event.button.button == SDL_BUTTON_RIGHT) { rightUp(); } } else if( event.type == SDL_MOUSEMOTION ) { // Keep track of the mouse position in a handy format. cursor_.position = layout_.ScreenToGame(event.motion.x, event.motion.y); } }
void individualMove(struct board_position pos, int i, int j, int turn, int *nc, char *child_ptr) { struct board_position p; if (pos.board[i][j] != WPAWN) { p = pos; if (leftDown(p.board, i, j)) { insert_into_array(p, *nc, child_ptr); (*nc)++; } p = pos; if (rightDown(p.board, i, j)) { insert_into_array(p, *nc, child_ptr); (*nc)++; } } if (pos.board[i][j] != BPAWN) { p = pos; if (leftUp(p.board, i, j)) { insert_into_array(p, *nc, child_ptr); (*nc)++; } p = pos; if (rightUp(p.board, i, j)) { insert_into_array(p, *nc, child_ptr); (*nc)++; } } stacks(pos, i, j, turn, nc, child_ptr); }
void Keyboard::checkKeys(System* system) { if( system->action.type == SDL_KEYDOWN ) { switch(system->action.key.keysym.sym) { case SDLK_UP: break; case SDLK_DOWN: break; case SDLK_LEFT: leftDown(system); break; case SDLK_RIGHT: rightDown(system); break; case SDLK_LSHIFT: { // this is a stack frame variable, for use of local hero Hero* hero = system->sprite_director->getHero(); if(!(hero->jumping) ) { Mix_PlayChannel( -1, system->jukebox->jump, 0 ); hero->jump_start_time = SDL_GetTicks(); hero->jumping = true; } } break; } } else if( system->action.type == SDL_KEYUP ) { //Adjust the velocity switch( system->action.key.keysym.sym ) { case SDLK_DOWN: break; case SDLK_LEFT: leftUp(system); break; case SDLK_RIGHT: rightUp(system); break; case SDLK_LSHIFT: break; } } }
// ------------------------------------------------------ render -------------------------------------------------------------------- // void Scene::render(Image &img){ int w = img.width(); int h = img.height(); Vector right = ((center-eye).cross(up)).normalized(); // right vector double pSize = up.length(); // pixel size as length of up vector Point leftUp(center - (w/2)*pSize*right + (h/2)*pSize*up); // pixel left upper bound double zBuffer[w][h]; cout << "eye: " << eye.x << "," << eye.y << "," << eye.z << endl; cout << "center: " << center.x << "," << center.y << "," << center.z << endl; cout << "up: " << up.x << "," << up.y << "," << up.z << endl; cout << "right: " << right.x << "," << right.y << "," << right.z << endl; cout << "viewSize: " << w << "," << h << endl; cout << "leftUp: " << leftUp.x << "," << leftUp.y << "," << leftUp.z << endl; cout << "pSize: " << pSize << endl; cout << "maxRecursionDepth: " << maxRecursionDepth << endl; cout << "superSamplingFactor: " << superSamplingFactor << endl; cout << "apertureSamples: " << apertureSamples << endl; cout << "apertureRadius: " << apertureRadius << endl; Color color; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { Point pixel = leftUp + (x*pSize*right) - (y*pSize*up); // go to correct x,y position if (rendermode == phong || rendermode == gooch){ img(x,y) = superSample(pixel, right, pSize); } if (rendermode == normal){ Ray ray(eye, ((pixel + right*pSize/2 - up*pSize/2)-eye).normalized()); img(x,y) = traceNormal(ray); } if (rendermode == zbuffer){ Ray ray(eye, ((pixel + right*pSize/2 - up*pSize/2)-eye).normalized()); zBuffer[x][y] = traceZBuffer(ray); } } } if (rendermode == zbuffer){ for (int y = 0; y < h; y++){ for (int x = 0; x < w; x++){ color.set((-1*(zBuffer[x][y]-minZB)/(maxZB-minZB))+1); color.clamp(); img(x,y) = color; } } } }