mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Started character controller implementation
This commit is contained in:
48
Editor/src/ComponentsPanel/CharacterControllerPanel.h
Normal file
48
Editor/src/ComponentsPanel/CharacterControllerPanel.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
#include "ComponentPanel.h"
|
||||
#include <src/Scene/Components/CharacterControllerComponent.h>
|
||||
#include <src/Core/FileSystem.h>
|
||||
|
||||
class CharacterControllerPanel : ComponentPanel {
|
||||
|
||||
public:
|
||||
CharacterControllerPanel() {}
|
||||
|
||||
void Draw(Nuake::Entity entity) override
|
||||
{
|
||||
if (!entity.HasComponent<Nuake::CharacterControllerComponent>())
|
||||
return;
|
||||
|
||||
auto& component = entity.GetComponent<Nuake::CharacterControllerComponent>();
|
||||
BeginComponentTable(CHARACTER CONTROLLER, Nuake::CharacterControllerComponent);
|
||||
{
|
||||
{
|
||||
ImGui::Text("Height");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::DragFloat("##Height", &component.Height, 0.01f, 0.1f, 100.0f);
|
||||
ImGui::TableNextColumn();
|
||||
ComponentTableReset(component.Height, 1.0f)
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
{
|
||||
ImGui::Text("Radius");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::DragFloat("##Radius", &component.Radius, 0.01f, 0.1f, 10.0f);
|
||||
ImGui::TableNextColumn();
|
||||
ComponentTableReset(component.Radius, 0.25f)
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
{
|
||||
ImGui::Text("Mass");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::DragFloat("##Mass", &component.Mass, 0.001f, 0.00001f, 10.0f);
|
||||
ImGui::TableNextColumn();
|
||||
ComponentTableReset(component.Mass, 0.001f)
|
||||
}
|
||||
}
|
||||
EndComponentTable()
|
||||
}
|
||||
};
|
||||
@@ -102,255 +102,7 @@ void EditorSelectionPanel::DrawEntity(Nuake::Entity entity)
|
||||
mBoxColliderPanel.Draw(entity);
|
||||
mSphereColliderPanel.Draw(entity);
|
||||
mMeshColliderPanel.Draw(entity);
|
||||
|
||||
/*
|
||||
if (Selection.Entity.HasComponent<MeshComponent>())
|
||||
{
|
||||
std::string icon = ICON_FA_MALE;
|
||||
if (ImGui::CollapsingHeader((icon + " " + "Mesh").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Mesh properties");
|
||||
auto& component = Selection.Entity.GetComponent<MeshComponent>();
|
||||
// Path
|
||||
std::string path = component.ModelPath;
|
||||
char pathBuffer[256];
|
||||
|
||||
memset(pathBuffer, 0, sizeof(pathBuffer));
|
||||
std::strncpy(pathBuffer, path.c_str(), sizeof(pathBuffer));
|
||||
|
||||
std::string oldPath = component.ModelPath;
|
||||
ImGui::Text("Model: ");
|
||||
ImGui::SameLine();
|
||||
if (ImGui::InputText("##ModelPath", pathBuffer, sizeof(pathBuffer)))
|
||||
path = FileSystem::AbsoluteToRelative(std::string(pathBuffer));
|
||||
if (ImGui::BeginDragDropTarget())
|
||||
{
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Model"))
|
||||
{
|
||||
char* file = (char*)payload->Data;
|
||||
std::string fullPath = std::string(file, 256);
|
||||
path = FileSystem::AbsoluteToRelative(fullPath);
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
|
||||
if (component.ModelPath != path)
|
||||
{
|
||||
component.ModelPath = path;
|
||||
component.LoadModel();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::Button("Reimport"))
|
||||
{
|
||||
component.LoadModel();
|
||||
}
|
||||
|
||||
ImGui::Indent(16.0f);
|
||||
if (ImGui::CollapsingHeader("Meshes"))
|
||||
{
|
||||
ImGui::Indent(16.0f);
|
||||
uint16_t index = 0;
|
||||
for (auto& m : component.meshes)
|
||||
{
|
||||
if (ImGui::CollapsingHeader(std::to_string(index).c_str()))
|
||||
{
|
||||
std::string materialName = "No material";
|
||||
if (m->m_Material)
|
||||
materialName = m->m_Material->GetName();
|
||||
|
||||
ImGui::Indent(16.0f);
|
||||
if (ImGui::CollapsingHeader(materialName.c_str()))
|
||||
{
|
||||
//if (ImGui::BeginChild("Material child", ImVec2(0, 0), true, ImGuiWindowFlags_AlwaysAutoResize))
|
||||
//{
|
||||
ImGui::Indent(16.0f);
|
||||
DrawMaterialEditor(m->m_Material);
|
||||
//}
|
||||
//ImGui::EndChild();
|
||||
}
|
||||
|
||||
if (ImGui::BeginDragDropTarget())
|
||||
{
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Material"))
|
||||
{
|
||||
char* file = (char*)payload->Data;
|
||||
std::string fullPath = std::string(file, 256);
|
||||
path = FileSystem::AbsoluteToRelative(fullPath);
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (Selection.Entity.HasComponent<WrenScriptComponent>()) {
|
||||
std::string icon = ICON_FA_FILE;
|
||||
if (ImGui::CollapsingHeader((icon + " " + "Wren Script").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Script properties");
|
||||
auto& component = Selection.Entity.GetComponent<WrenScriptComponent>();
|
||||
|
||||
// Path
|
||||
std::string path = component.Script;
|
||||
char pathBuffer[256];
|
||||
|
||||
memset(pathBuffer, 0, sizeof(pathBuffer));
|
||||
std::strncpy(pathBuffer, path.c_str(), sizeof(pathBuffer));
|
||||
|
||||
ImGui::Text("Script: ");
|
||||
ImGui::SameLine();
|
||||
if (ImGui::InputText("##ScriptPath", pathBuffer, sizeof(pathBuffer)))
|
||||
path = FileSystem::AbsoluteToRelative(std::string(pathBuffer));
|
||||
if (ImGui::BeginDragDropTarget())
|
||||
{
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Script"))
|
||||
{
|
||||
char* file = (char*)payload->Data;
|
||||
std::string fullPath = std::string(file, 256);
|
||||
path = FileSystem::AbsoluteToRelative(fullPath);
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
|
||||
|
||||
component.Script = path;
|
||||
|
||||
// Class
|
||||
std::string module = component.Class;
|
||||
|
||||
char classBuffer[256];
|
||||
|
||||
memset(classBuffer, 0, sizeof(classBuffer));
|
||||
std::strncpy(classBuffer, module.c_str(), sizeof(classBuffer));
|
||||
|
||||
ImGui::Text("Class: ");
|
||||
ImGui::SameLine();
|
||||
if (ImGui::InputText("##ScriptModule", classBuffer, sizeof(classBuffer)))
|
||||
module = std::string(classBuffer);
|
||||
|
||||
component.Class = module;
|
||||
ImGui::Separator();
|
||||
}
|
||||
}
|
||||
|
||||
if (Selection.Entity.HasComponent<CameraComponent>()) {
|
||||
|
||||
std::string icon = ICON_FA_LIGHTBULB;
|
||||
if (ImGui::CollapsingHeader((icon + " " + "Camera").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Camera properties");
|
||||
Selection.Entity.GetComponent<CameraComponent>().DrawEditor();
|
||||
ImGui::Separator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (Selection.Entity.HasComponent<CharacterControllerComponent>())
|
||||
{
|
||||
if (ImGui::CollapsingHeader("Character controller", ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Character controller properties");
|
||||
auto& c = Selection.Entity.GetComponent<CharacterControllerComponent>();
|
||||
ImGui::InputFloat("Height", &c.Height);
|
||||
ImGui::InputFloat("Radius", &c.Radius);
|
||||
ImGui::InputFloat("Mass", &c.Mass);
|
||||
ImGui::Separator();
|
||||
}
|
||||
}
|
||||
if (Selection.Entity.HasComponent<RigidBodyComponent>())
|
||||
{
|
||||
std::string icon = ICON_FA_BOWLING_BALL;
|
||||
if (ImGui::CollapsingHeader((icon + " Rigidbody").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Rigidbody properties");
|
||||
RigidBodyComponent& rbComponent = Selection.Entity.GetComponent<RigidBodyComponent>();
|
||||
ImGui::DragFloat("Mass", &rbComponent.mass, 0.1, 0.0);
|
||||
ImGui::Separator();
|
||||
}
|
||||
}
|
||||
if (Selection.Entity.HasComponent<BoxColliderComponent>())
|
||||
{
|
||||
std::string icon = ICON_FA_BOX;
|
||||
if (ImGui::CollapsingHeader((icon + " Box collider").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Box collider properties");
|
||||
BoxColliderComponent& component = Selection.Entity.GetComponent<BoxColliderComponent>();
|
||||
ImGuiHelper::DrawVec3("Size", &component.Size);
|
||||
ImGui::Checkbox("Is trigger", &component.IsTrigger);
|
||||
|
||||
ImGui::Separator();
|
||||
}
|
||||
}
|
||||
if (Selection.Entity.HasComponent<SphereColliderComponent>())
|
||||
{
|
||||
std::string icon = ICON_FA_CIRCLE;
|
||||
if (ImGui::CollapsingHeader((icon + " Sphere collider").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Sphere properties");
|
||||
SphereColliderComponent& component = Selection.Entity.GetComponent<SphereColliderComponent>();
|
||||
ImGui::DragFloat("Radius", &component.Radius, 0.1f, 0.0f, 100.0f);
|
||||
ImGui::Checkbox("Is trigger", &component.IsTrigger);
|
||||
|
||||
ImGui::Separator();
|
||||
}
|
||||
}
|
||||
if (Selection.Entity.HasComponent<QuakeMapComponent>())
|
||||
{
|
||||
|
||||
std::string icon = ICON_FA_BROOM;
|
||||
if (ImGui::CollapsingHeader((icon + " " + "Quake map").c_str(), ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Quake map properties");
|
||||
auto& component = Selection.Entity.GetComponent<QuakeMapComponent>();
|
||||
std::string path = component.Path;
|
||||
|
||||
|
||||
char pathBuffer[256];
|
||||
memset(pathBuffer, 0, sizeof(pathBuffer));
|
||||
std::strncpy(pathBuffer, path.c_str(), sizeof(pathBuffer));
|
||||
ImGui::Text("Map file: ");
|
||||
ImGui::SameLine();
|
||||
if (ImGui::InputText("##MapPath", pathBuffer, sizeof(pathBuffer)))
|
||||
{
|
||||
path = std::string(pathBuffer);
|
||||
}
|
||||
|
||||
if (ImGui::BeginDragDropTarget())
|
||||
{
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_Map"))
|
||||
{
|
||||
char* file = (char*)payload->Data;
|
||||
std::string fullPath = std::string(file, 256);
|
||||
path = FileSystem::AbsoluteToRelative(fullPath);
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
|
||||
component.Path = path;
|
||||
|
||||
ImGui::InputFloat("Scale factor", &component.ScaleFactor, 0.01f, 0.1f);
|
||||
|
||||
ImGui::Checkbox("Build collisions", &component.HasCollisions);
|
||||
if (ImGui::Button("Build Geometry"))
|
||||
{
|
||||
QuakeMapBuilder mapBuilder;
|
||||
mapBuilder.BuildQuakeMap(Selection.Entity);
|
||||
}
|
||||
ImGui::Separator();
|
||||
}
|
||||
}*/
|
||||
mCharacterControllerPanel.Draw(entity);
|
||||
}
|
||||
|
||||
void EditorSelectionPanel::DrawAddComponentMenu(Nuake::Entity entity)
|
||||
@@ -366,15 +118,18 @@ void EditorSelectionPanel::DrawAddComponentMenu(Nuake::Entity entity)
|
||||
|
||||
if (ImGui::BeginPopup("ComponentPopup"))
|
||||
{
|
||||
MenuItemComponent("Wren Script", Nuake::WrenScriptComponent);
|
||||
MenuItemComponent("Camera", Nuake::CameraComponent);
|
||||
MenuItemComponent("Light", Nuake::LightComponent);
|
||||
MenuItemComponent("Model", Nuake::ModelComponent);
|
||||
MenuItemComponent("Rigid body", Nuake::RigidBodyComponent);
|
||||
MenuItemComponent("Box collider", Nuake::BoxColliderComponent);
|
||||
MenuItemComponent("Sphere collider", Nuake::SphereColliderComponent);
|
||||
MenuItemComponent("Mesh collider", Nuake::MeshColliderComponent);
|
||||
MenuItemComponent("Quake map", Nuake::QuakeMapComponent);
|
||||
MenuItemComponent("Wren Script", Nuake::WrenScriptComponent)
|
||||
MenuItemComponent("Camera", Nuake::CameraComponent)
|
||||
MenuItemComponent("Light", Nuake::LightComponent)
|
||||
MenuItemComponent("Model", Nuake::ModelComponent)
|
||||
ImGui::Separator();
|
||||
MenuItemComponent("Character Controller", Nuake::CharacterControllerComponent)
|
||||
MenuItemComponent("Rigid body", Nuake::RigidBodyComponent)
|
||||
MenuItemComponent("Box collider", Nuake::BoxColliderComponent)
|
||||
MenuItemComponent("Sphere collider", Nuake::SphereColliderComponent)
|
||||
MenuItemComponent("Mesh collider", Nuake::MeshColliderComponent)
|
||||
ImGui::Separator();
|
||||
MenuItemComponent("Quake map", Nuake::QuakeMapComponent)
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
ImGui::Separator();
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "../ComponentsPanel/BoxColliderPanel.h"
|
||||
#include "../ComponentsPanel/SphereColliderPanel.h"
|
||||
#include "../ComponentsPanel/MeshColliderPanel.h"
|
||||
#include "../ComponentsPanel/CharacterControllerPanel.h"
|
||||
|
||||
class EditorSelectionPanel {
|
||||
private:
|
||||
@@ -28,6 +29,7 @@ private:
|
||||
BoxColliderPanel mBoxColliderPanel;
|
||||
SphereColliderPanel mSphereColliderPanel;
|
||||
MeshColliderPanel mMeshColliderPanel;
|
||||
CharacterControllerPanel mCharacterControllerPanel;
|
||||
|
||||
Ref<Nuake::File> currentFile;
|
||||
Ref<Nuake::Resource> selectedResource;
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Nuake
|
||||
Renderer2D::Init();
|
||||
Logger::Log("2D renderer initialized");
|
||||
|
||||
Logger::Log("Engine initialized succesfully!");
|
||||
Logger::Log("Engine initialized successfully!");
|
||||
}
|
||||
|
||||
void Engine::Tick()
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <Jolt/Physics/Body/BodyCreationSettings.h>
|
||||
#include <Jolt/Physics/Body/BodyActivationListener.h>
|
||||
#include <Jolt/Physics/Character/Character.h>
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
@@ -356,6 +357,12 @@ namespace Nuake
|
||||
|
||||
void DynamicWorld::AddCharacterController(Ref<CharacterController> cc)
|
||||
{
|
||||
auto settings = new JPH::CharacterSettings();
|
||||
settings->mMaxSlopeAngle = JPH::DegreesToRadians(45.0f);
|
||||
settings->mLayer = Layers::MOVING;
|
||||
settings->mFriction = 0.5f;
|
||||
|
||||
// Shape here
|
||||
}
|
||||
|
||||
RaycastResult DynamicWorld::Raycast(glm::vec3 from, glm::vec3 to)
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Nuake {
|
||||
class CharacterControllerComponent
|
||||
{
|
||||
public:
|
||||
Ref < Physics::CharacterController> CharacterController;
|
||||
Ref<Physics::CharacterController> CharacterController;
|
||||
|
||||
float Height = 1.0f;
|
||||
float Radius = 0.2f;
|
||||
|
||||
@@ -75,6 +75,13 @@ namespace Nuake
|
||||
}
|
||||
}
|
||||
|
||||
const auto characterControllerView = m_Scene->m_Registry.view<TransformComponent, CharacterControllerComponent>();
|
||||
for (auto e : characterControllerView)
|
||||
{
|
||||
auto [transformComponent, characterControllerComponent] = view.get<TransformComponent, RigidBodyComponent>(e);
|
||||
|
||||
}
|
||||
|
||||
//// character controllers
|
||||
//auto ccview = m_Scene->m_Registry.view<TransformComponent, CharacterControllerComponent>();
|
||||
//for (auto e : ccview)
|
||||
|
||||
Reference in New Issue
Block a user