Added sphere collider + serialization

This commit is contained in:
antopilo
2023-03-08 21:24:58 -05:00
parent d50b04be28
commit 0a6f7ad733
3 changed files with 34 additions and 1 deletions

View File

@@ -7,7 +7,24 @@ namespace Nuake {
{
public:
Ref<Physics::PhysicShape> Sphere;
float Radius = 0.5f;
bool IsTrigger;
bool IsTrigger = false;
json Serialize()
{
BEGIN_SERIALIZE();
j["Radius"] = Radius;
j["IsTrigger"] = IsTrigger;
END_SERIALIZE();
}
bool Deserialize(const std::string& str)
{
BEGIN_DESERIALIZE();
this->Radius = j["Radius"];
this->IsTrigger = j["IsTrigger"];
return true;
}
};
}

View File

@@ -46,6 +46,8 @@ namespace Nuake
SERIALIZE_OBJECT_REF_LBL("CharacterControllerComponent", GetComponent<CharacterControllerComponent>());
if (HasComponent<BoxColliderComponent>())
SERIALIZE_OBJECT_REF_LBL("BoxColliderComponent", GetComponent<BoxColliderComponent>());
if (HasComponent<SphereColliderComponent>())
SERIALIZE_OBJECT_REF_LBL("SphereColliderComponent", GetComponent<SphereColliderComponent>());
if (HasComponent<ModelComponent>())
SERIALIZE_OBJECT_REF_LBL("ModelComponent", GetComponent<ModelComponent>());
if (HasComponent<BSPBrushComponent>())
@@ -76,6 +78,7 @@ namespace Nuake
DESERIALIZE_COMPONENT(WrenScriptComponent);
DESERIALIZE_COMPONENT(CharacterControllerComponent);
DESERIALIZE_COMPONENT(BoxColliderComponent);
DESERIALIZE_COMPONENT(SphereColliderComponent);
DESERIALIZE_COMPONENT(RigidBodyComponent);
return true;
}

View File

@@ -2,6 +2,7 @@
#include "src/Scene/Scene.h"
#include "src/Scene/Components/BoxCollider.h"
#include "src/Scene/Components/SphereCollider.h"
#include "src/Scene/Components/MeshCollider.h"
#include <src/Scene/Components/RigidbodyComponent.h>
#include "src/Scene/Entities/Entity.h"
@@ -35,6 +36,18 @@ namespace Nuake
Ref<Physics::Box> boxShape = CreateRef<Physics::Box>(boxComponent.Size);
rigidBody = CreateRef<Physics::RigidBody>(mass, transform.GetGlobalPosition(), boxShape, ent);
PhysicsManager::Get()->RegisterBody(rigidBody);
}
if (ent.HasComponent<SphereColliderComponent>())
{
float mass = rigidbody.Mass;
const auto& component = ent.GetComponent<SphereColliderComponent>();
auto shape = CreateRef<Physics::Sphere>(component.Radius);
rigidBody = CreateRef<Physics::RigidBody>(mass, transform.GetGlobalPosition(), shape, ent);
PhysicsManager::Get()->RegisterBody(rigidBody);
}
if (ent.HasComponent<SphereColliderComponent>())