Merge branch 'SP3-2-Physics' into PlayerControllerWIthNewPhysics
This commit is contained in:
commit
799cac0924
|
@ -150,8 +150,8 @@
|
|||
IsActive: true
|
||||
RigidBody Component:
|
||||
Type: Dynamic
|
||||
Auto Mass: false
|
||||
Mass: 1
|
||||
Auto Mass: false
|
||||
Drag: 0.00999999978
|
||||
Angular Drag: 0.00999999978
|
||||
Use Gravity: true
|
||||
|
@ -190,8 +190,8 @@
|
|||
IsActive: true
|
||||
RigidBody Component:
|
||||
Type: Dynamic
|
||||
Auto Mass: false
|
||||
Mass: 1
|
||||
Auto Mass: false
|
||||
Drag: 0.00999999978
|
||||
Angular Drag: 0.00999999978
|
||||
Use Gravity: true
|
||||
|
@ -230,8 +230,8 @@
|
|||
IsActive: true
|
||||
RigidBody Component:
|
||||
Type: Dynamic
|
||||
Auto Mass: false
|
||||
Mass: 1
|
||||
Auto Mass: false
|
||||
Drag: 0.00999999978
|
||||
Angular Drag: 0.00999999978
|
||||
Use Gravity: true
|
||||
|
@ -270,8 +270,8 @@
|
|||
IsActive: true
|
||||
RigidBody Component:
|
||||
Type: Dynamic
|
||||
Auto Mass: false
|
||||
Mass: 1
|
||||
Auto Mass: false
|
||||
Drag: 0.00999999978
|
||||
Angular Drag: 0.00999999978
|
||||
Use Gravity: true
|
||||
|
@ -290,7 +290,7 @@
|
|||
- Is Trigger: false
|
||||
Collision Tag: 0
|
||||
Type: Box
|
||||
Half Extents: {x: 1, y: 1, z: 1}
|
||||
Half Extents: {x: 1, y: 2, z: 1}
|
||||
Friction: 0.400000006
|
||||
Bounciness: 0
|
||||
Density: 1
|
||||
|
|
|
@ -105,6 +105,12 @@ namespace SHADE
|
|||
template <IsFloatingPoint T = float>
|
||||
[[nodiscard]] static bool CompareFloat (T lhs, T rhs, T absTolerance = EPSILON, T relTolerance = EPSILON);
|
||||
|
||||
template <IsArithmetic T>
|
||||
[[nodiscard]] static bool IsInfinity (T value);
|
||||
|
||||
template <IsArithmetic T>
|
||||
[[nodiscard]] static bool IsNaN (T value);
|
||||
|
||||
private:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Static Data Members */
|
||||
|
|
|
@ -126,4 +126,21 @@ namespace SHADE
|
|||
return std::fabs(lhs - rhs) <= Max(absTolerance, RTOL);
|
||||
}
|
||||
|
||||
template <IsArithmetic T>
|
||||
bool SHMath::IsInfinity(T value)
|
||||
{
|
||||
const float MAX_VALUE = std::numeric_limits<T>::max();
|
||||
const float MIN_VALUE = std::numeric_limits<T>::min();
|
||||
|
||||
return !(MIN_VALUE <= value && value <= MAX_VALUE);
|
||||
}
|
||||
|
||||
template <IsArithmetic T>
|
||||
bool SHMath::IsNaN(T value)
|
||||
{
|
||||
return value != value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace SHADE
|
|
@ -67,8 +67,8 @@ namespace SHADE
|
|||
|
||||
bool SHCollision::ConvexVsConvex(SHManifold& manifold, const SHCollisionShape& A, const SHCollisionShape& B) noexcept
|
||||
{
|
||||
static constexpr float ABSOLUTE_TOLERANCE = 0.0005f;
|
||||
static constexpr float RELATIVE_TOLERANCE = 1.002f;
|
||||
static constexpr float ABSOLUTE_TOLERANCE = 0.01f;
|
||||
static constexpr float RELATIVE_TOLERANCE = 0.95f;
|
||||
|
||||
const SHConvexPolyhedron& POLY_A = reinterpret_cast<const SHConvexPolyhedron&>(A);
|
||||
const SHConvexPolyhedron& POLY_B = reinterpret_cast<const SHConvexPolyhedron&>(B);
|
||||
|
@ -130,7 +130,7 @@ namespace SHADE
|
|||
const SHConvexPolyhedron* incidentPoly = nullptr;
|
||||
|
||||
SHCollisionUtils::FaceQuery minFaceQuery;
|
||||
if (FACE_QUERY_A.bestDistance > FACE_QUERY_B.bestDistance * RELATIVE_TOLERANCE + ABSOLUTE_TOLERANCE)
|
||||
if (FACE_QUERY_A.bestDistance + ABSOLUTE_TOLERANCE > FACE_QUERY_B.bestDistance * RELATIVE_TOLERANCE)
|
||||
{
|
||||
minFaceQuery = FACE_QUERY_A;
|
||||
referencePoly = &POLY_A;
|
||||
|
@ -157,7 +157,7 @@ namespace SHADE
|
|||
|
||||
// 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.
|
||||
if (EDGE_QUERY.bestDistance * RELATIVE_TOLERANCE + ABSOLUTE_TOLERANCE > minFaceQuery.bestDistance + ABSOLUTE_TOLERANCE)
|
||||
if (EDGE_QUERY.bestDistance * RELATIVE_TOLERANCE > minFaceQuery.bestDistance + ABSOLUTE_TOLERANCE)
|
||||
{
|
||||
const SHHalfEdgeStructure::HalfEdge& HALF_EDGE_A = POLY_A.GetHalfEdge(EDGE_QUERY.halfEdgeA);
|
||||
const SHHalfEdgeStructure::HalfEdge& HALF_EDGE_B = POLY_B.GetHalfEdge(EDGE_QUERY.halfEdgeB);
|
||||
|
|
|
@ -326,6 +326,17 @@ namespace SHADE
|
|||
shape->Update();
|
||||
}
|
||||
|
||||
void SHCollider::UpdateBroadphase() noexcept
|
||||
{
|
||||
flags |= MOVED_FLAG;
|
||||
}
|
||||
|
||||
void SHCollider::UpdateBody() noexcept
|
||||
{
|
||||
if (rigidBody)
|
||||
rigidBody->ComputeMassData();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Private Member Function Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -149,6 +149,18 @@ namespace SHADE
|
|||
*/
|
||||
void Update () noexcept;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Updates the broadphase proxy of this collider.
|
||||
*/
|
||||
void UpdateBroadphase() noexcept;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Recomputes the mass of the body if one exists.
|
||||
*/
|
||||
void UpdateBody() noexcept;
|
||||
|
||||
protected:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
|
|
|
@ -207,9 +207,11 @@ namespace SHADE
|
|||
// Recompute Relative radius
|
||||
relativeExtents = 2.0f * Extents / scale;
|
||||
|
||||
// Hack: Indicate that the collider needs to update the broadphase proxy
|
||||
if (collider)
|
||||
collider->SetScale(collider->GetScale());
|
||||
{
|
||||
collider->UpdateBroadphase();
|
||||
collider->UpdateBody();
|
||||
}
|
||||
}
|
||||
|
||||
void SHBox::SetRelativeExtents(const SHVec3& newRelativeExtents) noexcept
|
||||
|
@ -219,9 +221,11 @@ namespace SHADE
|
|||
// Recompute world radius
|
||||
Extents = relativeExtents * scale * 0.5f;
|
||||
|
||||
// Hack: Indicate that the collider needs to update the broadphase proxy
|
||||
if (collider)
|
||||
collider->SetScale(collider->GetScale());
|
||||
{
|
||||
collider->UpdateBroadphase();
|
||||
collider->UpdateBody();
|
||||
}
|
||||
}
|
||||
|
||||
void SHBox::SetScale(const SHVec3& newScale) noexcept
|
||||
|
@ -231,9 +235,11 @@ namespace SHADE
|
|||
// Recompute world radius
|
||||
Extents = relativeExtents * scale * 0.5f;
|
||||
|
||||
// Hack: Indicate that the collider needs to update the broadphase proxy
|
||||
if (collider)
|
||||
collider->SetScale(collider->GetScale());
|
||||
{
|
||||
collider->UpdateBroadphase();
|
||||
collider->UpdateBody();
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -168,9 +168,11 @@ namespace SHADE
|
|||
// Recompute Relative radius
|
||||
relativeRadius = 2.0f * Radius / scale;
|
||||
|
||||
// Hack: Indicate that the collider needs to update the broadphase proxy
|
||||
if (collider)
|
||||
collider->SetScale(collider->GetScale());
|
||||
{
|
||||
collider->UpdateBroadphase();
|
||||
collider->UpdateBody();
|
||||
}
|
||||
}
|
||||
|
||||
void SHSphere::SetRelativeRadius(float newRelativeRadius) noexcept
|
||||
|
@ -180,9 +182,11 @@ namespace SHADE
|
|||
// Recompute world radius
|
||||
Radius = relativeRadius * scale * 0.5f;
|
||||
|
||||
// Hack: Indicate that the collider needs to update the broadphase proxy
|
||||
if (collider)
|
||||
collider->SetScale(collider->GetScale());
|
||||
{
|
||||
collider->UpdateBroadphase();
|
||||
collider->UpdateBody();
|
||||
}
|
||||
}
|
||||
|
||||
void SHSphere::SetScale(float maxScale) noexcept
|
||||
|
@ -192,9 +196,11 @@ namespace SHADE
|
|||
// Recompute world radius
|
||||
Radius = relativeRadius * scale * 0.5f;
|
||||
|
||||
// Hack: Indicate that the collider needs to update the broadphase proxy
|
||||
if (collider)
|
||||
collider->SetScale(collider->GetScale());
|
||||
{
|
||||
collider->UpdateBroadphase();
|
||||
collider->UpdateBody();
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -18,14 +18,6 @@
|
|||
#include "Physics/SHPhysicsConstants.h"
|
||||
#include "Physics/Collision/Narrowphase/SHCollisionUtils.h"
|
||||
|
||||
bool IsInfinity(float value)
|
||||
{
|
||||
const float MAX_VAL = std::numeric_limits<float>::max();
|
||||
const float MIN_VAL = -MAX_VAL;
|
||||
|
||||
return !(MIN_VAL <= value && value <= MAX_VAL);
|
||||
}
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
@ -227,7 +219,7 @@ namespace SHADE
|
|||
errorBias = -SHPHYSICS_BAUMGARTE * INV_DT * std::max(0.0f, contact.penetration - SHPHYSICS_LINEAR_SLOP);
|
||||
|
||||
// TODO: This should never occur. Move this check into the ConvexVSConvex to find the error.
|
||||
if (IsInfinity(errorBias))
|
||||
if (SHMath::IsInfinity(errorBias))
|
||||
errorBias = 0.0f;
|
||||
|
||||
// Warm starting
|
||||
|
|
|
@ -40,8 +40,6 @@ namespace SHADE
|
|||
flags |= 1U << 0; // Body is active
|
||||
flags |= 1U << 2; // Sleeping is enabled
|
||||
flags |= 1U << 3; // Gravity is enabled
|
||||
|
||||
// TODO: Compute inertia if body is dynamic
|
||||
}
|
||||
|
||||
SHRigidBody::SHRigidBody(const SHRigidBody& rhs) noexcept
|
||||
|
|
|
@ -360,8 +360,8 @@ RTTR_REGISTRATION
|
|||
|
||||
registration::class_<SHRigidBodyComponent>("RigidBody Component")
|
||||
.property("Type" , &SHRigidBodyComponent::GetType , &SHRigidBodyComponent::SetType )
|
||||
.property("Auto Mass" , &SHRigidBodyComponent::GetAutoMass , &SHRigidBodyComponent::SetAutoMass )
|
||||
.property("Mass" , &SHRigidBodyComponent::GetMass , &SHRigidBodyComponent::SetMass )
|
||||
.property("Auto Mass" , &SHRigidBodyComponent::GetAutoMass , &SHRigidBodyComponent::SetAutoMass )
|
||||
.property("Drag" , &SHRigidBodyComponent::GetDrag , &SHRigidBodyComponent::SetDrag )
|
||||
.property("Angular Drag" , &SHRigidBodyComponent::GetAngularDrag , &SHRigidBodyComponent::SetAngularDrag )
|
||||
.property("Use Gravity" , &SHRigidBodyComponent::IsGravityEnabled , &SHRigidBodyComponent::SetIsGravityEnabled )
|
||||
|
|
Loading…
Reference in New Issue