39 lines
947 B
C++
39 lines
947 B
C++
#pragma once
|
|
|
|
#include <algorithm>
|
|
|
|
#include <destrum/Components/Physics/Collider.h>
|
|
|
|
class SphereCollider final : public Collider {
|
|
public:
|
|
explicit SphereCollider(GameObject& owner, float radius = 0.5f)
|
|
: Collider(owner)
|
|
, m_Radius(std::max(radius, 0.0001f)) {}
|
|
|
|
void Update(float) override {}
|
|
|
|
nlohmann::json Serialize() const override;
|
|
void Deserialize(const nlohmann::json& data) override;
|
|
void ImGuiInspector() override;
|
|
std::string GetTypeName() const override
|
|
{
|
|
return "SphereCollider";
|
|
}
|
|
|
|
[[nodiscard]] PhysicsShapeDesc BuildPhysicsShape() const override {
|
|
return PhysicsShapeDesc::Sphere(m_Radius, m_CenterOffset, m_IsTrigger);
|
|
}
|
|
|
|
[[nodiscard]] float GetRadius() const {
|
|
return m_Radius;
|
|
}
|
|
|
|
void SetRadius(float radius) {
|
|
m_Radius = std::max(radius, 0.0001f);
|
|
NotifyPhysicsChanged();
|
|
}
|
|
|
|
private:
|
|
float m_Radius{0.5f};
|
|
};
|