void Grid::ResolveCollisions(Entity* ent) { RigidBody* rigid = ent->GetComponent<RigidBody>(); if (rigid) { rigid->ResolveCollisions(); BoxCollider* box = ent->GetComponent<BoxCollider>(); if (box) { Vector3& max = box->GetMaxCoord(); Vector3& min = box->GetMinCoord(); if (min.x < 0 || min.y < 0 || max.x > GridWidth || max.y > GridHeight) ent->OnCollisionEnter(Collision()); } } for (auto &child : ent->GetChildren()) { ResolveCollisions(child); } }
void Grid::PopulateCells(Entity* ent) { BoxCollider* box = ent->GetComponent<BoxCollider>(); if (box) { box->cell = cell; box->part.clear(); Vector3 min = box->GetMinCoord(); Vector3 max = box->GetMaxCoord(); min.x /= GridWidth; min.x *= NumberOfPartitionsX; max.x /= GridWidth; max.x *= NumberOfPartitionsX; min.y /= GridHeight; min.y *= NumberOfPartitionsY; max.y /= GridHeight; max.y *= NumberOfPartitionsY; for (int i = min.x; i <= max.x; ++i) for (int j = min.y; j <= max.y; ++j) { Partition* c = GetPartition(i, j); if (c) { c->Add(ent); box->part.push_back(c); } } } for (auto &child : ent->GetChildren()) { if (child->IsActive()) PopulateCells(child); } }