void Model::HandleOverlaps(ObjectList &objects) { if(objects.size() <= 1) // no overlap possible with one item return; ObjectList::iterator i = objects.begin(); for(i = objects.begin(); i != objects.end(); ++i) { if (i->isDead()) continue; ObjectList::iterator j = i; for(++j; j != objects.end(); ++j) { if(j->isDead()) continue; if(IsOverlapping(*i, *j)) { // remove the objects from the list i->kill(); j->kill(); break; // inner while loop is complete } } }; }
PhysicalObj* PhysicalObj::CollidedObjectXY(const Point2i & position) const { if (IsOutsideWorldXY(position)) return NULL; Rectanglei rect(position.x + m_test_left, position.y + m_test_top, m_width - m_test_right - m_test_left, m_height - m_test_bottom - m_test_top); if (m_collides_with_characters) { FOR_ALL_LIVING_CHARACTERS(team,character) { // We check both objet if one overlapses the other if (&(*character) != this && !IsOverlapping(&(*character)) && !character->IsOverlapping(this) && character->Intersect(rect)) { return (PhysicalObj*) &(*character); } else if (IsOverlapping(&(*character)) != character->IsOverlapping(this)) { //printf("Check 0\n"); } } } if (m_collides_with_objects) { if (m_is_character) { FOR_EACH_OBJECT(it) { PhysicalObj * object=*it; // We check both objet if one overlapses the other if (object->m_collides_with_characters) { if (object != this && !IsOverlapping(object) && !object->IsOverlapping(this) && object->m_collides_with_objects && object->Intersect(rect)) { return object; } else if (IsOverlapping(object) != object->IsOverlapping(this)) { //printf("Check1\n"); } } } } else { FOR_EACH_OBJECT(it) { PhysicalObj * object=*it; // We check both objet if one overlapses the other if (object != this && !IsOverlapping(object) && !object->IsOverlapping(this) && object->m_collides_with_objects && object->Intersect(rect)) { return object; } else if (IsOverlapping(object) != object->IsOverlapping(this)) { //printf("Check2\n"); } } } }
std::list<Contact> GetSpecContacts( Circle * pA, Circle * pB ) { // find and normalize distance vec2 d = pB->v2Center - pA->v2Center; vec2 n = glm::normalize( d ); // contact points along circumference vec2 a_pos = pA->v2Center + n * pA->Radius(); vec2 b_pos = pB->v2Center - n * pB->Radius(); // distance between circumferences float dist = glm::length( a_pos - b_pos ); if ( IsOverlapping( pA, pB ) ) { dist = -dist; // std::cout << "Negating circle dist" << std::endl; } // Construct and return return{ Contact( pA, pB, a_pos, b_pos, n, dist ) }; }
void LMNonMaximumSuppression::ComputeDetection(MatchingCostMap &matchingCostMap,double threshold,double overlapThresh,vector<LMDetWind> &wind,int varyingQuerySize) { wind.clear(); // Scan the matching cost map to find the hypotheses with a matching cost less than the threshold, // and construct the detection windows for these hypotheses. vector<LMDetWind> detWinds; if(varyingQuerySize) ComputeValidWindVaryingQuerySize(matchingCostMap,detWinds,threshold); else ComputeValidWindVaryingTemplateSize(matchingCostMap,detWinds,threshold); if(detWinds.size()==0) { cout<<"\t "<<wind.size()<<"//"<<detWinds.size()<<endl; return; } // Sort the window array in the ascending order of matching cost. LMDetWind *tmpWind = new LMDetWind [detWinds.size()]; for(unsigned int i=0;i<detWinds.size();i++) tmpWind[i] = detWinds[i]; MMFunctions::Sort(tmpWind,detWinds.size()); // Scan the array. // If a query detection window does not overlap the other detection windows which have a smaller cost, // create it as a new detection. Otherwise increasing the hit count for the overlapped window. for(unsigned int i=0;i<detWinds.size();i++) { if(!IsOverlapping(tmpWind[i],wind,overlapThresh)) wind.push_back(tmpWind[i]); } cout<<"\t "<<wind.size()<<"//"<<detWinds.size()<<endl; delete [] tmpWind; }
/* <4f029e> ../game_shared/bot/nav_file.cpp:562 */ NavErrorType CNavArea::PostLoad() { NavErrorType error = NAV_OK; // connect areas together for (int d = 0; d < NUM_DIRECTIONS; ++d) { NavConnectList::iterator iter; for (iter = m_connect[d].begin(); iter != m_connect[d].end(); ++iter) { NavConnect *connect = &(*iter); unsigned int id = connect->id; connect->area = TheNavAreaGrid.GetNavAreaByID(id); if (id && connect->area == NULL) { CONSOLE_ECHO("ERROR: Corrupt navigation data. Cannot connect Navigation Areas.\n"); error = NAV_CORRUPT_DATA; } } } // resolve approach area IDs for (int a = 0; a < m_approachCount; ++a) { m_approach[a].here.area = TheNavAreaGrid.GetNavAreaByID(m_approach[a].here.id); if (m_approach[a].here.id && m_approach[a].here.area == NULL) { CONSOLE_ECHO("ERROR: Corrupt navigation data. Missing Approach Area (here).\n"); error = NAV_CORRUPT_DATA; } m_approach[a].prev.area = TheNavAreaGrid.GetNavAreaByID(m_approach[a].prev.id); if (m_approach[a].prev.id && m_approach[a].prev.area == NULL) { CONSOLE_ECHO("ERROR: Corrupt navigation data. Missing Approach Area (prev).\n"); error = NAV_CORRUPT_DATA; } m_approach[a].next.area = TheNavAreaGrid.GetNavAreaByID(m_approach[a].next.id); if (m_approach[a].next.id && m_approach[a].next.area == NULL) { CONSOLE_ECHO("ERROR: Corrupt navigation data. Missing Approach Area (next).\n"); error = NAV_CORRUPT_DATA; } } // resolve spot encounter IDs SpotEncounter *e; for (SpotEncounterList::iterator iter = m_spotEncounterList.begin(); iter != m_spotEncounterList.end(); ++iter) { e = &(*iter); e->from.area = TheNavAreaGrid.GetNavAreaByID(e->from.id); if (e->from.area == NULL) { CONSOLE_ECHO("ERROR: Corrupt navigation data. Missing \"from\" Navigation Area for Encounter Spot.\n"); error = NAV_CORRUPT_DATA; } e->to.area = TheNavAreaGrid.GetNavAreaByID(e->to.id); if (e->to.area == NULL) { CONSOLE_ECHO("ERROR: Corrupt navigation data. Missing \"to\" Navigation Area for Encounter Spot.\n"); error = NAV_CORRUPT_DATA; } if (e->from.area && e->to.area) { // compute path float halfWidth; ComputePortal(e->to.area, e->toDir, &e->path.to, &halfWidth); ComputePortal(e->from.area, e->fromDir, &e->path.from, &halfWidth); const float eyeHeight = HalfHumanHeight; e->path.from.z = e->from.area->GetZ(&e->path.from) + eyeHeight; e->path.to.z = e->to.area->GetZ(&e->path.to) + eyeHeight; } // resolve HidingSpot IDs for (SpotOrderList::iterator oiter = e->spotList.begin(); oiter != e->spotList.end(); ++oiter) { SpotOrder *order = &(*oiter); order->spot = GetHidingSpotByID(order->id); if (order->spot == NULL) { CONSOLE_ECHO("ERROR: Corrupt navigation data. Missing Hiding Spot\n"); error = NAV_CORRUPT_DATA; } } } // build overlap list // TODO: Optimize this for (NavAreaList::iterator oiter = TheNavAreaList.begin(); oiter != TheNavAreaList.end(); ++oiter) { CNavArea *area = *oiter; if (area == this) continue; if (IsOverlapping(area)) m_overlapList.push_back(area); } return error; }