Sdk/Physics3D: Handle properly disabled physics entity
This commit is contained in:
parent
498bd77d8a
commit
f1b84bfc9e
|
|
@ -64,6 +64,7 @@ Nazara Development Kit:
|
|||
- Fix GraphicsComponent cloning not copying renderable local matrices
|
||||
- ⚠️ Rename PhysicsComponent3D::[Get|Set]Velocity to [Get|Set]LinearVelocity
|
||||
- Add OnEntityDisabled and OnEntityEnabled callbacks to BaseComponent
|
||||
- Disabling an entity with a CollisionComponent3D or PhysicsComponent3D will properly disable it from the physics simulation
|
||||
|
||||
# 0.4:
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ namespace Ndk
|
|||
void OnComponentAttached(BaseComponent& component) override;
|
||||
void OnComponentDetached(BaseComponent& component) override;
|
||||
void OnDetached() override;
|
||||
void OnEntityDisabled() override;
|
||||
void OnEntityEnabled() override;
|
||||
|
||||
std::unique_ptr<Nz::RigidBody3D> m_staticBody;
|
||||
Nz::Collider3DRef m_geom;
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ namespace Ndk
|
|||
void OnComponentDetached(BaseComponent& component) override;
|
||||
void OnDetached() override;
|
||||
void OnEntityDestruction() override;
|
||||
void OnEntityDisabled() override;
|
||||
void OnEntityEnabled() override;
|
||||
|
||||
std::unique_ptr<Nz::RigidBody3D> m_object;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ namespace Ndk
|
|||
NazaraAssert(entityWorld->HasSystem<PhysicsSystem3D>(), "World must have a physics system");
|
||||
Nz::PhysWorld3D& physWorld = entityWorld->GetSystem<PhysicsSystem3D>().GetWorld();
|
||||
|
||||
m_staticBody.reset(new Nz::RigidBody3D(&physWorld, m_geom));
|
||||
m_staticBody = std::make_unique<Nz::RigidBody3D>(&physWorld, m_geom);
|
||||
m_staticBody->EnableAutoSleep(false);
|
||||
}
|
||||
|
||||
|
|
@ -104,5 +104,17 @@ namespace Ndk
|
|||
m_staticBody.reset();
|
||||
}
|
||||
|
||||
void CollisionComponent3D::OnEntityDisabled()
|
||||
{
|
||||
if (m_staticBody)
|
||||
m_staticBody->EnableSimulation(false);
|
||||
}
|
||||
|
||||
void CollisionComponent3D::OnEntityEnabled()
|
||||
{
|
||||
if (m_staticBody)
|
||||
m_staticBody->EnableSimulation(true);
|
||||
}
|
||||
|
||||
ComponentIndex CollisionComponent3D::componentIndex;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,5 +93,19 @@ namespace Ndk
|
|||
m_object.reset();
|
||||
}
|
||||
|
||||
void PhysicsComponent3D::OnEntityDisabled()
|
||||
{
|
||||
NazaraAssert(m_object, "Invalid physics object");
|
||||
|
||||
m_object->EnableSimulation(false);
|
||||
}
|
||||
|
||||
void PhysicsComponent3D::OnEntityEnabled()
|
||||
{
|
||||
NazaraAssert(m_object, "Invalid physics object");
|
||||
|
||||
m_object->EnableSimulation(true);
|
||||
}
|
||||
|
||||
ComponentIndex PhysicsComponent3D::componentIndex;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue