Created
April 8, 2017 20:06
-
-
Save PoetaKodu/98c1d823c2ed9d70b2020d73a9b48481 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////// | |
IAISense::TQueryActors CSightSense::QueryActors(bool(*filterFunc)(IActor * const)) | |
{ | |
// W tej funkcji wykonujemy od nowa sprawdzenie jacy aktorzy sa w polu widzenia. | |
// Na poczatku musimy porzucic stare wyniki. | |
m_sensedActors.clear(); | |
// Bierzemy liste aktorow ze sceny. | |
auto actors = CGame::Instance().GetLevel()->GetActors(); | |
// Zapisujemy sobie pozycje wlasciciela do pomocniczej zmiennej | |
auto parentLocation = m_owner.GetLocation(); | |
// Sprawdzamy kazdego aktora ze sceny | |
for (auto actor : actors) | |
{ | |
/* Wykluczamy ze sprawdzenia wlasciciela zmyslu. | |
(!filterFunc || filterFunc(actor)) "przepusci" aktora dalej jesli: | |
a) niezdefiniowano funkcji filtra (filterFunc == nullptr) | |
b) funkcja filtra zostala zdefiniowana i zwrocila true | |
*/ | |
if (actor != &m_owner && (!filterFunc || filterFunc(actor))) | |
{ | |
// Zapisujemy pozycje aktualnie sprawdzanego aktora do pomocniczej zmiennej | |
auto actorLocation = actor->GetLocation(); | |
// Sprawdzamy czy aktor jest w zasiegu | |
if (actorLocation.Distance(parentLocation) <= m_sightDistance) | |
{ | |
/* Musimy sobie policzyc kat, w ktorym musialby patrzec wlasciciel, zeby patrzec dokladnie w kierunku sprawdzanego aktora. | |
Robi sie to w ten sposob. A = pozycja wlasciciela, B = pozycja sprawdzanego | |
kat = atan2(B.y - A.y, B.x - A.x). Nastepnie kat konwertujemy z radianow na stopnie (kat = kat / Pi * 180st) | |
*/ | |
float angle = atan2(actorLocation.y - parentLocation.y, actorLocation.x - parentLocation.x) / grim::Math::Pi * 180.f; | |
/* Sprawdzamy |kat| < kat widzenia. Jesli tak to gracz jest w polu widzenia. */ | |
if (grim::Math::Absolute(angle) < m_sightAngle) | |
{ | |
// Dodajemy sprawdzanego gracza jako poprawny wynik. | |
m_sensedActors.push_back(actor); | |
} | |
} | |
} | |
} | |
return m_sensedActors; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment