mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Added sphere collider + serialization
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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>())
|
||||
|
||||
Reference in New Issue
Block a user