diff --git a/include/Engine/Core/Ray.h b/include/Engine/Core/Ray.h
index 2ed192a2..0fcef01e 100644
--- a/include/Engine/Core/Ray.h
+++ b/include/Engine/Core/Ray.h
@@ -11,7 +11,7 @@ public:
: m_Origin(origin)
, m_Direction(glm::normalize(dir))
{
- IF_DEBUG_IS(true) {
+ DEBUG_IF(true) {
if (glm::any(glm::isnan(m_Direction))) {
LOG_WARNING("Ray Direction was set to the zero-vector, expect unknown side effects and/or crashes.");
}
diff --git a/include/Engine/Core/Util/IfDebug.h b/include/Engine/Core/Util/IfDebug.h
index 159162c5..79cb3a4c 100644
--- a/include/Engine/Core/Util/IfDebug.h
+++ b/include/Engine/Core/Util/IfDebug.h
@@ -1,17 +1,12 @@
-//Example:
-//IF_DEBUG_IS(true) {
-// //Stuff done only in debug mode.
-//}
-//
-//IF_DEBUG_IS(false) {
-// //Stuff done only in release mode.
-//} else {
-// //Stuff only in debug.
-//}
-#ifndef IF_DEBUG_IS
+// Example:
+// DEBUG_IF(condition) {
+// // This code is executed only in debug mode and if condition is true.
+// }
+// NOTE: condition statement is not executed at all in release mode.
+#ifndef DEBUG_IF
#ifndef DEBUG
-#define IF_DEBUG_IS(c) if(c)
+#define DEBUG_IF(c) if(c)
#else
-#define IF_DEBUG_IS(c) if(!c)
+#define DEBUG_IF(c) if(false)
#endif
#endif
\ No newline at end of file
diff --git a/resources/Schema/Entities/CollisionTestLevel.xml b/resources/Schema/Entities/CollisionTestLevel.xml
new file mode 100644
index 00000000..99842b88
--- /dev/null
+++ b/resources/Schema/Entities/CollisionTestLevel.xml
@@ -0,0 +1,122 @@
+
+
+
+
+
+
+
+
+ Models/DummyScene.obj
+
+
+
+
+
+
+
+
+
+
+ Models/ScaleWidget.obj
+
+
+
+
+
+
+
+
+
+
+ Models/RotationWidgetX.obj
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Models/Core/UnitCube.obj
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Models/Core/UnitRaptor.obj
+
+
+
+
+
+
+
+
+
+
+
+ 20
+
+
+
+
+
+
+
+
+
+
+
+
+ Models/Core/UnitCube.obj
+
+
+
+
+
+
+
+
+
+
+
+
+ Models/Core/UnitCube.obj
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Engine/Collision/Collision.cpp b/src/Engine/Collision/Collision.cpp
index ec6c471c..dd2adec8 100644
--- a/src/Engine/Collision/Collision.cpp
+++ b/src/Engine/Collision/Collision.cpp
@@ -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["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;
}
diff --git a/src/Engine/Core/AABB.cpp b/src/Engine/Core/AABB.cpp
index b1da6b26..0df56229 100644
--- a/src/Engine/Core/AABB.cpp
+++ b/src/Engine/Core/AABB.cpp
@@ -7,16 +7,14 @@ AABB::AABB(const glm::vec3& minPos, const glm::vec3& maxPos)
, m_Center(0.5f * (maxPos + minPos))
, m_HalfSize(0.5f * (maxPos - minPos))
{
- IF_DEBUG_IS(true) {
- if (glm::any(glm::lessThan(m_MaxCorner, m_MinCorner))) {
- LOG_WARNING("AABB maxCorner coordinates are not greater than minCorner");
- m_MaxCorner.x = glm::max(m_MaxCorner.x, m_MinCorner.x);
- m_MinCorner.x = glm::min(m_MaxCorner.x, m_MinCorner.x);
- m_MaxCorner.y = glm::max(m_MaxCorner.y, m_MinCorner.y);
- m_MinCorner.y = glm::min(m_MaxCorner.y, m_MinCorner.y);
- m_MaxCorner.z = glm::max(m_MaxCorner.z, m_MinCorner.z);
- m_MinCorner.z = glm::min(m_MaxCorner.z, m_MinCorner.z);
- }
+ DEBUG_IF(glm::any(glm::lessThan(m_MaxCorner, m_MinCorner))) {
+ LOG_WARNING("AABB maxCorner coordinates are not greater than minCorner");
+ m_MaxCorner.x = glm::max(m_MaxCorner.x, m_MinCorner.x);
+ m_MinCorner.x = glm::min(m_MaxCorner.x, m_MinCorner.x);
+ m_MaxCorner.y = glm::max(m_MaxCorner.y, m_MinCorner.y);
+ m_MinCorner.y = glm::min(m_MaxCorner.y, m_MinCorner.y);
+ m_MaxCorner.z = glm::max(m_MaxCorner.z, m_MinCorner.z);
+ m_MinCorner.z = glm::min(m_MaxCorner.z, m_MinCorner.z);
}
}