Implemented a custom physics engine #316

Merged
direnbharwani merged 95 commits from SHPhysics into main 2023-01-23 15:55:45 +08:00
2 changed files with 13 additions and 11 deletions
Showing only changes of commit 67907b1ca9 - Show all commits

View File

@ -66,7 +66,7 @@
NumberOfChildren: 0 NumberOfChildren: 0
Components: Components:
Transform Component: 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} Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1} Scale: {x: 1, y: 1, z: 1}
IsActive: true IsActive: true

View File

@ -130,12 +130,12 @@ namespace SHADE
const SHVec3 CP = P1 + projection * tangent; const SHVec3 CP = P1 + projection * tangent;
// Check 2nd condition // Check 2nd condition
// Get adjacent normal from twin half edge // Get adjacent normal from the cross product (tangent x normal)
const int32_t EDGE_INDEX = FACE.vertexIndices[CLOSEST_POINT].edgeIndex; //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 TWIN_EDGE = HALF_EDGE_STRUCTURE->GetHalfEdge(EDGE_INDEX).twinEdgeIndex;
const int32_t ADJ_FACE = HALF_EDGE_STRUCTURE->GetHalfEdge(TWIN_EDGE).faceIndex; //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(tangent, FACE_NORMAL);
projection = SHVec3::Dot(P1_TO_CENTER, ADJ_NORMAL); projection = SHVec3::Dot(P1_TO_CENTER, ADJ_NORMAL);
if (projection >= 0.0f) if (projection >= 0.0f)
@ -172,12 +172,14 @@ namespace SHADE
const SHVec3 CP = P1 + projection * tangent; const SHVec3 CP = P1 + projection * tangent;
// Check 2nd condition // Check 2nd condition
// Get adjacent normal from twin half edge // Get adjacent normal from the cross product (normal x tangent)
const int32_t EDGE_INDEX = FACE.vertexIndices[P3_INDEX].edgeIndex; //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 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); projection = SHVec3::Dot(P1_TO_CENTER, ADJ_NORMAL);
if (projection >= 0.0f) if (projection >= 0.0f)