|
|
|
@@ -13,46 +13,73 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
|
|
|
|
transform->Position[2] += parentTransform->Position[2];
|
|
|
|
|
}
|
|
|
|
|
LOG_INFO("Updating entity %i with parent %i", entity, parent);
|
|
|
|
|
|
|
|
|
|
auto entities = m_World->GetEntities();
|
|
|
|
|
|
|
|
|
|
for (auto pair : *entities) {
|
|
|
|
|
EntityID entity2 = pair.first;
|
|
|
|
|
EntityID parent2 = pair.second;
|
|
|
|
|
|
|
|
|
|
// Check if entity2 is a child of entity
|
|
|
|
|
/*auto currentParent = parent;
|
|
|
|
|
bool childOfEntity2 = false;
|
|
|
|
|
while (currentParent != 0) {
|
|
|
|
|
if (currentParent == entity2) {
|
|
|
|
|
childOfEntity2 = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
currentParent = entities[currentParent];
|
|
|
|
|
}
|
|
|
|
|
if (childOfEntity2)
|
|
|
|
|
continue;*/
|
|
|
|
|
|
|
|
|
|
// Check if we're the parent to entity2
|
|
|
|
|
|
|
|
|
|
//pair.first, pair.second;
|
|
|
|
|
if(entity == entity2)
|
|
|
|
|
break;
|
|
|
|
|
Intersects(entity, entity2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Systems::CollisionSystem::Intersects(EntityID aEntity, EntityID bEntity)
|
|
|
|
|
void Systems::CollisionSystem::Intersects(EntityID aEntity, EntityID bEntity)
|
|
|
|
|
{
|
|
|
|
|
auto aTransform = m_World->GetComponent<Components::Transform>(aEntity, "Transform");
|
|
|
|
|
if(aTransform == nullptr)
|
|
|
|
|
return false;
|
|
|
|
|
return;
|
|
|
|
|
auto bTransform = m_World->GetComponent<Components::Transform>(bEntity, "Transform");
|
|
|
|
|
if(bTransform == nullptr)
|
|
|
|
|
return false;
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
auto aCollisionComponent = m_World->GetComponent<Components::Collision>(aEntity, "Collision");
|
|
|
|
|
if(aCollisionComponent == nullptr)
|
|
|
|
|
return false;
|
|
|
|
|
return;
|
|
|
|
|
auto bCollisionComponent = m_World->GetComponent<Components::Collision>(bEntity, "Collision");
|
|
|
|
|
if(bCollisionComponent == nullptr)
|
|
|
|
|
return false;
|
|
|
|
|
aCollisionComponent->CollidingEntities.clear();
|
|
|
|
|
bCollisionComponent->CollidingEntities.clear();
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto aBounds = m_World->GetComponent<Components::Bounds>(aEntity, "Bounds");
|
|
|
|
|
|
|
|
|
|
auto bBounds = m_World->GetComponent<Components::Bounds>(bEntity, "Bounds");
|
|
|
|
|
|
|
|
|
|
glm::vec3 aMax = aTransform->Position + aBounds->Origin + aBounds->VolumeVector;
|
|
|
|
|
glm::vec3 aMin = aTransform->Position + aBounds->Origin - aBounds->VolumeVector;
|
|
|
|
|
glm::vec3 bMax = bTransform->Position + bBounds->Origin + bBounds->VolumeVector;
|
|
|
|
|
glm::vec3 bMin = bTransform->Position + bBounds->Origin - bBounds->VolumeVector;
|
|
|
|
|
glm::vec3 aPos = aTransform->Position + (aBounds->Origin * aTransform->Scale);
|
|
|
|
|
glm::vec3 bPos = bTransform->Position + (bBounds->Origin * bTransform->Scale);
|
|
|
|
|
|
|
|
|
|
glm::vec3 aMax = aPos + aBounds->VolumeVector * aTransform->Scale;
|
|
|
|
|
glm::vec3 aMin = aPos - aBounds->VolumeVector * aTransform->Scale;
|
|
|
|
|
glm::vec3 bMax = bPos + bBounds->VolumeVector * bTransform->Scale;
|
|
|
|
|
glm::vec3 bMin = bPos - bBounds->VolumeVector * bTransform->Scale;
|
|
|
|
|
|
|
|
|
|
if (aMin.x <= bMax.x && bMin.x <= aMax.x) {
|
|
|
|
|
if (aMin.y <= bMax.y && bMin.y <= aMax.y) {
|
|
|
|
|
if (aMin.z <= bMax.z && bMin.z <= aMax.z) {
|
|
|
|
|
aCollisionComponent->CollidingEntities.push_back(aEntity);
|
|
|
|
|
bCollisionComponent->CollidingEntities.push_back(bEntity);
|
|
|
|
|
return true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Systems::CollisionSystem::CreateBoundingBox(std::shared_ptr<Components::Bounds> bounds)
|
|
|
|
|