Added sphere collider

This commit is contained in:
antopilo
2023-03-08 20:21:50 -05:00
parent 75cb774caf
commit 8c9c6c21df
4 changed files with 54 additions and 4 deletions

View File

@@ -0,0 +1,38 @@
#pragma once
#include "ComponentPanel.h"
#include <src/Scene/Components/SphereCollider.h>
#include <src/Core/FileSystem.h>
#include <src/Scene/Entities/ImGuiHelper.h>
class SphereColliderPanel : ComponentPanel {
public:
SphereColliderPanel() {}
void Draw(Nuake::Entity entity) override
{
if (!entity.HasComponent<Nuake::SphereColliderComponent>())
return;
auto& component = entity.GetComponent<Nuake::SphereColliderComponent>();
BeginComponentTable(SPHERE COLLIDER, Nuake::SphereColliderComponent);
{
{
ImGui::Text("Size");
ImGui::TableNextColumn();
ImGui::DragFloat("##Radius", &component.Radius);
ImGui::TableNextColumn();
ComponentTableReset(component.Radius, 0.5f);
}
ImGui::TableNextColumn();
{
ImGui::Text("Is Trigger");
ImGui::TableNextColumn();
ImGui::Checkbox("##isTrigger", &component.IsTrigger);
ImGui::TableNextColumn();
ComponentTableReset(component.IsTrigger, false);
}
}
EndComponentTable();
}
};

View File

@@ -100,7 +100,7 @@ void EditorSelectionPanel::DrawEntity(Nuake::Entity entity)
mCameraPanel.Draw(entity);
mRigidbodyPanel.Draw(entity);
mBoxColliderPanel.Draw(entity);
mSphereColliderPanel.Draw(entity);
/*
if (Selection.Entity.HasComponent<MeshComponent>())
{

View File

@@ -13,6 +13,7 @@
#include "../ComponentsPanel/CameraPanel.h"
#include "../ComponentsPanel/RigidbodyPanel.h"
#include "../ComponentsPanel/BoxColliderPanel.h"
#include "../ComponentsPanel/SphereColliderPanel.h"
class EditorSelectionPanel {
private:
@@ -24,6 +25,7 @@ private:
CameraPanel mCameraPanel;
RigidbodyPanel mRigidbodyPanel;
BoxColliderPanel mBoxColliderPanel;
SphereColliderPanel mSphereColliderPanel;
Ref<Nuake::File> currentFile;
Ref<Nuake::Resource> selectedResource;

View File

@@ -1,6 +1,7 @@
#include "PhysicsSystem.h"
#include "src/Scene/Scene.h"
#include "src/Scene/Components/BoxCollider.h"
#include "src/Scene/Components/SphereCollider.h"
#include <src/Scene/Components/RigidbodyComponent.h>
#include "src/Scene/Entities/Entity.h"
@@ -25,7 +26,7 @@ namespace Nuake
{
auto [transform, rigidbody] = view.get<TransformComponent, RigidBodyComponent>(e);
Entity ent = Entity({ e, m_Scene });
Ref<Physics::RigidBody> rigidBody;
if (ent.HasComponent<BoxColliderComponent>())
{
float mass = rigidbody.Mass;
@@ -33,9 +34,18 @@ namespace Nuake
BoxColliderComponent& boxComponent = ent.GetComponent<BoxColliderComponent>();
Ref<Physics::Box> boxShape = CreateRef<Physics::Box>(boxComponent.Size);
Ref<Physics::RigidBody> btRigidbody = CreateRef<Physics::RigidBody>(mass, transform.GetGlobalPosition(), boxShape);
rigidBody = CreateRef<Physics::RigidBody>(mass, transform.GetGlobalPosition(), boxShape, ent);
}
PhysicsManager::Get()->RegisterBody(btRigidbody);
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);
}
}