diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 82efcf48..3d15e8d1 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -191,16 +191,8 @@ int main(int argc, char* argv[]) if (currentScene && !Nuake::Engine::IsPlayMode()) { - auto& gBuffer = currentScene->mSceneRenderer->GetGBuffer(); - auto& depthTexture = gBuffer.GetTexture(GL_DEPTH_ATTACHMENT); - - float nearZ = 0.1f; - float farZ = 1000.0f; - //gizmoDrawer.GetLineShader().SetUniformTex("u_Depth", depthTexture.get(), 3); - //gizmoDrawer.GetLineShader().SetUniformVec2("u_Resolution", depthTexture->GetSize()); glEnable(GL_LINE_SMOOTH); - glEnable(GL_BLEND); - glDepthRange(0.1f, 1000.0f); + if (editor.ShouldDrawAxis()) { //gizmoDrawer.DrawAxis(currentScene); diff --git a/Editor/src/ComponentsPanel/BoxColliderPanel.h b/Editor/src/ComponentsPanel/BoxColliderPanel.h index 05ba27e5..c210f651 100644 --- a/Editor/src/ComponentsPanel/BoxColliderPanel.h +++ b/Editor/src/ComponentsPanel/BoxColliderPanel.h @@ -1,10 +1,13 @@ #pragma once #include "ComponentPanel.h" -#include + #include +#include +#include #include -class BoxColliderPanel : ComponentPanel { +class BoxColliderPanel : ComponentPanel +{ public: BoxColliderPanel() {} @@ -28,7 +31,7 @@ public: component.Size.z = std::max(component.Size.z, 0.0001f); ImGui::TableNextColumn(); - ComponentTableReset(component.Size, glm::vec3(0.5f, 0.5f, 0.5f)); + ComponentTableReset(component.Size, Nuake::Vector3(0.5f, 0.5f, 0.5f)); } ImGui::TableNextColumn(); { diff --git a/Editor/src/ComponentsPanel/ScriptPanel.h b/Editor/src/ComponentsPanel/ScriptPanel.h index cad0f9d5..2a51065d 100644 --- a/Editor/src/ComponentsPanel/ScriptPanel.h +++ b/Editor/src/ComponentsPanel/ScriptPanel.h @@ -37,6 +37,16 @@ public: } component.Script = path; + + // Double click on file + if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)) + { + if(!component.Script.empty()) + { + Nuake::OS::OpenIn(component.mWrenScript->GetFile()->GetAbsolutePath()); + } + } + ImGui::TableNextColumn(); ComponentTableReset(component.Script, ""); diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 1731eddf..81af2da4 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -79,6 +79,7 @@ namespace Nuake { { ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); std::string name = ICON_FA_GAMEPAD + std::string(" Scene"); + if (ImGui::Begin(name.c_str())) { ImGui::PopStyleVar(); @@ -102,7 +103,7 @@ namespace Nuake { ImGui::SameLine(); - if (ImGui::Button(ICON_FA_STOP, ImVec2(30, 30)) || Input::IsKeyPressed(GLFW_KEY_F8)) + if ((ImGui::Button(ICON_FA_STOP, ImVec2(30, 30)) || Input::IsKeyPressed(GLFW_KEY_F8)) && Engine::IsPlayMode()) { Engine::ExitPlayMode(); @@ -242,8 +243,11 @@ namespace Nuake { } } - if (m_IsHoveringViewport && Input::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_1) && !ImGuizmo::IsUsing()) + m_IsViewportFocused = ImGui::IsWindowFocused(); + if (m_IsHoveringViewport && Input::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_2) && !ImGuizmo::IsUsing()) { + ImGui::FocusWindow(ImGui::GetCurrentWindow()); + const auto windowPosNuake = Vector2(windowPos.x, windowPos.y); auto& gbuffer = Engine::GetCurrentScene()->mSceneRenderer->GetGBuffer(); auto pixelPos = Input::GetMousePosition() - windowPosNuake; @@ -1513,7 +1517,11 @@ namespace Nuake { } auto& editorCam = Engine::GetCurrentScene()->m_EditorCamera; - editorCam->Update(ts, m_IsHoveringViewport); + + if (m_IsViewportFocused) + { + editorCam->Update(ts, m_IsHoveringViewport); + } const bool entityIsSelected = Selection.Type == EditorSelectionType::Entity && Selection.Entity.IsValid(); if (entityIsSelected && Input::IsKeyPressed(GLFW_KEY_F)) diff --git a/Editor/src/Windows/EditorInterface.h b/Editor/src/Windows/EditorInterface.h index 57f5ac94..740b3a1b 100644 --- a/Editor/src/Windows/EditorInterface.h +++ b/Editor/src/Windows/EditorInterface.h @@ -26,6 +26,8 @@ namespace Nuake bool m_DebugCollisions = true; bool m_ShowOverlay = true; bool m_IsHoveringViewport = false; + bool m_IsViewportFocused = false; + Vector2 m_ViewportPos = {0, 0}; Vector2 m_ViewportSize = {}; diff --git a/Editor/src/Windows/FileSystemUI.cpp b/Editor/src/Windows/FileSystemUI.cpp index 1a07bf03..d75531c3 100644 --- a/Editor/src/Windows/FileSystemUI.cpp +++ b/Editor/src/Windows/FileSystemUI.cpp @@ -44,8 +44,6 @@ const std::string TEMPLATE_SCRIPT_SECOND = R"( is ScriptableEntity { namespace Nuake { - - // TODO: add filetree in same panel void FileSystemUI::Draw() { @@ -61,16 +59,16 @@ namespace Nuake void FileSystemUI::EditorInterfaceDrawFiletree(Ref dir) { - ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth; + ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_FramePadding; //if (is_selected) - std::string icon = ICON_FA_FOLDER; if (m_CurrentDirectory == dir) base_flags |= ImGuiTreeNodeFlags_Selected; if (dir->Directories.size() <= 0) - base_flags = ImGuiTreeNodeFlags_Leaf; + base_flags |= ImGuiTreeNodeFlags_Leaf; - bool open = ImGui::TreeNodeEx(dir->name.c_str(), base_flags); + std::string icon = ICON_FA_FOLDER; + bool open = ImGui::TreeNodeEx((icon + " " + dir->name.c_str()).c_str(), base_flags); if (ImGui::IsItemClicked()) m_CurrentDirectory = dir; @@ -86,7 +84,7 @@ namespace Nuake void FileSystemUI::DrawDirectory(Ref directory) { - ImGui::PushFont(EditorInterface::bigIconFont); + ImGui::PushFont(FontManager::GetFont(Icons)); const char* icon = ICON_FA_FOLDER; const std::string id = ICON_FA_FOLDER + std::string("##") + directory->name; if (ImGui::Button(id.c_str(), ImVec2(100, 100))) @@ -324,20 +322,25 @@ namespace Nuake ImVec2 avail = ImGui::GetContentRegionAvail(); Splitter(true, 4.0f, &sz1, &sz2, 100, 8, avail.y); - if (ImGui::BeginChild("Tree browser", ImVec2(sz1, avail.y))) + ImVec4* colors = ImGui::GetStyle().Colors; + ImGui::PushStyleColor(ImGuiCol_ChildBg, colors[ImGuiCol_TitleBgCollapsed]); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 8); + if (ImGui::BeginChild("Tree browser", ImVec2(sz1, avail.y), true)) { - ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_DefaultOpen; + ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_FramePadding; bool is_selected = m_CurrentDirectory == FileSystem::RootDirectory; if (is_selected) base_flags |= ImGuiTreeNodeFlags_Selected; std::string icon = ICON_FA_FOLDER; - bool open = ImGui::TreeNodeEx((icon + " " + "Project files").c_str(), base_flags); + ImGui::PushFont(FontManager::GetFont(Bold)); + bool open = ImGui::TreeNodeEx("PROJECT", base_flags); if (ImGui::IsItemClicked()) { m_CurrentDirectory = FileSystem::RootDirectory; } + ImGui::PopFont(); if (open) { @@ -348,6 +351,8 @@ namespace Nuake } } + ImGui::PopStyleVar(); + ImGui::PopStyleColor(); ImGui::EndChild(); ImGui::SameLine(); @@ -368,31 +373,101 @@ namespace Nuake if (ImGui::BeginChild("Wrapper", avail)) { avail.y = 30; - if (ImGui::BeginChild("Path", avail)) + if (ImGui::BeginChild("Path", avail, true)) { - if (ImGui::Button("Refresh")) + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); + + const auto buttonSize = ImVec2(26, 26); + std::string refreshIcon = ICON_FA_SYNC_ALT; + if (ImGui::Button((refreshIcon).c_str(), buttonSize)) { RefreshFileBrowser(); } ImGui::SameLine(); + + const auto cursorStart = ImGui::GetCursorPosX(); + if (ImGui::Button((std::string(ICON_FA_ANGLE_LEFT)).c_str(), buttonSize)) + { + if (m_CurrentDirectory != FileSystem::RootDirectory) + { + m_CurrentDirectory = m_CurrentDirectory->Parent; + } + } + + ImGui::SameLine(); + + const auto cursorEnd = ImGui::GetCursorPosX(); + const auto buttonWidth = cursorEnd - cursorStart; + if (ImGui::Button((std::string(ICON_FA_ANGLE_RIGHT)).c_str(), buttonSize)) + { + // TODO + } + + const uint32_t numButtonAfterPathBrowser = 2; + ImGui::SameLine(); + + ImGui::PushStyleColor(ImGuiCol_ChildBg, colors[ImGuiCol_TitleBgCollapsed]); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4, 4)); + ImGui::BeginChild("pathBrowser", ImVec2(ImGui::GetContentRegionAvailWidth() - (numButtonAfterPathBrowser * buttonWidth) - 4.0, 24)); for (int i = paths.size() - 1; i > 0; i--) { if (i != paths.size()) ImGui::SameLine(); - if (ImGui::Button(paths[i]->name.c_str())) + std::string pathLabel; + if (i == paths.size() - 1) + { + pathLabel = "Project files"; + } + else + { + pathLabel = paths[i]->name; + } + + if (ImGui::Button(pathLabel.c_str())) + { m_CurrentDirectory = paths[i]; + } ImGui::SameLine(); ImGui::Text("/"); } + + ImGui::EndChild(); + ImGui::PopStyleVar(); + ImGui::PopStyleVar(); + ImGui::PopStyleColor(); + + ImGui::SameLine(); + + if (ImGui::Button((std::string(ICON_FA_FOLDER_OPEN)).c_str(), buttonSize)) + { + OS::ShowInFileExplorer(m_CurrentDirectory->fullPath); + } + + ImGui::SameLine(); + + if (ImGui::Button((std::string(ICON_FA_ELLIPSIS_V)).c_str(), buttonSize)) + { + // TODO + } + + ImGui::PopStyleColor(); // Button color } + ImGui::EndChild(); + ImDrawList* drawList = ImGui::GetWindowDrawList(); + ImGui::GetWindowDrawList()->AddLine(ImVec2(ImGui::GetCursorPosX(), ImGui::GetCursorPosY()), ImVec2(ImGui::GetContentRegionAvailWidth(), ImGui::GetCursorPosY()), IM_COL32(255, 0, 0, 255), 1.0f); + + ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(0, 0)); avail = ImGui::GetContentRegionAvail(); - if (ImGui::BeginChild("Content", avail)) + bool child = ImGui::BeginChild("Content", avail); + ImGui::PopStyleVar(); + if (child) { int width = avail.x; ImVec2 buttonSize = ImVec2(80, 80); diff --git a/Nuake/src/Core/Input.cpp b/Nuake/src/Core/Input.cpp index b5cd1db5..47e8e115 100644 --- a/Nuake/src/Core/Input.cpp +++ b/Nuake/src/Core/Input.cpp @@ -121,7 +121,6 @@ namespace Nuake { auto window = Window::Get()->GetHandle(); auto state = glfwGetMouseButton(window, button); - return state == GLFW_RELEASE && m_MouseButtons[button] == true; } diff --git a/Nuake/src/Core/Maths.cpp b/Nuake/src/Core/Maths.cpp index 884f4339..0b66c7a8 100644 --- a/Nuake/src/Core/Maths.cpp +++ b/Nuake/src/Core/Maths.cpp @@ -37,29 +37,12 @@ Quat Nuake::CreateFromAxisAngle(Vector3 axis, float angle) Quat Nuake::QuatFromEuler(float x, float y, float z) { - glm::quat pitchQuat = glm::angleAxis(Rad(x), glm::vec3(1.0f, 0.0f, 0.0f)); - glm::quat yawQuat = glm::angleAxis(Rad(y), glm::vec3(0.0f, 1.0f, 0.0f)); - glm::quat rollQuat = glm::angleAxis(Rad(z), glm::vec3(0.0f, 0.0f, -1.0f)); - glm::quat orientation = yawQuat * pitchQuat * rollQuat; + Quat pitchQuat = glm::angleAxis(Rad(x), Vector3(1.0f, 0.0f, 0.0f)); + Quat yawQuat = glm::angleAxis(Rad(y), Vector3(0.0f, 1.0f, 0.0f)); + Quat rollQuat = glm::angleAxis(Rad(z), Vector3(0.0f, 0.0f, -1.0f)); + Quat orientation = yawQuat * pitchQuat * rollQuat; return glm::normalize(orientation); - - return Quat(Vector3(Rad(x), Rad(y), Rad(z))); - - Quat q; - - float cr = cos(x * 0.5); - float sr = sin(x * 0.5); - float cp = cos(y * 0.5); - float sp = sin(y * 0.5); - float cy = cos(z * 0.5); - float sy = sin(z * 0.5); - - q.w = cr * cp * cy + sr * sp * sy; - q.x = sr * cp * cy - cr * sp * sy; - q.y = cr * sp * cy + sr * cp * sy; - q.z = cr * cp * sy - sr * sp * cy; - return q; } Vector3 Nuake::QuatToDirection(const Quat& quat) @@ -72,9 +55,9 @@ void Nuake::Decompose(const Matrix4& m, Vector3& pos, Quat& rot, Vector3& scale) pos = m[3]; for (int i = 0; i < 3; i++) scale[i] = glm::length(Vector3(m[i])); - const glm::mat3 rotMtx( - glm::vec3(m[0]) / scale[0], - glm::vec3(m[1]) / scale[1], - glm::vec3(m[2]) / scale[2]); + const Matrix3 rotMtx( + Vector3(m[0]) / scale[0], + Vector3(m[1]) / scale[1], + Vector3(m[2]) / scale[2]); rot = glm::quat_cast(rotMtx); } \ No newline at end of file diff --git a/Nuake/src/Core/Physics/CharacterController.cpp b/Nuake/src/Core/Physics/CharacterController.cpp index 93c8518c..ddcd671c 100644 --- a/Nuake/src/Core/Physics/CharacterController.cpp +++ b/Nuake/src/Core/Physics/CharacterController.cpp @@ -29,38 +29,6 @@ namespace Nuake { PhysicsManager::Get().GetWorld()->MoveAndSlideCharacterController(Owner, velocity); } - - void CharacterController::ParseGhostContacts() - { - - } - - void CharacterController::UpdatePosition() - { - - - } - - void CharacterController::UpdateVelocity() - { - // Decelerate - //m_manualVelocity -= m_manualVelocity * m_deceleration * m_pPhysicsWorld->GetScene()->m_frameTimer.GetTimeMultiplier(); - - if (m_hittingWall) - { - for (size_t i = 0, size = m_surfaceHitNormals.size(); i < size; i++) - { - // Cancel velocity across normal - glm::vec3 velInNormalDir(glm::reflect(m_manualVelocity, m_surfaceHitNormals[i])); - - // Apply correction - m_manualVelocity -= velInNormalDir * 1.05f; - } - - // Do not adjust rigid body velocity manually (so bodies can still be pushed by character) - return; - } - } } } diff --git a/Nuake/src/Core/Physics/CharacterController.h b/Nuake/src/Core/Physics/CharacterController.h index 9e20bb6b..b4bf99ab 100644 --- a/Nuake/src/Core/Physics/CharacterController.h +++ b/Nuake/src/Core/Physics/CharacterController.h @@ -29,8 +29,8 @@ namespace Nuake float m_bottomYOffset; float m_bottomRoundedRegionYOffset; - glm::vec3 m_manualVelocity; - std::vector m_surfaceHitNormals; + Vector3 m_manualVelocity; + std::vector m_surfaceHitNormals; CharacterController(const Ref& shape, float friction, float maxSlopeAngle); @@ -42,11 +42,6 @@ namespace Nuake { return IsOnGround; } - - private: - void ParseGhostContacts(); - void UpdatePosition(); - void UpdateVelocity(); }; } } diff --git a/Nuake/src/Core/Physics/DynamicWorld.cpp b/Nuake/src/Core/Physics/DynamicWorld.cpp index 927190d5..6b47a206 100644 --- a/Nuake/src/Core/Physics/DynamicWorld.cpp +++ b/Nuake/src/Core/Physics/DynamicWorld.cpp @@ -241,7 +241,7 @@ namespace Nuake } - void DynamicWorld::SetGravity(glm::vec3 g) + void DynamicWorld::SetGravity(const Vector3& gravity) { } @@ -323,16 +323,16 @@ namespace Nuake return false; } - RaycastResult DynamicWorld::Raycast(glm::vec3 from, glm::vec3 to) + RaycastResult DynamicWorld::Raycast(const Vector3& from, const Vector3& to) { - Vector3 localNorm = glm::vec3(0,0,0); + Vector3 localNorm = Vector3(0,0,0); //Logger::Log("normal: x:" + std::to_string(localNorm.x) + " y:" + std::to_string(localNorm.y )+ "z: " + std::to_string(localNorm.z)); // Map bullet result to dto. RaycastResult result{ - glm::vec3(0,0,0), - glm::vec3(0,0,0), + Vector3(0,0,0), + Vector3(0,0,0), localNorm }; diff --git a/Nuake/src/Core/Physics/DynamicWorld.h b/Nuake/src/Core/Physics/DynamicWorld.h index d568c957..bbb5c05c 100644 --- a/Nuake/src/Core/Physics/DynamicWorld.h +++ b/Nuake/src/Core/Physics/DynamicWorld.h @@ -52,7 +52,7 @@ namespace Nuake void DrawDebug(); - void SetGravity(glm::vec3 g); + void SetGravity(const Vector3& g); void AddRigidbody(Ref rb); void AddGhostbody(Ref gb); @@ -62,7 +62,7 @@ namespace Nuake void MoveAndSlideCharacterController(const Entity& entity, const Vector3& velocity); void AddForceToRigidBody(const Entity& entity, const Vector3& force); - RaycastResult Raycast(glm::vec3 from, glm::vec3 to); + RaycastResult Raycast(const Vector3& from, const Vector3& to); void StepSimulation(Timestep ts); void Clear(); diff --git a/Nuake/src/Core/Physics/PhysicsManager.cpp b/Nuake/src/Core/Physics/PhysicsManager.cpp index 7d5ebaf1..26aa6bac 100644 --- a/Nuake/src/Core/Physics/PhysicsManager.cpp +++ b/Nuake/src/Core/Physics/PhysicsManager.cpp @@ -37,7 +37,7 @@ namespace Nuake m_World->Clear(); } - RaycastResult PhysicsManager::Raycast(glm::vec3 from, glm::vec3 to) + RaycastResult PhysicsManager::Raycast(const Vector3& from, const Vector3& to) { return m_World->Raycast(from, to); } @@ -58,7 +58,7 @@ namespace Nuake JPH::RegisterTypes(); m_World = new Physics::DynamicWorld(); - m_World->SetGravity(glm::vec3(0, -3, 0)); + m_World->SetGravity(Vector3(0, -3, 0)); m_IsRunning = false; } diff --git a/Nuake/src/Core/Physics/PhysicsManager.h b/Nuake/src/Core/Physics/PhysicsManager.h index 4a854340..3934a07c 100644 --- a/Nuake/src/Core/Physics/PhysicsManager.h +++ b/Nuake/src/Core/Physics/PhysicsManager.h @@ -45,7 +45,7 @@ namespace Nuake void Reset(); - RaycastResult Raycast(glm::vec3 from, glm::vec3 to); + RaycastResult Raycast(const Vector3& from, const Vector3& to); void RegisterBody(Ref rb); void RegisterGhostBody(Ref rb); diff --git a/Nuake/src/Core/Physics/PhysicsShapes.cpp b/Nuake/src/Core/Physics/PhysicsShapes.cpp index 5009e910..00ce6da5 100644 --- a/Nuake/src/Core/Physics/PhysicsShapes.cpp +++ b/Nuake/src/Core/Physics/PhysicsShapes.cpp @@ -1,5 +1,4 @@ #include "PhysicsShapes.h" -#include "src/Rendering/Vertex.h" namespace Nuake { @@ -7,12 +6,11 @@ namespace Nuake { Box::Box() { - Size = glm::vec3(1); + Size = Vector3(1); m_Type = BOX; } - // Sphere - Box::Box(glm::vec3 size) + Box::Box(Vector3 size) { Size = size; m_Type = BOX; @@ -20,11 +18,10 @@ namespace Nuake Box::Box(float x, float y, float z) { - Size = glm::vec3(x, y, z); + Size = Vector3(x, y, z); m_Type = BOX; } - // Sphere Sphere::Sphere(float radius) { Radius = radius; diff --git a/Nuake/src/Core/Physics/PhysicsShapes.h b/Nuake/src/Core/Physics/PhysicsShapes.h index 49e3b167..859768dc 100644 --- a/Nuake/src/Core/Physics/PhysicsShapes.h +++ b/Nuake/src/Core/Physics/PhysicsShapes.h @@ -26,7 +26,7 @@ namespace Nuake Vector3 Size; public: Box(); - Box(glm::vec3 size); + Box(Vector3 size); Box(float x, float y, float z); Vector3 GetSize() const { return Size; } diff --git a/Nuake/src/Core/Physics/RaycastResult.h b/Nuake/src/Core/Physics/RaycastResult.h index 2da51a59..be12f90c 100644 --- a/Nuake/src/Core/Physics/RaycastResult.h +++ b/Nuake/src/Core/Physics/RaycastResult.h @@ -13,8 +13,8 @@ namespace Nuake // result object from raycast. struct RaycastResult { - glm::vec3 WorldPoint; - glm::vec3 LocalPoint; - glm::vec3 Normal; + Vector3 WorldPoint; + Vector3 LocalPoint; + Vector3 Normal; }; } diff --git a/Nuake/src/Core/Physics/Rigibody.h b/Nuake/src/Core/Physics/Rigibody.h index 4a9bc9e1..354dd84f 100644 --- a/Nuake/src/Core/Physics/Rigibody.h +++ b/Nuake/src/Core/Physics/Rigibody.h @@ -26,7 +26,7 @@ namespace Nuake RigidBody(); RigidBody(Vector3 position, Entity handle); - RigidBody(float mass, Vector3 position, Quat rotation, Matrix4 transform, Ref shape, Entity entity, glm::vec3 initialVel = glm::vec3(0, 0, 0)); + RigidBody(float mass, Vector3 position, Quat rotation, Matrix4 transform, Ref shape, Entity entity, Vector3 initialVel = Vector3(0, 0, 0)); void UpdateTransform(); diff --git a/Nuake/src/Core/Physics/Rigidbody.cpp b/Nuake/src/Core/Physics/Rigidbody.cpp index a8cbd7fc..464aa7b6 100644 --- a/Nuake/src/Core/Physics/Rigidbody.cpp +++ b/Nuake/src/Core/Physics/Rigidbody.cpp @@ -15,12 +15,12 @@ namespace Nuake } - RigidBody::RigidBody(glm::vec3 position, Entity handle) : _position(position) + RigidBody::RigidBody(Vector3 position, Entity handle) : _position(position) { } - RigidBody::RigidBody(float mass, Vector3 position, Quat rotation, Matrix4 transform, Ref shape, Entity entity, glm::vec3 initialVel) : + RigidBody::RigidBody(float mass, Vector3 position, Quat rotation, Matrix4 transform, Ref shape, Entity entity, Vector3 initialVel) : _position(position), _collisionShape(shape), _mass(mass), diff --git a/Nuake/src/Rendering/Camera.cpp b/Nuake/src/Rendering/Camera.cpp index f44b340c..7b60d972 100644 --- a/Nuake/src/Rendering/Camera.cpp +++ b/Nuake/src/Rendering/Camera.cpp @@ -10,7 +10,7 @@ namespace Nuake { - Camera::Camera(CAMERA_TYPE type, glm::vec3 position) + Camera::Camera(CAMERA_TYPE type, Vector3 position) { m_Type = PERSPECTIVE; Translation = position; @@ -25,7 +25,7 @@ namespace Nuake Camera::Camera() { m_Type = PERSPECTIVE; - Translation = glm::vec3(0, 0, 0); + Translation = Vector3(0, 0, 0); Direction = Vector3(0, 0, 1); Right = glm::normalize(glm::cross(Vector3(0, 1, 0), Direction)); Up = glm::cross(Direction, Right); @@ -83,7 +83,7 @@ namespace Nuake Matrix4 Camera::GetTransformRotation() { - return lookAt(glm::vec3(), Direction, Up); + return lookAt(Vector3(), Direction, Up); } bool Camera::BoxFrustumCheck(const AABB& aabb) diff --git a/Nuake/src/Rendering/Frustum.h b/Nuake/src/Rendering/Frustum.h index 01febbb9..22479bce 100644 --- a/Nuake/src/Rendering/Frustum.h +++ b/Nuake/src/Rendering/Frustum.h @@ -124,7 +124,7 @@ namespace Nuake { template inline Vector3 Frustum::intersection(const Vector3* crosses) const { - float D = glm::dot(glm::vec3(m_planes[a]), crosses[ij2k::k]); + float D = glm::dot(Vector3(m_planes[a]), crosses[ij2k::k]); Vector3 res = glm::mat3(crosses[ij2k::k], -crosses[ij2k::k], crosses[ij2k::k]) * Vector3(m_planes[a].w, m_planes[b].w, m_planes[c].w); return res * (-1.0f / D); diff --git a/Nuake/src/Rendering/Light.cpp b/Nuake/src/Rendering/Light.cpp index 84643404..b2091acc 100644 --- a/Nuake/src/Rendering/Light.cpp +++ b/Nuake/src/Rendering/Light.cpp @@ -87,17 +87,17 @@ namespace Nuake float radius = 0.0f; for (int i = 0; i < 8; i++) { - float distance = glm::length(glm::vec3(frustumCorners[i]) - frustumCenter); + float distance = glm::length(Vector3(frustumCorners[i]) - frustumCenter); radius = glm::max(radius, distance); } radius = std::ceil(radius * 16.0f) / 16.0f; - Vector3 maxExtents = glm::vec3(radius); + Vector3 maxExtents = Vector3(radius); Vector3 minExtents = -maxExtents; // Calculate the view and projection matrix Vector3 lightDir = -this->Direction; - Matrix4 lightViewMatrix = glm::lookAt(frustumCenter - lightDir * -minExtents.z, frustumCenter, glm::vec3(0.0f, 0.0f, 1.0f)); + Matrix4 lightViewMatrix = glm::lookAt(frustumCenter - lightDir * -minExtents.z, frustumCenter, Vector3(0.0f, 0.0f, 1.0f)); Matrix4 lightProjectionMatrix = glm::ortho(minExtents.x, maxExtents.x, minExtents.y, maxExtents.y, 0.0f + mCascadeNearPlaneOffset, maxExtents.z - minExtents.z + mCascadeFarPlaneOffset); // Offset to texel space to avoid shimmering ->(https://stackoverflow.com/questions/33499053/cascaded-shadow-map-shimmering) diff --git a/Nuake/src/Rendering/PostFX/SSAO.cpp b/Nuake/src/Rendering/PostFX/SSAO.cpp index 16624513..02a75aaf 100644 --- a/Nuake/src/Rendering/PostFX/SSAO.cpp +++ b/Nuake/src/Rendering/PostFX/SSAO.cpp @@ -44,10 +44,10 @@ namespace Nuake { std::uniform_real_distribution randomFloats(0.0, 1.0); // random floats between [0.0, 1.0] std::default_random_engine generator; - std::vector ssaoKernel; + std::vector ssaoKernel; for (unsigned int i = 0; i < 64; ++i) { - glm::vec3 sample( + Vector3 sample( randomFloats(generator) * 2.0 - 1.0, randomFloats(generator) * 2.0 - 1.0, randomFloats(generator) @@ -70,7 +70,7 @@ namespace Nuake for (unsigned int i = 0; i < 16; i++) { - glm::vec3 noise( + Vector3 noise( randomFloats(generator) * 2.0 - 1.0, randomFloats(generator) * 2.0 - 1.0, 0.0f); diff --git a/Nuake/src/Rendering/Renderer.cpp b/Nuake/src/Rendering/Renderer.cpp index bcd2d449..25f86f4f 100644 --- a/Nuake/src/Rendering/Renderer.cpp +++ b/Nuake/src/Rendering/Renderer.cpp @@ -209,7 +209,7 @@ namespace Nuake RenderCommand::DrawLines(0, 2); } - void Renderer::DrawDebugLine(glm::vec3 start, glm::vec3 end, glm::vec4 color) + void Renderer::DrawDebugLine(Vector3 start, Vector3 end, Vector3 color) { //m_DebugShader->Bind(); //m_DebugShader->SetUniform4f("u_Color", color.r, color.g, color.b, color.a); diff --git a/Nuake/src/Rendering/Renderer.h b/Nuake/src/Rendering/Renderer.h index 0b5de6ae..847e3b86 100644 --- a/Nuake/src/Rendering/Renderer.h +++ b/Nuake/src/Rendering/Renderer.h @@ -16,10 +16,6 @@ namespace Nuake }; const int MAX_LIGHT = 64; - //struct LightDataArray - //{ - // LightData Lights[MAX_LIGHT]; - //}; struct LightData { @@ -59,7 +55,6 @@ namespace Nuake static void Init(); static void LoadShaders(); - static void BeginScene(); static void SubmitMesh(Ref mesh, Matrix4 transform, const int32_t entityId = -1); static void SubmitCube(Matrix4 transform); static void Flush(Shader* shader, bool depthOnly = false); @@ -75,7 +70,7 @@ namespace Nuake // Debug static void DrawLine(Vector3 start, Vector3 end, Color color, Matrix4 transform = Matrix4()); - static void DrawDebugLine(glm::vec3 start, glm::vec3 end, glm::vec4 color); + static void DrawDebugLine(Vector3 start, Vector3 end, Vector3 color); static void DrawCube(TransformComponent transform, glm::vec4 color); static void DrawSphere(TransformComponent transform, glm::vec4 color); static void DrawQuad(Matrix4 transform = Matrix4()); diff --git a/Nuake/src/Rendering/SceneRenderer.cpp b/Nuake/src/Rendering/SceneRenderer.cpp index 6bd30a64..7d4b2512 100644 --- a/Nuake/src/Rendering/SceneRenderer.cpp +++ b/Nuake/src/Rendering/SceneRenderer.cpp @@ -4,7 +4,8 @@ #include #include -namespace Nuake { +namespace Nuake +{ void SceneRenderer::Init() { const auto defaultResolution = Vector2(1920, 1080); diff --git a/Nuake/src/Rendering/Textures/Material.cpp b/Nuake/src/Rendering/Textures/Material.cpp index f68785cd..65c14827 100644 --- a/Nuake/src/Rendering/Textures/Material.cpp +++ b/Nuake/src/Rendering/Textures/Material.cpp @@ -56,7 +56,7 @@ namespace Nuake InitDefaultTextures(); } - Material::Material(const glm::vec3 albedoColor) + Material::Material(const Vector3 albedoColor) { InitDefaultTextures(); InitUniformBuffer(); diff --git a/Nuake/src/Rendering/Textures/Material.h b/Nuake/src/Rendering/Textures/Material.h index 9dd2e269..2d9986fc 100644 --- a/Nuake/src/Rendering/Textures/Material.h +++ b/Nuake/src/Rendering/Textures/Material.h @@ -73,7 +73,7 @@ namespace Nuake Material(); Material(const std::string albedo); Material(Ref texture) { m_Albedo = texture; } - Material(const glm::vec3 albedoColor); + Material(const Vector3 albedoColor); ~Material(); void InitDefaultTextures(); diff --git a/Nuake/src/Scene/Components/BoxCollider.h b/Nuake/src/Scene/Components/BoxCollider.h index 125452b3..4cc88f8e 100644 --- a/Nuake/src/Scene/Components/BoxCollider.h +++ b/Nuake/src/Scene/Components/BoxCollider.h @@ -7,7 +7,7 @@ namespace Nuake { { public: Ref Box; - glm::vec3 Size = glm::vec3(0.5f, 0.5f, 0.5f); + Vector3 Size = Vector3(0.5f, 0.5f, 0.5f); bool IsTrigger = false; json Serialize(); diff --git a/Nuake/src/Scene/Components/LightComponent.cpp b/Nuake/src/Scene/Components/LightComponent.cpp index 9cd8a776..42b69d47 100644 --- a/Nuake/src/Scene/Components/LightComponent.cpp +++ b/Nuake/src/Scene/Components/LightComponent.cpp @@ -7,25 +7,13 @@ #include "src/Core/Core.h" #include -namespace Nuake { - LightComponent::LightComponent() +namespace Nuake +{ + LightComponent::LightComponent() : + Color(1, 1, 1), + Strength(10.0f), + Direction(0, 1, 0) { - Color = glm::vec3(1, 1, 1); - Strength = 10.0f; - Direction = glm::vec3(0, -1, 0); - - - //m_Framebuffers = std::vector>(); - //mViewProjections = std::vector(); - //mCascadeSplitDepth = std::vector(); - //mCascadeSplits = std::vector(); - // Framebuffer used for shadow mapping. - - //for (int i = 0; i < 4; i++) - //{ - // m_Framebuffers[i] = CreateRef(false, glm::vec2(4096, 4096)); - // m_Framebuffers[i]->SetTexture(CreateRef(glm::vec2(4096, 4096), GL_DEPTH_COMPONENT), GL_DEPTH_ATTACHMENT); - //} } void LightComponent::SetCastShadows(bool toggle) @@ -42,7 +30,8 @@ namespace Nuake { } } - else { + else + { for (int i = 0; i < CSM_AMOUNT; i++) { m_Framebuffers[i] = nullptr; @@ -50,92 +39,13 @@ namespace Nuake { } } - glm::mat4 LightComponent::GetProjection() + Matrix4 LightComponent::GetProjection() { return glm::ortho(-25.0f, 25.0f, -25.0f, 25.0f, -25.0f, 25.0f); } - void LightComponent::SetDirection(glm::vec3 dir) + Vector3 LightComponent::GetDirection() { - - } - - glm::vec3 LightComponent::GetDirection() - { - //glm::mat4 start = glm::mat4(1.0f); - //glm::vec3 defaultDirection(0, 0, 1); // forward - // - //start = glm::rotate(start, glm::radians(Direction.x), glm::vec3(1, 0, 0)); - //start = glm::rotate(start, glm::radians(Direction.y), glm::vec3(0, 1, 0)); - //start = glm::rotate(start, glm::radians(Direction.z), glm::vec3(0, 0, 1)); - - //return glm::vec3(start * glm::vec4(defaultDirection, 1.0f)); return glm::normalize(Direction); } - - - void LightComponent::BeginDrawShadow() - { - Renderer::m_ShadowmapShader->Bind(); - //m_Framebuffer->Bind(); - - // Render scene... - - } - - void LightComponent::EndDrawShadow() - { - //m_Framebuffer->Unbind(); - } - - void LightComponent::DrawShadow() - { - if (Type != Directional) - return; - - Renderer::m_ShadowmapShader->Bind(); - } - - void LightComponent::DrawEditor() { - ImGui::TextColored(ImGui::GetStyleColorVec4(1), "Light properties"); - ImGui::ColorEdit3("Light Color", &Color.r); - ImGui::SliderFloat("Strength", &Strength, 0.0f, 50.0f); - bool before = CastShadows; - ImGui::Checkbox("Cast shadows", &CastShadows); - - if (CastShadows && before == false) - SetCastShadows(true); - - const char* types[] = { "Directional", "Point", "Spot" }; - static const char* current_item = types[Type]; - - if (ImGui::BeginCombo("Type", current_item)) // The second parameter is the label previewed before opening the combo. - { - for (int n = 0; n < IM_ARRAYSIZE(types); n++) - { - bool is_selected = (current_item == types[n]); // You can store your selection however you want, outside or inside your objects - if (ImGui::Selectable(types[n], is_selected)) { - current_item = types[n]; - Type = (LightType)n; - } - if (is_selected) - ImGui::SetItemDefaultFocus(); // You may set the initial focus when opening the combo (scrolling + for keyboard navigation support) - } - ImGui::EndCombo(); - } - - if (Type == Directional) { - ImGui::Checkbox("Sync with sky", &SyncDirectionWithSky); - ImGui::Checkbox("Volumetric?", &IsVolumetric); - ImGuiHelper::DrawVec3("Direction", &Direction); - } - - //if (Type == 1) { - // ImGui::SliderFloat("Attenuation", &Attenuation, 0.0f, 1.0f); - // ImGui::SliderFloat("Linear attenuation", &LinearAttenuation, 0.0f, 1.0f); - // ImGui::SliderFloat("Quadratic attenuation", &QuadraticAttenuation, 0.0f, 1.0f); - //} - - //Direction = glm::normalize(Direction); - } } diff --git a/Nuake/src/Scene/Components/LightComponent.h b/Nuake/src/Scene/Components/LightComponent.h index 32c4a110..321fb07e 100644 --- a/Nuake/src/Scene/Components/LightComponent.h +++ b/Nuake/src/Scene/Components/LightComponent.h @@ -21,41 +21,28 @@ namespace Nuake { public: LightType Type = Point; - glm::vec3 Direction = glm::vec3(0, -1, 0); - glm::vec3 Color; + Vector3 Direction; + Vector3 Color; + bool IsVolumetric = false; float Strength; - bool SyncDirectionWithSky = false; - Ref m_Framebuffer; + bool SyncDirectionWithSky = false; bool CastShadows = false; Ref m_Framebuffers[CSM_AMOUNT]; - glm::mat4 mViewProjections[CSM_AMOUNT]; + Matrix4 mViewProjections[CSM_AMOUNT]; float mCascadeSplitDepth[CSM_AMOUNT]; + float mCascadeSplits[CSM_AMOUNT]; + public: LightComponent(); + ~LightComponent() = default; void SetCastShadows(bool toggle); - glm::mat4 GetProjection(); - - glm::mat4 GetLightTransform(); - void SetDirection(glm::vec3 dir); - glm::vec3 GetDirection(); - - void BeginDrawShadow(); - - void EndDrawShadow(); - void DrawShadow(); - - void Draw(TransformComponent transformComponent, Ref cam); - void DrawDeferred(TransformComponent transformComponent, Camera* cam); - void DrawEditor(); - - void SetType(LightType type); - - float mCascadeSplits[CSM_AMOUNT]; + Matrix4 GetProjection(); + Vector3 GetDirection(); void CalculateViewProjection(glm::mat4& view, const glm::mat4& projection) { diff --git a/Nuake/src/Scene/Components/WrenScriptComponent.h b/Nuake/src/Scene/Components/WrenScriptComponent.h index d5f069e2..57bbf47c 100644 --- a/Nuake/src/Scene/Components/WrenScriptComponent.h +++ b/Nuake/src/Scene/Components/WrenScriptComponent.h @@ -39,7 +39,10 @@ namespace Nuake if (j.contains("Script")) { Script = j["Script"]; - LoadScript(Script); + if(!Script.empty()) + { + LoadScript(Script); + } } if (j.contains("mModule")) diff --git a/Nuake/src/Scene/EditorCamera.cpp b/Nuake/src/Scene/EditorCamera.cpp index 9d80a962..79d0c177 100644 --- a/Nuake/src/Scene/EditorCamera.cpp +++ b/Nuake/src/Scene/EditorCamera.cpp @@ -164,6 +164,8 @@ namespace Nuake mouseLastX = x; mouseLastY = y; controlled = true; + + SetDirection(glm::normalize(Direction)); } else if (Input::YScroll != 0) { @@ -171,6 +173,7 @@ namespace Nuake Input::YScroll = 0.0f; } + SetDirection(glm::normalize(Direction)); mouseLastX = x; mouseLastY = y; } @@ -192,7 +195,8 @@ namespace Nuake Direction.y = sin(glm::radians(Pitch)); Direction.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch)); Direction = glm::normalize(Direction); - Right = glm::normalize(glm::cross(Up, Direction)); + SetDirection(Direction); + } void EditorCamera::SetYaw(float yaw) diff --git a/Nuake/src/Scripting/Modules/SceneModule.h b/Nuake/src/Scripting/Modules/SceneModule.h index c0297bbc..22947c43 100644 --- a/Nuake/src/Scripting/Modules/SceneModule.h +++ b/Nuake/src/Scripting/Modules/SceneModule.h @@ -109,7 +109,6 @@ namespace Nuake { prefabComponent.PrefabInstance = Prefab::New(prefabPath); wrenSetSlotDouble(vm, 0, newEntity.GetHandle()); - return; } static void EntityHasComponent(WrenVM* vm) diff --git a/Nuake/src/Window.cpp b/Nuake/src/Window.cpp index 29b92506..62ce9665 100644 --- a/Nuake/src/Window.cpp +++ b/Nuake/src/Window.cpp @@ -236,11 +236,14 @@ namespace Nuake ImGui::StyleColorsDark(); ImGuiStyle& s = ImGui::GetStyle(); + s.WindowMenuButtonPosition = ImGuiDir_None; s.FrameRounding = 2.0f; s.GrabRounding = 2.0f; s.CellPadding = ImVec2(8, 8); - s.WindowPadding = ImVec2(8, 8); + s.WindowPadding = ImVec2(2, 2); s.ScrollbarRounding = 9.0f; + s.ScrollbarSize = 15.0f; + s.GrabMinSize = 32.0f; s.TabRounding = 0; s.WindowRounding = 0; s.ChildRounding = 0; @@ -251,6 +254,7 @@ namespace Nuake s.ItemInnerSpacing = ImVec2(4, 4); s.TabRounding = 4.0f; s.WindowBorderSize = 0.0f; + s.IndentSpacing = 12.0f; s.ChildBorderSize = 0.0f; ImVec4* colors = ImGui::GetStyle().Colors; @@ -268,7 +272,7 @@ namespace Nuake colors[ImGuiCol_TitleBgActive] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f); colors[ImGuiCol_MenuBarBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f); - colors[ImGuiCol_ScrollbarBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f); + colors[ImGuiCol_ScrollbarBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.00f); colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.34f, 0.34f, 0.34f, 1.00f); colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.29f, 0.29f, 0.29f, 1.00f); colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);