Renamed IF_DEBUG_IS to DEBUG_IF, slightly different behavior and added some safety checking for auto creating AABBs from models.

This commit is contained in:
William Moberg
2015-12-17 17:08:47 +01:00
parent 46ae2d39af
commit 0f59b863ee
5 changed files with 146 additions and 26 deletions
+7 -2
View File
@@ -213,8 +213,11 @@ bool IsSameBoxProbably(const AABB& first, const AABB& second, const float epsilo
(std::abs(mi1.y - mi2.y) < epsilon);
}
void attachAABBComponentFromModel(World* world, EntityID id)
bool attachAABBComponentFromModel(World* world, EntityID id)
{
if (!world->HasComponent(id, "Model")) {
return false;
}
ComponentWrapper model = world->GetComponent(id, "Model");
ComponentWrapper collision = world->AttachComponent(id, "AABB");
Model* modelRes = ResourceManager::Load<Model>(model["Resource"]);
@@ -234,6 +237,7 @@ void attachAABBComponentFromModel(World* world, EntityID id)
}
collision["BoxCenter"] = 0.5f * (maxi + mini);
collision["BoxSize"] = maxi - mini;
return true;
}
bool GetEntityBox(World* world, ComponentWrapper& AABBComponent, AABB& outBox)
@@ -258,7 +262,8 @@ bool GetEntityBox(World* world, EntityID entity, AABB& outBox, bool forceBoxFrom
{
if (!world->HasComponent(entity, "AABB")) {
if (forceBoxFromModel) {
attachAABBComponentFromModel(world, entity);
if (!attachAABBComponentFromModel(world, entity))
return false;
} else {
return false;
}