From 67907b1ca98a4355a8f9708b994be9ed7ca38ab1 Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Sun, 1 Jan 2023 02:48:02 +0800 Subject: [PATCH] Replaced twin-edge dependency on sphere vs convex polyhedron --- Assets/Scenes/PhysicsSandbox.shade | 2 +- .../Narrowphase/SHSphereVsConvex.cpp | 22 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Assets/Scenes/PhysicsSandbox.shade b/Assets/Scenes/PhysicsSandbox.shade index 632dd485..266447e3 100644 --- a/Assets/Scenes/PhysicsSandbox.shade +++ b/Assets/Scenes/PhysicsSandbox.shade @@ -66,7 +66,7 @@ NumberOfChildren: 0 Components: Transform Component: - Translate: {x: -2.01111817, y: 7, z: 0.695722342} + Translate: {x: -0.903104782, y: 7, z: -0.782080948} Rotate: {x: -0, y: 0, z: -0} Scale: {x: 1, y: 1, z: 1} IsActive: true diff --git a/SHADE_Engine/src/Physics/Collision/Narrowphase/SHSphereVsConvex.cpp b/SHADE_Engine/src/Physics/Collision/Narrowphase/SHSphereVsConvex.cpp index 568d33a3..4523fc5b 100644 --- a/SHADE_Engine/src/Physics/Collision/Narrowphase/SHSphereVsConvex.cpp +++ b/SHADE_Engine/src/Physics/Collision/Narrowphase/SHSphereVsConvex.cpp @@ -130,12 +130,12 @@ namespace SHADE const SHVec3 CP = P1 + projection * tangent; // Check 2nd condition - // Get adjacent normal from twin half edge - const int32_t EDGE_INDEX = FACE.vertexIndices[CLOSEST_POINT].edgeIndex; - const int32_t TWIN_EDGE = HALF_EDGE_STRUCTURE->GetHalfEdge(EDGE_INDEX).twinEdgeIndex; + // Get adjacent normal from the cross product (tangent x normal) + //const int32_t EDGE_INDEX = FACE.vertexIndices[CLOSEST_POINT].edgeIndex; + //const int32_t TWIN_EDGE = HALF_EDGE_STRUCTURE->GetHalfEdge(EDGE_INDEX).twinEdgeIndex; - const int32_t ADJ_FACE = HALF_EDGE_STRUCTURE->GetHalfEdge(TWIN_EDGE).faceIndex; - const SHVec3& ADJ_NORMAL = POLYHEDRON.GetNormal(ADJ_FACE); + //const int32_t ADJ_FACE = HALF_EDGE_STRUCTURE->GetHalfEdge(TWIN_EDGE).faceIndex; + const SHVec3 ADJ_NORMAL = SHVec3::Cross(tangent, FACE_NORMAL); projection = SHVec3::Dot(P1_TO_CENTER, ADJ_NORMAL); if (projection >= 0.0f) @@ -172,12 +172,14 @@ namespace SHADE const SHVec3 CP = P1 + projection * tangent; // Check 2nd condition - // Get adjacent normal from twin half edge - const int32_t EDGE_INDEX = FACE.vertexIndices[P3_INDEX].edgeIndex; - const int32_t TWIN_EDGE = HALF_EDGE_STRUCTURE->GetHalfEdge(EDGE_INDEX).twinEdgeIndex; + // Get adjacent normal from the cross product (normal x tangent) + //const int32_t EDGE_INDEX = FACE.vertexIndices[P3_INDEX].edgeIndex; + //const int32_t TWIN_EDGE = HALF_EDGE_STRUCTURE->GetHalfEdge(EDGE_INDEX).twinEdgeIndex; + + //const int32_t ADJ_FACE = HALF_EDGE_STRUCTURE->GetHalfEdge(TWIN_EDGE).faceIndex; + //const SHVec3& ADJ_NORMAL = POLYHEDRON.GetNormal(ADJ_FACE); + const SHVec3 ADJ_NORMAL = SHVec3::Cross(FACE_NORMAL, tangent); - const int32_t ADJ_FACE = HALF_EDGE_STRUCTURE->GetHalfEdge(TWIN_EDGE).faceIndex; - const SHVec3& ADJ_NORMAL = POLYHEDRON.GetNormal(ADJ_FACE); projection = SHVec3::Dot(P1_TO_CENTER, ADJ_NORMAL); if (projection >= 0.0f)