From 752ea5ad4a6edcd88c9024382ea4e3640300d0fc Mon Sep 17 00:00:00 2001 From: illegitimate-egg Date: Sat, 12 Oct 2024 09:41:32 +0100 Subject: [PATCH] Stuff --- .gitmodules | 3 -- CMakeLists.txt | 13 +----- TODO.md | 5 +-- engine.cpp | 113 ++++++++++++++++++++++++----------------------- include/ImGuizmo | 1 - 5 files changed, 60 insertions(+), 75 deletions(-) delete mode 160000 include/ImGuizmo diff --git a/.gitmodules b/.gitmodules index fc7323e..9f7a356 100644 --- a/.gitmodules +++ b/.gitmodules @@ -25,6 +25,3 @@ [submodule "include/glad"] path = include/glad url = https://github.com/Dav1dde/glad.git -[submodule "include/ImGuizmo"] - path = include/ImGuizmo - url = https://github.com/CedricGuillemet/ImGuizmo.git diff --git a/CMakeLists.txt b/CMakeLists.txt index c02a030..6563176 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,17 +55,6 @@ add_library( include/imgui/backends/imgui_impl_opengl3.cpp) target_link_libraries(imgui glfw) -include_directories(include/ImGuizmo) -add_library( - imGuizmo STATIC - include/ImGuizmo/GraphEditor.cpp - include/ImGuizmo/ImCurveEdit.cpp - include/ImGuizmo/ImGradient.cpp - include/ImGuizmo/ImGuizmo.cpp - include/ImGuizmo/ImSequencer.cpp -) -target_link_libraries(imGuizmo imgui) - add_executable(fred engine.cpp shader.c) target_link_libraries(fred $<$:-lm> glad_gl_core_33 glm glfw - soil2 assimp imgui imGuizmo clog) + soil2 assimp imgui clog) diff --git a/TODO.md b/TODO.md index d5091f8..bc5cb14 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,5 @@ - [x] Destruct all at the end -- [x] Make ImGuIZMO~~.quat~~ work +- [x] ~~Make ImGuIZMO.quat work~~ No longer required - [ ] Finish modularization - [ ] Make SOIL2 stop giving that smelly error message Wtf is this warning? @@ -15,10 +15,9 @@ This warning is for project developers. Use -Wno-dev to suppress it. CMake Warning (dev) at include/SOIL2/CMakeLists.txt:67 (install): Target soil2 has PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION. This warning is for project developers. Use -Wno-dev to suppress it. -- [ ] Overhaul asset debug screen +- [x] Overhaul asset debug screen - [ ] Simple Lighting - [ ] Lightmapped Lighting -- [x] Deuteronomy is the coolest word ever - [ ] Get ziggy with it - [x] Implement Cameras diff --git a/engine.cpp b/engine.cpp index 3ead84c..949666c 100644 --- a/engine.cpp +++ b/engine.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -16,7 +17,6 @@ #include #include #include -#include #include #include @@ -230,6 +230,7 @@ class Scene { public: std::vector assets; std::vector cameras; + void (*renderCallback)() = NULL; int activeCamera = 0; @@ -239,10 +240,25 @@ public: void addCamera(Camera &camera) { cameras.push_back(&camera); } + void setRenderCallback(void (*callback)()) { + renderCallback = callback; + } }; GLFWwindow *window; GLuint vertexArrayID; +float deltaTime = 0; +float deltaTimeMultiplier = 1.0f; + +void setDeltaTimeMultiplier(float mult) { + deltaTimeMultiplier = mult; +} +float getDeltaTime() { + return deltaTime * deltaTimeMultiplier; +} +float getUnscaledDeltaTime() { + return deltaTime; +} static bool shouldExit() { return glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0; @@ -321,26 +337,30 @@ void destroy() { glfwTerminate(); } -void imguiMat4Table(glm::mat4 matrix, const char *name) { - if (ImGui::BeginTable(name, 4)) { - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - ImGui::TableNextColumn(); - ImGui::Text("%f", matrix[i][j]); - } - } - ImGui::EndTable(); - } -} +/*void imguiMat4Table(glm::mat4 matrix, const char *name) {*/ +/* if (ImGui::BeginTable(name, 4)) {*/ +/* for (int i = 0; i < 4; i++) {*/ +/* for (int j = 0; j < 4; j++) {*/ +/* ImGui::TableNextColumn();*/ +/* ImGui::Text("%f", matrix[i][j]);*/ +/* }*/ +/* }*/ +/* ImGui::EndTable();*/ +/* }*/ +/*}*/ void render(Scene scene) { // Clear this mf glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + static double lastTime = glfwGetTime(); + double currentTime = glfwGetTime(); + + deltaTime = float(currentTime - lastTime); + lastTime = currentTime; ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); - ImGuizmo::BeginFrame(); Camera *currentCamera = scene.cameras[scene.activeCamera]; @@ -348,13 +368,6 @@ void render(Scene scene) { glm::mat4 viewMatrix = glm::inverse(glm::translate(glm::mat4(1), currentCamera->position) * (mat4_cast(currentCamera->rotation))); glm::mat4 projectionMatrix = glm::perspective(currentCamera->fov, (float)WIDTH / (float)HEIGHT, currentCamera->nearPlane, currentCamera->farPlane); - ImGui::Begin("Matrix Debug"); - ImGui::Text("Computed View Matrix"); - imguiMat4Table(viewMatrix, "cvm"); - ImGui::Text("Computed Projection Matrix"); - imguiMat4Table(projectionMatrix, "cpm"); - ImGui::End(); - for (int i = 0; i < scene.assets.size(); i++) { Asset *currentAsset = scene.assets[i]; @@ -371,40 +384,12 @@ void render(Scene scene) { char assetName[] = "Asset: 00"; sprintf(assetName, "Asset: %d", i); ImGui::Begin(assetName); - static ImGuizmo::OPERATION mCurrentGizmoOperation(ImGuizmo::ROTATE); - static ImGuizmo::MODE mCurrentGizmoMode(ImGuizmo::WORLD); - if (ImGui::RadioButton("Translate", - mCurrentGizmoOperation == ImGuizmo::TRANSLATE)) { - mCurrentGizmoOperation = ImGuizmo::TRANSLATE; - } - ImGui::SameLine(); - if (ImGui::RadioButton("Rotate", - mCurrentGizmoOperation == ImGuizmo::TRANSLATE)) { - mCurrentGizmoOperation = ImGuizmo::ROTATE; - } - ImGui::SameLine(); - if (ImGui::RadioButton("Scale", - mCurrentGizmoOperation == ImGuizmo::TRANSLATE)) { - mCurrentGizmoOperation = ImGuizmo::SCALE; - } - glm::vec3 rotationEuler = eulerAngles(currentAsset->rotation); - ImGui::DragFloat3("Translate", (float*)¤tAsset->position); + ImGui::Text("Frametime/Deltatime (ms): %f", deltaTime * 1000); + glm::vec3 rotationEuler = glm::degrees(eulerAngles(currentAsset->rotation)); + ImGui::DragFloat3("Translate", (float*)¤tAsset->position, 0.01f); ImGui::DragFloat3("Rotate", (float*)&rotationEuler); - ImGui::DragFloat3("Scale", (float*)¤tAsset->scaling); - - if (ImGui::IsWindowFocused()) { - ImGuiIO &io = ImGui::GetIO(); - ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y); - ImGuizmo::Manipulate((const float *)&viewMatrix, - (const float *)&projectionMatrix, - mCurrentGizmoOperation, mCurrentGizmoMode, - (float *)&modelMatrix, NULL, NULL); - ImGuizmo::DecomposeMatrixToComponents( - (const float *)&modelMatrix, (float *)¤tAsset->position, - (float *)&rotationEuler, (float *)¤tAsset->scaling); - //currentAsset->rotation = glm::quat(rotationEuler); - } - + ImGui::DragFloat3("Scale", (float*)¤tAsset->scaling, 0.01f); + currentAsset->rotation = glm::quat(glm::radians(rotationEuler)); ImGui::End(); glUniformMatrix4fv(currentAsset->matrixID, 1, GL_FALSE, &mvp[0][0]); @@ -441,6 +426,10 @@ void render(Scene scene) { glDisableVertexAttribArray(2); } + if (scene.renderCallback != NULL) { + scene.renderCallback(); + } + ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); @@ -451,6 +440,15 @@ void render(Scene scene) { } // namespace fred +// Userspace ================================================================ // + +void renderCallback() { + ImGui::Begin("User Render Callback"); + ImGui::Text("Frametime (ms): %f", fred::getUnscaledDeltaTime() * 1000); + ImGui::Text("FPS: %f", 1/fred::getUnscaledDeltaTime()); + ImGui::End(); +} + int main() { fred::initWindow(); fred::Model coneModel("../models/model.obj"); @@ -469,12 +467,15 @@ int main() { scene.addAsset(cone); scene.addAsset(coneTwo); + scene.setRenderCallback(&renderCallback); + + fred::setDeltaTimeMultiplier(20.0f); + while (fred::shouldExit()) { - //while (1) { fred::render(scene); - cone.position.x += 0.01; + cone.position.x += 0.01 * fred::getDeltaTime(); glm::vec3 eulerAngles = glm::eulerAngles(coneTwo.rotation); - eulerAngles.x += glm::radians(1.0f); + eulerAngles.x += glm::radians(1.0f) * fred::getDeltaTime(); coneTwo.rotation = glm::quat(eulerAngles); } diff --git a/include/ImGuizmo b/include/ImGuizmo deleted file mode 160000 index 6d58820..0000000 --- a/include/ImGuizmo +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6d588209f99b1324a608783d1f52faa518886c29