Simple quickly made CollisionSystem.

This commit is contained in:
William Moberg
2015-12-16 12:23:08 +01:00
parent d10df6ae09
commit cf0ff9bfe5
2 changed files with 11 additions and 16 deletions
+8 -13
View File
@@ -2,16 +2,13 @@
#include "Collision/CollisionSystem.h"
#include "Core/AABB.h"
void CollisionSystem::Update(World * world, ComponentWrapper & cAABB, double dt)
void CollisionSystem::UpdateComponent(World * world, ComponentWrapper & cAABB, double dt)
{
//cAABB is any entity that should be collideable.
m_EventBroker->Process<CollisionSystem>();
//Currently the box is translated according to the models Transform matrix,
//but not scaled (or rotated since it's AABB). This should be fine, if we don't
//want to shrink or scale up an collideable object after creation.
cAABB["BoxCenter"] = (glm::vec3)world->GetComponent(cAABB.EntityID, "Transform")["Position"];
AABB thisBox;
thisBox.CreateFromCenter(cAABB["BoxCenter"], cAABB["BoxSize"]);
if (!Collision::GetEntityBox(world, cAABB, thisBox)) {
return;
}
//Here c should be an object that moves, currently only players.
if (zPress) {
return;
@@ -21,8 +18,9 @@ void CollisionSystem::Update(World * world, ComponentWrapper & cAABB, double dt)
continue;
}
AABB otherBox;
ComponentWrapper& aabbComp = world->GetComponent(mover.EntityID, "AABB");
otherBox.CreateFromCenter(aabbComp["BoxCenter"], aabbComp["BoxSize"]);
if (!Collision::GetEntityBox(world, mover.EntityID, otherBox)) {
continue;
}
if (Collision::AABBVsAABB(thisBox, otherBox)) {
ComponentWrapper& trans = world->GetComponent(mover.EntityID, "Transform");
//TODO: Move entity to correct position on collision instead of this. Special treatment if both are movers.
@@ -30,7 +28,6 @@ void CollisionSystem::Update(World * world, ComponentWrapper & cAABB, double dt)
float moveSpeed = 0.12f;
newPos += moveSpeed * glm::normalize(newPos - thisBox.Center());
trans["Position"] = newPos;
aabbComp["BoxCenter"] = newPos;
}
}
}
@@ -38,9 +35,7 @@ void CollisionSystem::Update(World * world, ComponentWrapper & cAABB, double dt)
bool CollisionSystem::OnKeyUp(const Events::KeyUp & event)
{
if (event.KeyCode == GLFW_KEY_Z) {
zPress = true;
} else if (event.KeyCode == GLFW_KEY_X) {
zPress = false;
zPress = !zPress;
}
return false;
}