adding on collided callback

This commit is contained in:
Bluub
2021-06-01 14:43:48 +02:00
parent ef492f3b57
commit b3dd001532
5 changed files with 62 additions and 24 deletions
+8 -6
View File
@@ -20,7 +20,7 @@ namespace BBM
auto &col = entity.getComponent<CollisionComponent>();
Vector3f position = posA.position;
if (entity.hasComponent(typeid(MovableComponent)))
position += entity.getComponent<MovableComponent>()._velocity;
position += entity.getComponent<MovableComponent>().getVelocity();
Vector3f minA = Vector3f::min(position, position + col.bound);
Vector3f maxA = Vector3f::max(position, position + col.bound);
for (auto &other : _wal.scene->getEntities()) {
@@ -29,14 +29,16 @@ namespace BBM
if (!other.hasComponent(typeid(CollisionComponent)) ||
!other.hasComponent(typeid(PositionComponent)))
continue;
auto colB = entity.getComponent<CollisionComponent>().bound;
auto colB = entity.getComponent<CollisionComponent>();
auto posB = other.getComponent<PositionComponent>().position;
Vector3f minB = Vector3f::min(posB, posB + colB);
Vector3f maxB = Vector3f::max(posB, posB + colB);
Vector3f minB = Vector3f::min(posB, posB + colB.bound);
Vector3f maxB = Vector3f::max(posB, posB + colB.bound);
if ((minA.x <= maxB.x && maxA.x >= minB.x) &&
(minA.y <= maxB.y && maxA.y >= minB.y) &&
(minA.z <= maxB.z && maxA.z >= minB.z))
col.onCollide(entity, other);
(minA.z <= maxB.z && maxA.z >= minB.z)) {
col.getOnCollide()(entity, other);
colB.getOnCollided()(entity, other);
}
}
}
}