//----------------------------------------------------------------------------- // // VActorPhysicsController::processCollisions(); // // ... // //----------------------------------------------------------------------------- void VActorPhysicsController::processCollisions( void ) { // Find & Resolve Collisions. Collision *collision; if ( findCollision( collision ) ) { // Solve the Collision. solveCollision( collision ); } }
void PickHandler::updateRay(const sofa::defaulttype::Vector3 &position,const sofa::defaulttype::Vector3 &orientation) { if (!interactorInUse || !mouseCollision) return; mouseCollision->getRay(0).setOrigin( position+orientation*interaction->mouseInteractor->getDistanceFromMouse() ); mouseCollision->getRay(0).setDirection( orientation ); simulation::MechanicalPropagateOnlyPositionVisitor(sofa::core::MechanicalParams::defaultInstance(), 0, sofa::core::VecCoordId::position(), true).execute(mouseCollision->getContext()); simulation::MechanicalPropagateOnlyPositionVisitor(sofa::core::MechanicalParams::defaultInstance(), 0, sofa::core::VecCoordId::freePosition(), true).execute(mouseCollision->getContext()); if (needToCastRay()) { lastPicked=findCollision(); setCompatibleInteractor(); interaction->mouseInteractor->setMouseRayModel(mouseCollision.get()); interaction->mouseInteractor->setBodyPicked(lastPicked); for (unsigned int i=0; i<callbacks.size(); ++i) { callbacks[i]->execute(lastPicked); } } if(mouseButton != NONE) { switch (mouseStatus) { case PRESSED: { if (operations[mouseButton]) operations[mouseButton]->start(); mouseStatus=ACTIVATED; break; } case RELEASED: { if (operations[mouseButton]) operations[mouseButton]->end(); mouseStatus=DEACTIVATED; break; } case ACTIVATED: { if (operations[mouseButton]) operations[mouseButton]->execution(); } case DEACTIVATED: { } } } for (unsigned int i=0; i<operations.size(); ++i) { if (operations[i]) operations[i]->wait(); } }
Rect* Rect::findCollision(prec_t offset_x, prec_t offset_y, World* world) { if (container && world == nullptr) { return findCollision(offset_x, offset_y, container); } else if (world) { if (!world->use_partitioning) return findCollisionInContext(&(world->v_rect), offset_x, offset_y); else { int min_x = (x + offset_x) / container->bucket_width; int max_x = (x + offset_x + w) / container->bucket_width; int min_y = (y + offset_y) / container->bucket_height; int max_y = (y + offset_y + h) / container->bucket_height; for (int i = min_x; i <= max_x; i++) for (int j = min_y; j <= max_y; j++) { if (bucket* b = world->getBucket(i, j)) if (Rect* r = findCollisionInContext(&b->rect_v, offset_x, offset_y)) return r; } } } return nullptr; }
//**************************************************************************** ErrorCode MD5UtilCore::processCollide (const CommandLineOptions& options, std::string& output) { static const std::string& NO_COLLISION_FOUND = "No collision found for current hash with given settings."; if (options.getHelpMode ()) { std::cout << MSG_COLLIDE_HELP << std::endl; return ErrorCode::NONE; } if (options.getInputText ().length () == 0 || options.getAlphabet ().length () == 0) { return ErrorCode::COLLIDE_USAGE_ERROR; } if (findCollision (options, output)) { if (options.getOutputFilename ().length () != 0) { if (!saveToFile (options.getOutputFilename (), output)) { return ErrorCode::FILE_WRITE_ERROR; } } } else { output = NO_COLLISION_FOUND; } return ErrorCode::NONE; }
Box IMGUI::placeGroup(int flags){ Box pos, out; Box m_freeRect = Box(0,0,m_maxHorizontal,m_maxVertical); if(flags & LayoutVertical){ if(flags & AlignLeft && flags & AlignTop){ pos = Box(m_freeRect.x, m_freeRect.y+m_freeRect.w,0,0); while(findCollision(pos, out)){ if(out.y + out.w < 300) pos += Box(out.z+1,0,0,0); else pos -= Box(0,out.w+1,0,0); } pos.z = m_freeRect.z - pos.x + m_freeRect.x; pos.w = m_freeRect.y - pos.y; } else if(flags & AlignRight && flags & AlignTop){ pos = Box(m_freeRect.x+m_freeRect.z, m_freeRect.y+m_freeRect.w,0,0); while(findCollision(pos, out)){ // if(out.y + out.w < 300) if(out.z < out.w) pos -= Box(out.z+1,0,0,0); else pos -= Box(0,out.w+1,0,0); } pos.z = m_freeRect.x - pos.x; pos.w = m_freeRect.y - pos.y; } else if(flags & AlignLeft && flags & AlignBottom){ pos = Box(m_freeRect.x, m_freeRect.y,0,0); while(findCollision(pos, out)){ if(out.z < out.w) // if(out.y + out.w > group.m_freeRect.w/2) pos += Box(out.z+1,0.f,0.f,0.f); else pos += Box(0.f,out.w+1,0.f,0.f); } pos.z = m_freeRect.x+m_freeRect.z - pos.x; pos.w = m_freeRect.y+m_freeRect.w - pos.y; } else if(flags & AlignRight && flags & AlignBottom){ pos = Box(m_freeRect.x+m_freeRect.z, m_freeRect.y,0,0); while(findCollision(pos, out)){ if(out.y + out.w > 250) pos -= Box(out.z+1,0,0,0); else pos += Box(0,out.w+1,0,0); } pos.z = m_freeRect.x - pos.x; pos.w = m_freeRect.y+m_freeRect.w - pos.y; } } else if(flags & LayoutHorizontal){ if(flags & AlignLeft && flags & AlignTop){ pos = Box(m_freeRect.x, m_freeRect.y+m_freeRect.w,0,0); while(findCollision(pos, out)){ if(out.x + out.z > 300) pos -= Box(0,out.w+1,0,0); else pos += Box(out.z+1,0,0,0); } pos.z = m_freeRect.z - pos.x + m_freeRect.x; pos.w = m_freeRect.y - pos.y; } else if(flags & AlignRight && flags & AlignTop){ pos = Box(m_freeRect.x+m_freeRect.z, m_freeRect.y+m_freeRect.w,0,0); while(findCollision(pos, out)){ if(out.w < out.z){ pos -= Box(0,out.w+1,0,0); } else{ pos -= Box(out.z+1,0,0,0); } } pos.z = m_freeRect.x - pos.x; pos.w = m_freeRect.y - pos.y; } else if(flags & AlignLeft && flags & AlignBottom){ pos = Box(m_freeRect.x, m_freeRect.y,0,0); while(findCollision(pos, out)){ if(out.x + out.z > 300) pos += Box(0.f,out.w+1,0.f,0.f); else pos += Box(out.z+1,0.f,0.f,0.f); } pos.z = m_freeRect.x+m_freeRect.z - pos.x; pos.w = m_freeRect.y+m_freeRect.w - pos.y; } else if(flags & AlignRight && flags & AlignBottom){ pos = Box(m_freeRect.x+m_freeRect.z, m_freeRect.y,0,0); while(findCollision(pos, out)){ if(out.x + out.z < 300) pos += Box(0,out.w+1,0,0); else pos -= Box(out.z+1,0,0,0); } pos.z = m_freeRect.x - pos.x; pos.w = m_freeRect.y+m_freeRect.w - pos.y; } } return pos; }
int main(int argc, char * argv[]) { bool firsttime = true; ostringstream convert; convert << playerScore; playerScoreTX = convert.str(); srand(time(NULL)); GameTextures a, b, c, d, e; int indicator = 0; int adder = 150; int goSpeed = 30; if(!init()) cout << "\nSDL Failed to Initialize. ERROR: " << SDL_GetError(); else { if(!loadMedia(a) || !loadMedia(b) || !loadMedia(c) || !loadMedia(d) || !loadMedia(e)) cout << "\nLoading media failed. ERROR: " << SDL_GetError(); else if(!renderScore(36)) cout << "\nSDL Has Failed to handle text. ERROR: " << SDL_GetError(); else { bool quit = false; SDL_Event event; mainShip ship; monsterGroup MOBS; shipProtector protectora(150, 515); shipProtector protectorb(375, 515); shipProtector protectorc(600, 515); shipProtector protectord(825, 515); shipProtector protectore(1025, 515); protectora.setColliders(); protectorb.setColliders(); protectorc.setColliders(); protectord.setColliders(); protectore.setColliders(); MOBS.spawn(head); while (!quit) { while(SDL_PollEvent(&event) != 0) { if(event.type == SDL_QUIT) quit = true; ship.handleEvent(event); } if(!dead && monstersKilled != 55) { if(!skip) { ship.moveShip(); if(MOBS.getHeading(head)) { goSpeed -= 1; if(goSpeed <= 3) goSpeed = 3; } if(indicator % goSpeed == 0) { track = false; MOBS.setDirection(head); } bgTexture.render(0,0); textTexture.render(140, 7); switch(shipLives) { case 3: { shipLivesTexture.render(1045, 0); shipLivesTexture.render(1125, 0); shipLivesTexture.render(1205, 0); break; } case 2: { shipLivesTexture.render(1045, 0); shipLivesTexture.render(1125, 0); break; } case 1: { shipLivesTexture.render(1045, 0); break; } case 0: { gameOver.render(0 , 0); dead = true; break; } } psetColliders(pbulletContainer); setColliders(bulletContainer); ship.setShipColliders(); MOBS.setGColliders(head); pfindCollision(pbulletContainer, ship); findCollision(bulletContainer, protectora, MOBS, a); findCollision(bulletContainer, protectorb, MOBS, b); findCollision(bulletContainer, protectorc, MOBS, c); findCollision(bulletContainer, protectord, MOBS, d); findCollision(bulletContainer, protectore, MOBS, e); pfindCColision(pbulletContainer, protectora, a); pfindCColision(pbulletContainer, protectorb, b); pfindCColision(pbulletContainer, protectorc, c); pfindCColision(pbulletContainer, protectord, d); pfindCColision(pbulletContainer, protectore, e); ostringstream convert; convert << playerScore; playerScoreTX = convert.str(); renderScore(36); if(shootlevel >= 15) { if(indicator % shootlevel == 0) { int index = rand() % 55 + 1; MOBS.shoot(head, index); } } else if(shootlevel < 15) { if(indicator % 15 == 0) { int index = rand() % 55 + 1; MOBS.shoot(head, index); } } ship.render(); protectora.renderProtector(1, killTarget, a); protectorb.renderProtector(2 , -1, b); protectorc.renderProtector(3, -1, c); protectord.renderProtector(4, -1, d); protectore.renderProtector(5, -1, e); MOBS.renderMGroup(head); renderBullet(bulletContainer, 0); prenderBullet(pbulletContainer, 0); if(indicator % 120 == 0) cout << "\nYour Score : " << playerScore; SDL_RenderPresent(mainRenderer); // RENDER ALL TO FRONT BUFFER indicator++; } } else if(dead) { const Uint32 timeEntered = SDL_GetTicks(); SDL_RenderClear(mainRenderer); gameOver.render(0,0); SDL_RenderPresent(mainRenderer); if(SDL_GetTicks() - 6000 == timeEntered) quit = true; else skip = true; } else if(monstersKilled >= 55) { if(firsttime) { int tempscore = 1000; tempscore = tempscore / (SDL_GetTicks() / 1000); playerScore = playerScore + (tempscore * 25); ostringstream convert; convert << playerScore; playerScoreTX = convert.str(); firsttime = false; } else { const Uint32 timeEntered = SDL_GetTicks(); SDL_RenderClear(mainRenderer); youWin.render(0, 0); renderScore(100); textTexture.render(570, 590); SDL_RenderPresent(mainRenderer); skip = true; } } } } } close(a); close(b); close(c); close(d); close(e); return 0; }