Fixed auto mass serialisation and colliders not recomputing mass on size change
This commit is contained in:
parent
9b2c5a1804
commit
02b21f2694
|
@ -50,8 +50,8 @@
|
||||||
IsActive: true
|
IsActive: true
|
||||||
RigidBody Component:
|
RigidBody Component:
|
||||||
Type: Dynamic
|
Type: Dynamic
|
||||||
Auto Mass: false
|
|
||||||
Mass: 1
|
Mass: 1
|
||||||
|
Auto Mass: false
|
||||||
Drag: 0.00999999978
|
Drag: 0.00999999978
|
||||||
Angular Drag: 0.00999999978
|
Angular Drag: 0.00999999978
|
||||||
Use Gravity: true
|
Use Gravity: true
|
||||||
|
@ -188,8 +188,8 @@
|
||||||
IsActive: true
|
IsActive: true
|
||||||
RigidBody Component:
|
RigidBody Component:
|
||||||
Type: Dynamic
|
Type: Dynamic
|
||||||
Auto Mass: false
|
|
||||||
Mass: 1
|
Mass: 1
|
||||||
|
Auto Mass: false
|
||||||
Drag: 0.00999999978
|
Drag: 0.00999999978
|
||||||
Angular Drag: 0.00999999978
|
Angular Drag: 0.00999999978
|
||||||
Use Gravity: true
|
Use Gravity: true
|
||||||
|
@ -228,8 +228,8 @@
|
||||||
IsActive: true
|
IsActive: true
|
||||||
RigidBody Component:
|
RigidBody Component:
|
||||||
Type: Dynamic
|
Type: Dynamic
|
||||||
Auto Mass: false
|
|
||||||
Mass: 1
|
Mass: 1
|
||||||
|
Auto Mass: false
|
||||||
Drag: 0.00999999978
|
Drag: 0.00999999978
|
||||||
Angular Drag: 0.00999999978
|
Angular Drag: 0.00999999978
|
||||||
Use Gravity: true
|
Use Gravity: true
|
||||||
|
@ -268,8 +268,8 @@
|
||||||
IsActive: true
|
IsActive: true
|
||||||
RigidBody Component:
|
RigidBody Component:
|
||||||
Type: Dynamic
|
Type: Dynamic
|
||||||
Auto Mass: false
|
|
||||||
Mass: 1
|
Mass: 1
|
||||||
|
Auto Mass: false
|
||||||
Drag: 0.00999999978
|
Drag: 0.00999999978
|
||||||
Angular Drag: 0.00999999978
|
Angular Drag: 0.00999999978
|
||||||
Use Gravity: true
|
Use Gravity: true
|
||||||
|
@ -308,8 +308,8 @@
|
||||||
IsActive: true
|
IsActive: true
|
||||||
RigidBody Component:
|
RigidBody Component:
|
||||||
Type: Dynamic
|
Type: Dynamic
|
||||||
Auto Mass: false
|
|
||||||
Mass: 1
|
Mass: 1
|
||||||
|
Auto Mass: false
|
||||||
Drag: 0.00999999978
|
Drag: 0.00999999978
|
||||||
Angular Drag: 0.00999999978
|
Angular Drag: 0.00999999978
|
||||||
Use Gravity: true
|
Use Gravity: true
|
||||||
|
@ -328,7 +328,7 @@
|
||||||
- Is Trigger: false
|
- Is Trigger: false
|
||||||
Collision Tag: 0
|
Collision Tag: 0
|
||||||
Type: Box
|
Type: Box
|
||||||
Half Extents: {x: 1, y: 1, z: 1}
|
Half Extents: {x: 1, y: 2, z: 1}
|
||||||
Friction: 0.400000006
|
Friction: 0.400000006
|
||||||
Bounciness: 0
|
Bounciness: 0
|
||||||
Density: 1
|
Density: 1
|
||||||
|
|
|
@ -326,6 +326,17 @@ namespace SHADE
|
||||||
shape->Update();
|
shape->Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHCollider::UpdateBroadphase() noexcept
|
||||||
|
{
|
||||||
|
flags |= MOVED_FLAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHCollider::UpdateBody() noexcept
|
||||||
|
{
|
||||||
|
if (rigidBody)
|
||||||
|
rigidBody->ComputeMassData();
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Private Member Function Definitions */
|
/* Private Member Function Definitions */
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -149,6 +149,18 @@ namespace SHADE
|
||||||
*/
|
*/
|
||||||
void Update () noexcept;
|
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:
|
protected:
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Data Members */
|
/* Data Members */
|
||||||
|
|
|
@ -207,9 +207,11 @@ namespace SHADE
|
||||||
// Recompute Relative radius
|
// Recompute Relative radius
|
||||||
relativeExtents = 2.0f * Extents / scale;
|
relativeExtents = 2.0f * Extents / scale;
|
||||||
|
|
||||||
// Hack: Indicate that the collider needs to update the broadphase proxy
|
|
||||||
if (collider)
|
if (collider)
|
||||||
collider->SetScale(collider->GetScale());
|
{
|
||||||
|
collider->UpdateBroadphase();
|
||||||
|
collider->UpdateBody();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHBox::SetRelativeExtents(const SHVec3& newRelativeExtents) noexcept
|
void SHBox::SetRelativeExtents(const SHVec3& newRelativeExtents) noexcept
|
||||||
|
@ -219,9 +221,11 @@ namespace SHADE
|
||||||
// Recompute world radius
|
// Recompute world radius
|
||||||
Extents = relativeExtents * scale * 0.5f;
|
Extents = relativeExtents * scale * 0.5f;
|
||||||
|
|
||||||
// Hack: Indicate that the collider needs to update the broadphase proxy
|
|
||||||
if (collider)
|
if (collider)
|
||||||
collider->SetScale(collider->GetScale());
|
{
|
||||||
|
collider->UpdateBroadphase();
|
||||||
|
collider->UpdateBody();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHBox::SetScale(const SHVec3& newScale) noexcept
|
void SHBox::SetScale(const SHVec3& newScale) noexcept
|
||||||
|
@ -231,9 +235,11 @@ namespace SHADE
|
||||||
// Recompute world radius
|
// Recompute world radius
|
||||||
Extents = relativeExtents * scale * 0.5f;
|
Extents = relativeExtents * scale * 0.5f;
|
||||||
|
|
||||||
// Hack: Indicate that the collider needs to update the broadphase proxy
|
|
||||||
if (collider)
|
if (collider)
|
||||||
collider->SetScale(collider->GetScale());
|
{
|
||||||
|
collider->UpdateBroadphase();
|
||||||
|
collider->UpdateBody();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -168,9 +168,11 @@ namespace SHADE
|
||||||
// Recompute Relative radius
|
// Recompute Relative radius
|
||||||
relativeRadius = 2.0f * Radius / scale;
|
relativeRadius = 2.0f * Radius / scale;
|
||||||
|
|
||||||
// Hack: Indicate that the collider needs to update the broadphase proxy
|
|
||||||
if (collider)
|
if (collider)
|
||||||
collider->SetScale(collider->GetScale());
|
{
|
||||||
|
collider->UpdateBroadphase();
|
||||||
|
collider->UpdateBody();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHSphere::SetRelativeRadius(float newRelativeRadius) noexcept
|
void SHSphere::SetRelativeRadius(float newRelativeRadius) noexcept
|
||||||
|
@ -180,9 +182,11 @@ namespace SHADE
|
||||||
// Recompute world radius
|
// Recompute world radius
|
||||||
Radius = relativeRadius * scale * 0.5f;
|
Radius = relativeRadius * scale * 0.5f;
|
||||||
|
|
||||||
// Hack: Indicate that the collider needs to update the broadphase proxy
|
|
||||||
if (collider)
|
if (collider)
|
||||||
collider->SetScale(collider->GetScale());
|
{
|
||||||
|
collider->UpdateBroadphase();
|
||||||
|
collider->UpdateBody();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHSphere::SetScale(float maxScale) noexcept
|
void SHSphere::SetScale(float maxScale) noexcept
|
||||||
|
@ -192,9 +196,11 @@ namespace SHADE
|
||||||
// Recompute world radius
|
// Recompute world radius
|
||||||
Radius = relativeRadius * scale * 0.5f;
|
Radius = relativeRadius * scale * 0.5f;
|
||||||
|
|
||||||
// Hack: Indicate that the collider needs to update the broadphase proxy
|
|
||||||
if (collider)
|
if (collider)
|
||||||
collider->SetScale(collider->GetScale());
|
{
|
||||||
|
collider->UpdateBroadphase();
|
||||||
|
collider->UpdateBody();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -40,8 +40,6 @@ namespace SHADE
|
||||||
flags |= 1U << 0; // Body is active
|
flags |= 1U << 0; // Body is active
|
||||||
flags |= 1U << 2; // Sleeping is enabled
|
flags |= 1U << 2; // Sleeping is enabled
|
||||||
flags |= 1U << 3; // Gravity is enabled
|
flags |= 1U << 3; // Gravity is enabled
|
||||||
|
|
||||||
// TODO: Compute inertia if body is dynamic
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SHRigidBody::SHRigidBody(const SHRigidBody& rhs) noexcept
|
SHRigidBody::SHRigidBody(const SHRigidBody& rhs) noexcept
|
||||||
|
|
|
@ -360,8 +360,8 @@ RTTR_REGISTRATION
|
||||||
|
|
||||||
registration::class_<SHRigidBodyComponent>("RigidBody Component")
|
registration::class_<SHRigidBodyComponent>("RigidBody Component")
|
||||||
.property("Type" , &SHRigidBodyComponent::GetType , &SHRigidBodyComponent::SetType )
|
.property("Type" , &SHRigidBodyComponent::GetType , &SHRigidBodyComponent::SetType )
|
||||||
.property("Auto Mass" , &SHRigidBodyComponent::GetAutoMass , &SHRigidBodyComponent::SetAutoMass )
|
|
||||||
.property("Mass" , &SHRigidBodyComponent::GetMass , &SHRigidBodyComponent::SetMass )
|
.property("Mass" , &SHRigidBodyComponent::GetMass , &SHRigidBodyComponent::SetMass )
|
||||||
|
.property("Auto Mass" , &SHRigidBodyComponent::GetAutoMass , &SHRigidBodyComponent::SetAutoMass )
|
||||||
.property("Drag" , &SHRigidBodyComponent::GetDrag , &SHRigidBodyComponent::SetDrag )
|
.property("Drag" , &SHRigidBodyComponent::GetDrag , &SHRigidBodyComponent::SetDrag )
|
||||||
.property("Angular Drag" , &SHRigidBodyComponent::GetAngularDrag , &SHRigidBodyComponent::SetAngularDrag )
|
.property("Angular Drag" , &SHRigidBodyComponent::GetAngularDrag , &SHRigidBodyComponent::SetAngularDrag )
|
||||||
.property("Use Gravity" , &SHRigidBodyComponent::IsGravityEnabled , &SHRigidBodyComponent::SetIsGravityEnabled )
|
.property("Use Gravity" , &SHRigidBodyComponent::IsGravityEnabled , &SHRigidBodyComponent::SetIsGravityEnabled )
|
||||||
|
|
Loading…
Reference in New Issue