From f4b7618fc2d7fa61d2fa52d3e89ac603ccf9978e Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Thu, 2 Mar 2023 05:23:08 +0800 Subject: [PATCH] Fixed incorrect edge preference for convex vs convex --- Assets/Editor/Editor.SHConfig | 2 +- Assets/Scenes/PhysicsSandbox.shade | 118 +++++++++++++++++- Assets/Scenes/SS_Playground.shade | 14 ++- .../Narrowphase/SHConvexVsConvex.cpp | 9 +- .../src/Physics/Dynamics/SHContactSolver.cpp | 2 + 5 files changed, 131 insertions(+), 14 deletions(-) diff --git a/Assets/Editor/Editor.SHConfig b/Assets/Editor/Editor.SHConfig index 9f915147..65fe522e 100644 --- a/Assets/Editor/Editor.SHConfig +++ b/Assets/Editor/Editor.SHConfig @@ -1,4 +1,4 @@ Start Maximized: true Working Scene ID: 92914350 -Window Size: {x: 1920, y: 1080} +Window Size: {x: 2000, y: 1518} Style: 0 \ No newline at end of file diff --git a/Assets/Scenes/PhysicsSandbox.shade b/Assets/Scenes/PhysicsSandbox.shade index f984c3df..584a1667 100644 --- a/Assets/Scenes/PhysicsSandbox.shade +++ b/Assets/Scenes/PhysicsSandbox.shade @@ -28,9 +28,9 @@ NumberOfChildren: 0 Components: Camera Component: - Position: {x: 5, y: 5, z: 0} + Position: {x: 0, y: 0, z: 7} Pitch: 0 - Yaw: 90 + Yaw: 0 Roll: 0 Width: 1920 Height: 1080 @@ -45,7 +45,7 @@ NumberOfChildren: 0 Components: Transform Component: - Translate: {x: 0, y: 7.5, z: 0.75} + Translate: {x: 0, y: 7.5, z: 0} Rotate: {x: -0, y: 0, z: 0.785398185} Scale: {x: 1, y: 1, z: 1} IsActive: true @@ -55,7 +55,7 @@ Mass: 0.52359879 Drag: 0.00999999978 Angular Drag: 0 - Use Gravity: true + Use Gravity: false Gravity Scale: 1 Interpolate: true Sleeping Enabled: true @@ -175,4 +175,114 @@ Position Offset: {x: 0, y: 0, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} IsActive: true + Scripts: ~ +- EID: 7 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 0, y: 0, z: 3} + Rotate: {x: 0, y: 0, z: 0} + Scale: {x: 1, y: 1, z: 1} + IsActive: true + Collider Component: + DrawColliders: false + Colliders: + - Is Trigger: false + Collision Tag: 1 + Type: Box + Half Extents: {x: 1, y: 1, z: 1} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0, z: 0} + Rotation Offset: {x: 0, y: 0, z: 0} + IsActive: true + Scripts: ~ +- EID: 8 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: -1, y: 7, z: 0} + Rotate: {x: 0, y: 0, z: 0.785398185} + Scale: {x: 0.999999642, y: 0.999998569, z: 0.999999642} + IsActive: true + RigidBody Component: + Type: Dynamic + Auto Mass: false + Mass: 1 + Drag: 0.00999999978 + Angular Drag: 0.00999999978 + Use Gravity: true + Gravity Scale: 1 + Interpolate: true + Sleeping Enabled: true + Freeze Position X: false + Freeze Position Y: false + Freeze Position Z: false + Freeze Rotation X: false + Freeze Rotation Y: false + Freeze Rotation Z: false + IsActive: true + Collider Component: + DrawColliders: false + Colliders: + - Is Trigger: false + Collision Tag: 1 + Type: Box + Half Extents: {x: 1, y: 1, z: 1} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0, z: 0} + Rotation Offset: {x: 0, y: 0, z: 0} + IsActive: true + Scripts: + - Type: PhysicsTestObj + Enabled: true + forceAmount: 250 + torqueAmount: 5 +- EID: 65545 + Name: Default + IsActive: true + NumberOfChildren: 0 + Components: + Transform Component: + Translate: {x: 2, y: 5, z: 3} + Rotate: {x: 0, y: 0, z: 0.785398185} + Scale: {x: 0.999999642, y: 0.999998569, z: 0.999999642} + IsActive: true + RigidBody Component: + Type: Dynamic + Auto Mass: false + Mass: 1 + Drag: 0.00999999978 + Angular Drag: 0.00999999978 + Use Gravity: true + Gravity Scale: 1 + Interpolate: true + Sleeping Enabled: true + Freeze Position X: false + Freeze Position Y: false + Freeze Position Z: false + Freeze Rotation X: false + Freeze Rotation Y: false + Freeze Rotation Z: false + IsActive: true + Collider Component: + DrawColliders: false + Colliders: + - Is Trigger: false + Collision Tag: 1 + Type: Box + Half Extents: {x: 1, y: 1, z: 1} + Friction: 0.400000006 + Bounciness: 0 + Density: 1 + Position Offset: {x: 0, y: 0, z: 0} + Rotation Offset: {x: 0, y: 0, z: 0} + IsActive: true Scripts: ~ \ No newline at end of file diff --git a/Assets/Scenes/SS_Playground.shade b/Assets/Scenes/SS_Playground.shade index 4f3ba0c8..55d60e73 100644 --- a/Assets/Scenes/SS_Playground.shade +++ b/Assets/Scenes/SS_Playground.shade @@ -4,7 +4,7 @@ NumberOfChildren: 0 Components: Camera Component: - Position: {x: 0, y: 1, z: 3} + Position: {x: 0, y: 1, z: 5} Pitch: 0 Yaw: 0 Roll: 0 @@ -22,8 +22,8 @@ Components: Transform Component: Translate: {x: 0, y: 0, z: 0} - Rotate: {x: 0, y: 0, z: 0} - Scale: {x: 1, y: 1, z: 1} + Rotate: {x: -0, y: 0, z: -0} + Scale: {x: 5, y: 0.999998808, z: 5} IsActive: true Collider Component: DrawColliders: false @@ -45,7 +45,7 @@ NumberOfChildren: 0 Components: Transform Component: - Translate: {x: 0, y: 2, z: 0} + Translate: {x: 1.5, y: 2, z: 1.5} Rotate: {x: 0, y: 0.785398185, z: 0} Scale: {x: 1, y: 1, z: 1} IsActive: true @@ -79,4 +79,8 @@ Position Offset: {x: 0, y: 0, z: 0} Rotation Offset: {x: 0, y: 0, z: 0} IsActive: true - Scripts: ~ \ No newline at end of file + Scripts: + - Type: PhysicsTestObj + Enabled: true + forceAmount: 50 + torqueAmount: 500 \ No newline at end of file diff --git a/SHADE_Engine/src/Physics/Collision/Narrowphase/SHConvexVsConvex.cpp b/SHADE_Engine/src/Physics/Collision/Narrowphase/SHConvexVsConvex.cpp index 09b5284d..a2c7f9f8 100644 --- a/SHADE_Engine/src/Physics/Collision/Narrowphase/SHConvexVsConvex.cpp +++ b/SHADE_Engine/src/Physics/Collision/Narrowphase/SHConvexVsConvex.cpp @@ -153,6 +153,7 @@ namespace SHADE cachedInfo.info.refFace = minFaceQuery.closestFace; } + minFaceQuery.bestDistance = std::max(FACE_QUERY_A.bestDistance, FACE_QUERY_B.bestDistance); // If an edge pair contains the closest distance,vwe ignore any face queries and find the closest points on // each edge and use that as the contact point. @@ -516,10 +517,10 @@ namespace SHADE SHContact contact; contact.penetration = -DIST; - // A: Incident, B: Reference - // Project the clipped point onto the reference place for localPointB - contact.localPointA = INV_TF_INC * (TF_REF * POS); - contact.localPointB = POS + LOCAL_REF_NORMAL * SHVec3::Dot(LOCAL_REF_NORMAL, POS - LOCAL_REF_POINT); + // A: Reference, B: Incident + // Project the clipped point onto the reference place for localPointA + contact.localPointA = POS + LOCAL_REF_NORMAL * SHVec3::Dot(LOCAL_REF_NORMAL, POS - LOCAL_REF_POINT); + contact.localPointB = INV_TF_INC * (TF_REF * POS); if (flip) { diff --git a/SHADE_Engine/src/Physics/Dynamics/SHContactSolver.cpp b/SHADE_Engine/src/Physics/Dynamics/SHContactSolver.cpp index 60ffd8a2..2b690f05 100644 --- a/SHADE_Engine/src/Physics/Dynamics/SHContactSolver.cpp +++ b/SHADE_Engine/src/Physics/Dynamics/SHContactSolver.cpp @@ -247,6 +247,8 @@ namespace SHADE void SHContactSolver::solve() noexcept { + static const float TEMP_INF = std::numeric_limits::infinity(); + for (auto& [key, constraint] : contactConstraints) { SHVelocityState& velocityStateA = velocityStates.find(key.GetEntityA())->second;