diff --git a/resources/Schema/Components/AABB.xsd b/resources/Schema/Components/AABB.xsd
index daa633a6..7dec510f 100644
--- a/resources/Schema/Components/AABB.xsd
+++ b/resources/Schema/Components/AABB.xsd
@@ -7,10 +7,10 @@
- Middle point of the bounding box
+ Middle point of the bounding box, in model space
- Size of the bounding box
+ Size of the bounding box, in model space
diff --git a/resources/Schema/Entities/GameMap.xml b/resources/Schema/Entities/GameMap.xml
index e206d31f..4d0a2716 100644
--- a/resources/Schema/Entities/GameMap.xml
+++ b/resources/Schema/Entities/GameMap.xml
@@ -8,6 +8,9 @@
+
+
+
Models\MapVersion1.mesh
diff --git a/src/Engine/Collision/CollisionSystem.cpp b/src/Engine/Collision/CollisionSystem.cpp
index 382238e7..846d38a7 100644
--- a/src/Engine/Collision/CollisionSystem.cpp
+++ b/src/Engine/Collision/CollisionSystem.cpp
@@ -1,6 +1,7 @@
#include "Collision/Collision.h"
#include "Collision/CollisionSystem.h"
#include "Core/AABB.h"
+#include "Rendering/Model.h"
void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt)
{
@@ -25,33 +26,28 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
continue;
}
- if (Collision::AABBVsAABB(boxA, boxB, resolutionVector)) {
+ if (boxB.Entity.HasComponent("Model") && Collision::AABBVsAABB(boxA, boxB)) {
+ //Here we know boxB is a entity with Collideable, AABB, and Model.
+ RawModel* model;
+ try {
+ model = ResourceManager::Load(boxB.Entity["Model"]["Resource"]);
+ } catch (const std::exception&) {
+ continue;
+ }
+
+ glm::mat4 modelMatrix = Transform::ModelMatrix(boxB.Entity);
+
+ glm::vec3 newVelocity = (glm::vec3)cPhysics["Velocity"];
+ if (Collision::AABBvsTriangles(boxA, model->m_Vertices, model->m_Indices, modelMatrix, newVelocity, resolutionVector)) {
+ (glm::vec3&)cTransform["Position"] += resolutionVector;
+ cPhysics["Velocity"] = newVelocity;
+ }
+ } else if (Collision::AABBVsAABB(boxA, boxB, resolutionVector)) {
+ //Enter here if boxB has no Model.
(glm::vec3&)cTransform["Position"] += resolutionVector;
if (resolutionVector.y > 0) {
((glm::vec3&)cPhysics["Velocity"]).y = 0.f;
}
}
}
-
- // HACK: Temporarily collide against all collidable models since they're not in the octree yet
- //auto otherCollidables = world->GetComponents("Model");
- //for (auto& cModel : *otherCollidables) {
- // if (cModel.EntityID == entity) {
- // continue;
- // }
- // if (!world->HasComponent(cModel.EntityID, "Collidable")) {
- // continue;
- // }
-
- // auto absPosition = RenderQueueFactory::AbsolutePosition(world, cModel.EntityID);
- // auto absOrientation = RenderQueueFactory::AbsoluteOrientation(world, cModel.EntityID);
- // auto absScale = RenderQueueFactory::AbsoluteScale(world, cModel.EntityID);
- // glm::mat4 modelMatrix = glm::translate(absPosition); // *glm::toMat4(absOrientation) * glm::scale(absScale);
-
- // auto model = ResourceManager::Load(cModel["Resource"]);
- // glm::vec3 resolutionVector;
- // if (Collision::AABBvsTriangles(boxA, model->m_Vertices, model->m_Indices, modelMatrix, resolutionVector)) {
- // (glm::vec3&)cTransform["Position"] += resolutionVector;
- // }
- //}
-}
\ No newline at end of file
+}