Fix Everything #1
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -25,6 +25,3 @@
|
|||||||
[submodule "include/glad"]
|
[submodule "include/glad"]
|
||||||
path = include/glad
|
path = include/glad
|
||||||
url = https://github.com/Dav1dde/glad.git
|
url = https://github.com/Dav1dde/glad.git
|
||||||
[submodule "include/ImGuizmo"]
|
|
||||||
path = include/ImGuizmo
|
|
||||||
url = https://github.com/CedricGuillemet/ImGuizmo.git
|
|
||||||
|
@ -55,17 +55,6 @@ add_library(
|
|||||||
include/imgui/backends/imgui_impl_opengl3.cpp)
|
include/imgui/backends/imgui_impl_opengl3.cpp)
|
||||||
target_link_libraries(imgui glfw)
|
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)
|
add_executable(fred engine.cpp shader.c)
|
||||||
target_link_libraries(fred $<$<PLATFORM_ID:Linux>:-lm> glad_gl_core_33 glm glfw
|
target_link_libraries(fred $<$<PLATFORM_ID:Linux>:-lm> glad_gl_core_33 glm glfw
|
||||||
soil2 assimp imgui imGuizmo clog)
|
soil2 assimp imgui clog)
|
||||||
|
5
TODO.md
5
TODO.md
@ -1,5 +1,5 @@
|
|||||||
- [x] Destruct all at the end
|
- [x] Destruct all at the end
|
||||||
- [x] Make ImGuIZMO~~.quat~~ work
|
- [x] ~~Make ImGuIZMO.quat work~~ No longer required
|
||||||
- [ ] Finish modularization
|
- [ ] Finish modularization
|
||||||
- [ ] Make SOIL2 stop giving that smelly error message
|
- [ ] Make SOIL2 stop giving that smelly error message
|
||||||
Wtf is this warning?
|
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):
|
CMake Warning (dev) at include/SOIL2/CMakeLists.txt:67 (install):
|
||||||
Target soil2 has PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION.
|
Target soil2 has PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION.
|
||||||
This warning is for project developers. Use -Wno-dev to suppress it.
|
This warning is for project developers. Use -Wno-dev to suppress it.
|
||||||
- [ ] Overhaul asset debug screen
|
- [x] Overhaul asset debug screen
|
||||||
- [ ] Simple Lighting
|
- [ ] Simple Lighting
|
||||||
- [ ] Lightmapped Lighting
|
- [ ] Lightmapped Lighting
|
||||||
- [x] Deuteronomy is the coolest word ever
|
|
||||||
- [ ] Get ziggy with it
|
- [ ] Get ziggy with it
|
||||||
- [x] Implement Cameras
|
- [x] Implement Cameras
|
||||||
|
|
||||||
|
113
engine.cpp
113
engine.cpp
@ -1,3 +1,4 @@
|
|||||||
|
#include <cstddef>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -16,7 +17,6 @@
|
|||||||
#include <backends/imgui_impl_glfw.h>
|
#include <backends/imgui_impl_glfw.h>
|
||||||
#include <backends/imgui_impl_opengl3.h>
|
#include <backends/imgui_impl_opengl3.h>
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <ImGuizmo.h>
|
|
||||||
#include <clog/clog.h>
|
#include <clog/clog.h>
|
||||||
|
|
||||||
#include <SOIL2.h>
|
#include <SOIL2.h>
|
||||||
@ -230,6 +230,7 @@ class Scene {
|
|||||||
public:
|
public:
|
||||||
std::vector<Asset*> assets;
|
std::vector<Asset*> assets;
|
||||||
std::vector<Camera*> cameras;
|
std::vector<Camera*> cameras;
|
||||||
|
void (*renderCallback)() = NULL;
|
||||||
|
|
||||||
int activeCamera = 0;
|
int activeCamera = 0;
|
||||||
|
|
||||||
@ -239,10 +240,25 @@ public:
|
|||||||
void addCamera(Camera &camera) {
|
void addCamera(Camera &camera) {
|
||||||
cameras.push_back(&camera);
|
cameras.push_back(&camera);
|
||||||
}
|
}
|
||||||
|
void setRenderCallback(void (*callback)()) {
|
||||||
|
renderCallback = callback;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
GLFWwindow *window;
|
GLFWwindow *window;
|
||||||
GLuint vertexArrayID;
|
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() {
|
static bool shouldExit() {
|
||||||
return glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0;
|
return glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0;
|
||||||
@ -321,26 +337,30 @@ void destroy() {
|
|||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void imguiMat4Table(glm::mat4 matrix, const char *name) {
|
/*void imguiMat4Table(glm::mat4 matrix, const char *name) {*/
|
||||||
if (ImGui::BeginTable(name, 4)) {
|
/* if (ImGui::BeginTable(name, 4)) {*/
|
||||||
for (int i = 0; i < 4; i++) {
|
/* for (int i = 0; i < 4; i++) {*/
|
||||||
for (int j = 0; j < 4; j++) {
|
/* for (int j = 0; j < 4; j++) {*/
|
||||||
ImGui::TableNextColumn();
|
/* ImGui::TableNextColumn();*/
|
||||||
ImGui::Text("%f", matrix[i][j]);
|
/* ImGui::Text("%f", matrix[i][j]);*/
|
||||||
}
|
/* }*/
|
||||||
}
|
/* }*/
|
||||||
ImGui::EndTable();
|
/* ImGui::EndTable();*/
|
||||||
}
|
/* }*/
|
||||||
}
|
/*}*/
|
||||||
|
|
||||||
void render(Scene scene) {
|
void render(Scene scene) {
|
||||||
// Clear this mf
|
// Clear this mf
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
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_ImplOpenGL3_NewFrame();
|
||||||
ImGui_ImplGlfw_NewFrame();
|
ImGui_ImplGlfw_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
ImGuizmo::BeginFrame();
|
|
||||||
|
|
||||||
Camera *currentCamera = scene.cameras[scene.activeCamera];
|
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 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);
|
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++) {
|
for (int i = 0; i < scene.assets.size(); i++) {
|
||||||
Asset *currentAsset = scene.assets[i];
|
Asset *currentAsset = scene.assets[i];
|
||||||
|
|
||||||
@ -371,40 +384,12 @@ void render(Scene scene) {
|
|||||||
char assetName[] = "Asset: 00";
|
char assetName[] = "Asset: 00";
|
||||||
sprintf(assetName, "Asset: %d", i);
|
sprintf(assetName, "Asset: %d", i);
|
||||||
ImGui::Begin(assetName);
|
ImGui::Begin(assetName);
|
||||||
static ImGuizmo::OPERATION mCurrentGizmoOperation(ImGuizmo::ROTATE);
|
ImGui::Text("Frametime/Deltatime (ms): %f", deltaTime * 1000);
|
||||||
static ImGuizmo::MODE mCurrentGizmoMode(ImGuizmo::WORLD);
|
glm::vec3 rotationEuler = glm::degrees(eulerAngles(currentAsset->rotation));
|
||||||
if (ImGui::RadioButton("Translate",
|
ImGui::DragFloat3("Translate", (float*)¤tAsset->position, 0.01f);
|
||||||
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::DragFloat3("Rotate", (float*)&rotationEuler);
|
ImGui::DragFloat3("Rotate", (float*)&rotationEuler);
|
||||||
ImGui::DragFloat3("Scale", (float*)¤tAsset->scaling);
|
ImGui::DragFloat3("Scale", (float*)¤tAsset->scaling, 0.01f);
|
||||||
|
currentAsset->rotation = glm::quat(glm::radians(rotationEuler));
|
||||||
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::End();
|
ImGui::End();
|
||||||
|
|
||||||
glUniformMatrix4fv(currentAsset->matrixID, 1, GL_FALSE, &mvp[0][0]);
|
glUniformMatrix4fv(currentAsset->matrixID, 1, GL_FALSE, &mvp[0][0]);
|
||||||
@ -441,6 +426,10 @@ void render(Scene scene) {
|
|||||||
glDisableVertexAttribArray(2);
|
glDisableVertexAttribArray(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (scene.renderCallback != NULL) {
|
||||||
|
scene.renderCallback();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
|
||||||
@ -451,6 +440,15 @@ void render(Scene scene) {
|
|||||||
|
|
||||||
} // namespace fred
|
} // 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() {
|
int main() {
|
||||||
fred::initWindow();
|
fred::initWindow();
|
||||||
fred::Model coneModel("../models/model.obj");
|
fred::Model coneModel("../models/model.obj");
|
||||||
@ -469,12 +467,15 @@ int main() {
|
|||||||
scene.addAsset(cone);
|
scene.addAsset(cone);
|
||||||
scene.addAsset(coneTwo);
|
scene.addAsset(coneTwo);
|
||||||
|
|
||||||
|
scene.setRenderCallback(&renderCallback);
|
||||||
|
|
||||||
|
fred::setDeltaTimeMultiplier(20.0f);
|
||||||
|
|
||||||
while (fred::shouldExit()) {
|
while (fred::shouldExit()) {
|
||||||
//while (1) {
|
|
||||||
fred::render(scene);
|
fred::render(scene);
|
||||||
cone.position.x += 0.01;
|
cone.position.x += 0.01 * fred::getDeltaTime();
|
||||||
glm::vec3 eulerAngles = glm::eulerAngles(coneTwo.rotation);
|
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);
|
coneTwo.rotation = glm::quat(eulerAngles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1 +0,0 @@
|
|||||||
Subproject commit 6d588209f99b1324a608783d1f52faa518886c29
|
|
Loading…
Reference in New Issue
Block a user