Skip to content

Commit

Permalink
[physicsbody] cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosK92 committed Jan 7, 2025
1 parent f2b97b9 commit 1c8a15e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 36 deletions.
34 changes: 5 additions & 29 deletions runtime/World/Components/PhysicsBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,7 @@ namespace Spartan

PhysicsBody::PhysicsBody(Entity* entity) : Component(entity)
{
m_in_world = false;
m_mass = default_mass;
m_restitution = default_restitution;
m_friction = default_friction;
m_friction_rolling = default_friction_rolling;
m_use_gravity = true;
m_gravity = Physics::GetGravity();
m_is_kinematic = false;
m_position_lock = Vector3::Zero;
m_rotation_lock = Vector3::Zero;
m_rigid_body = nullptr;
m_shape_type = PhysicsShape::Box;
m_center_of_mass = Vector3::Zero;
m_size = Vector3::One;
m_shape = nullptr;
m_gravity = Physics::GetGravity();

SP_REGISTER_ATTRIBUTE_VALUE_VALUE(m_mass, float);
SP_REGISTER_ATTRIBUTE_VALUE_VALUE(m_friction, float);
Expand Down Expand Up @@ -272,7 +258,6 @@ namespace Spartan
stream->Write(m_is_kinematic);
stream->Write(m_position_lock);
stream->Write(m_rotation_lock);
stream->Write(m_in_world);
stream->Write(uint32_t(m_shape_type));
stream->Write(m_size);
stream->Write(m_center_of_mass);
Expand All @@ -289,7 +274,6 @@ namespace Spartan
stream->Read(&m_is_kinematic);
stream->Read(&m_position_lock);
stream->Read(&m_rotation_lock);
stream->Read(&m_in_world);
m_shape_type = PhysicsShape(stream->ReadAs<uint32_t>());
stream->Read(&m_size);
stream->Read(&m_center_of_mass);
Expand Down Expand Up @@ -710,8 +694,6 @@ namespace Spartan
SetLinearVelocity(Vector3::Zero);
SetAngularVelocity(Vector3::Zero);
}

m_in_world = true;
}
}

Expand All @@ -720,20 +702,14 @@ namespace Spartan
if (!m_rigid_body)
return;

// release any constraints that refer to it
for (const auto& constraint : m_constraints)
{
constraint->ReleaseConstraint();
}

if (m_rigid_body)
{
if (m_in_world)
{
Physics::RemoveBody(reinterpret_cast<btRigidBody*&>(m_rigid_body));
m_in_world = false;
}

Physics::RemoveBody(reinterpret_cast<btRigidBody*&>(m_rigid_body));
delete rigid_body->getMotionState();
delete rigid_body;
m_rigid_body = nullptr;
Expand Down Expand Up @@ -979,9 +955,9 @@ namespace Spartan
{
// create
btConvexHullShape* shape_convex = new btConvexHullShape(
reinterpret_cast<btScalar*>(&vertices[0]),
static_cast<uint32_t>(vertices.size()),
static_cast<uint32_t>(sizeof(RHI_Vertex_PosTexNorTan))
reinterpret_cast<btScalar*>(&vertices[0]),
static_cast<uint32_t>(vertices.size()),
static_cast<uint32_t>(sizeof(RHI_Vertex_PosTexNorTan))
);
shape_convex->optimizeConvexHull();

Expand Down
12 changes: 5 additions & 7 deletions runtime/World/Components/PhysicsBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ namespace Spartan
void ClearForces() const;
void Activate() const;
void Deactivate() const;
bool IsInWorld() const { return m_in_world; }
void* GetBtRigidBody() const { return m_rigid_body; }
std::shared_ptr<Car> GetCar() { return m_car; }

Expand All @@ -167,11 +166,11 @@ namespace Spartan
void RemoveBodyFromWorld();
void UpdateShape();

float m_mass = 0.0f;
float m_friction = 0.0f;
float m_friction_rolling = 0.0f;
float m_restitution = 0.0f;
bool m_use_gravity = false;
float m_mass = 1.0f;
float m_friction = 1.0f;
float m_friction_rolling = 0.002f;
float m_restitution = 0.2f;
bool m_use_gravity = true;
bool m_is_kinematic = false;
Math::Vector3 m_gravity = Math::Vector3::Zero;
Math::Vector3 m_position_lock = Math::Vector3::Zero;
Expand All @@ -182,7 +181,6 @@ namespace Spartan
PhysicsBodyType m_body_type = PhysicsBodyType::RigidBody;
uint32_t terrain_width = 0;
uint32_t terrain_length = 0;
bool m_in_world = false;
void* m_shape = nullptr;
void* m_rigid_body = nullptr;
std::shared_ptr<Car> m_car = nullptr;
Expand Down

0 comments on commit 1c8a15e

Please sign in to comment.