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