Can resolve collision when AABB corners cut through triangle.
At least two more cases left to resolve.
This commit is contained in:
@@ -299,7 +299,7 @@ bool AABBvsTriangle(const AABB& box, const glm::vec3& v0, const glm::vec3& v1, c
|
||||
//closest to being perpendicular to the plane of the polygon.
|
||||
|
||||
triNormal = glm::normalize(triNormal);
|
||||
glm::vec3 diagonal = signNonZero(triNormal) * half;
|
||||
glm::vec3 diagonal = -signNonZero(triNormal) * half;
|
||||
#define EARLY_OUT_OR_MAYBE_JUST_EXTRA_WORK
|
||||
#ifdef EARLY_OUT_OR_MAYBE_JUST_EXTRA_WORK
|
||||
//The triangle plane contains all points P in dot(triNormal, P) == dot(triNormal, v0)
|
||||
@@ -323,9 +323,9 @@ bool AABBvsTriangle(const AABB& box, const glm::vec3& v0, const glm::vec3& v1, c
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
float dist = glm::dot(triNormal, origin + diagonal - v0);
|
||||
outResolutionVector = dist * triNormal;
|
||||
LOG_DEBUG("Triangle collision corner");
|
||||
//Distance between triangle plane, and the diagonal corner, multiplied by the normal.
|
||||
//Signed distance, positive if on the same side as the normal.
|
||||
outResolutionVector = -glm::dot(triNormal, origin + diagonal - v0) * triNormal;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -51,7 +51,13 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
||||
auto absScale = Transform::AbsoluteScale(m_World, cModel.EntityID);
|
||||
glm::mat4 modelMatrix = glm::translate(absPosition) * glm::toMat4(absOrientation) * glm::scale(absScale);
|
||||
|
||||
RawModel* model = ResourceManager::Load<RawModel>(cModel["Resource"]);
|
||||
RawModel* model;
|
||||
try {
|
||||
model = ResourceManager::Load<RawModel, true>(cModel["Resource"]);
|
||||
} catch (const std::exception&) {
|
||||
continue;
|
||||
}
|
||||
|
||||
glm::vec3 resolutionVector;
|
||||
if (Collision::AABBvsTriangles(boxA, model->m_Vertices, model->m_Indices, modelMatrix, resolutionVector)) {
|
||||
(glm::vec3&)cTransform["Position"] += resolutionVector;
|
||||
|
||||
Reference in New Issue
Block a user