Merge branch 'Dev'
This commit is contained in:
commit
7ffcaecbac
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,4 +2,3 @@ build/
|
|||||||
*.exe
|
*.exe
|
||||||
*.o
|
*.o
|
||||||
.vscode/
|
.vscode/
|
||||||
*.ini
|
|
||||||
|
59
imgui.ini
Normal file
59
imgui.ini
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
[Window][DockSpace]
|
||||||
|
Pos=0,0
|
||||||
|
Size=1920,1177
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
|
[Window][Debug##Default]
|
||||||
|
Pos=60,60
|
||||||
|
Size=400,400
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
|
[Window][Inspector]
|
||||||
|
Pos=1588,27
|
||||||
|
Size=324,772
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000005,0
|
||||||
|
|
||||||
|
[Window][OpenGL Output]
|
||||||
|
Pos=375,27
|
||||||
|
Size=1211,770
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000003,0
|
||||||
|
|
||||||
|
[Window][Performance]
|
||||||
|
Pos=1588,801
|
||||||
|
Size=324,368
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000006,0
|
||||||
|
|
||||||
|
[Window][Logger]
|
||||||
|
Pos=375,799
|
||||||
|
Size=1211,370
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000004,0
|
||||||
|
|
||||||
|
[Window][Object Selector]
|
||||||
|
Pos=8,27
|
||||||
|
Size=357,1142
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000007,0
|
||||||
|
|
||||||
|
[Window][Scene Window]
|
||||||
|
Pos=8,27
|
||||||
|
Size=365,1142
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000009,0
|
||||||
|
|
||||||
|
[Docking][Data]
|
||||||
|
DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=8,27 Size=1904,1142 Split=X Selected=0xF7365A5A
|
||||||
|
DockNode ID=0x00000009 Parent=0x14621557 SizeRef=365,1142 Selected=0x3DC5AC3F
|
||||||
|
DockNode ID=0x0000000A Parent=0x14621557 SizeRef=1537,1142 Split=X
|
||||||
|
DockNode ID=0x00000007 Parent=0x0000000A SizeRef=357,1142 Selected=0x7737E8B2
|
||||||
|
DockNode ID=0x00000008 Parent=0x0000000A SizeRef=1545,1142 Split=X
|
||||||
|
DockNode ID=0x00000001 Parent=0x00000008 SizeRef=1211,1142 Split=Y Selected=0xF7365A5A
|
||||||
|
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=1578,770 CentralNode=1 HiddenTabBar=1 Selected=0xF7365A5A
|
||||||
|
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=1578,370 HiddenTabBar=1 Selected=0x9DD4E196
|
||||||
|
DockNode ID=0x00000002 Parent=0x00000008 SizeRef=324,1142 Split=Y Selected=0x36DC96AB
|
||||||
|
DockNode ID=0x00000005 Parent=0x00000002 SizeRef=324,772 HiddenTabBar=1 Selected=0x36DC96AB
|
||||||
|
DockNode ID=0x00000006 Parent=0x00000002 SizeRef=324,368 HiddenTabBar=1 Selected=0x726D8899
|
||||||
|
|
127
src/Engine.cpp
127
src/Engine.cpp
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
|
|
||||||
#define VSync 0
|
#define VSync 1
|
||||||
|
|
||||||
#include "Engine.h"
|
#include "Engine.h"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@ -21,6 +21,17 @@
|
|||||||
#include "Windows/PerformanceWindow.h"
|
#include "Windows/PerformanceWindow.h"
|
||||||
#include "Windows/LoggerWindow.h"
|
#include "Windows/LoggerWindow.h"
|
||||||
#include "Windows/InspectorWindow.h"
|
#include "Windows/InspectorWindow.h"
|
||||||
|
#include "Windows/SceneWindow.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define YAML_CPP_STATIC_DEFINE
|
||||||
|
#include <yaml-cpp/yaml.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "TestModel.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -31,7 +42,11 @@ AssetManager g_AssetManager;
|
|||||||
|
|
||||||
LoggerWindow *g_LoggerWindow;
|
LoggerWindow *g_LoggerWindow;
|
||||||
|
|
||||||
std::vector<GameObject> m_GameObjects;
|
std::vector<GameObject> g_GameObjects;
|
||||||
|
|
||||||
|
GameObject* g_SelectedObject; // Pointer to the currently selected object
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool MyEngine::Init(int width, int height, const std::string& title)
|
bool MyEngine::Init(int width, int height, const std::string& title)
|
||||||
@ -95,7 +110,7 @@ bool MyEngine::Init(int width, int height, const std::string& title)
|
|||||||
m_PerformanceWindow = std::make_unique<PerformanceWindow>();
|
m_PerformanceWindow = std::make_unique<PerformanceWindow>();
|
||||||
m_LoggerWindow = std::make_unique<LoggerWindow>();
|
m_LoggerWindow = std::make_unique<LoggerWindow>();
|
||||||
m_InspectorWindow = std::make_unique<InspectorWindow>();
|
m_InspectorWindow = std::make_unique<InspectorWindow>();
|
||||||
|
m_SceneWindow = std::make_unique<SceneWindow>();
|
||||||
|
|
||||||
|
|
||||||
// Some initial logs
|
// Some initial logs
|
||||||
@ -111,104 +126,6 @@ bool MyEngine::Init(int width, int height, const std::string& title)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint CreateCubeVAO()
|
|
||||||
{
|
|
||||||
// Define cube vertices (Position + UVs)
|
|
||||||
static float g_CubeVertices[] =
|
|
||||||
{
|
|
||||||
// Front face
|
|
||||||
-1.f, -1.f, 1.f, 0.f, 0.f,
|
|
||||||
1.f, -1.f, 1.f, 1.f, 0.f,
|
|
||||||
1.f, 1.f, 1.f, 1.f, 1.f,
|
|
||||||
-1.f, 1.f, 1.f, 0.f, 1.f,
|
|
||||||
|
|
||||||
// Back face
|
|
||||||
-1.f, -1.f, -1.f, 1.f, 0.f,
|
|
||||||
1.f, -1.f, -1.f, 0.f, 0.f,
|
|
||||||
1.f, 1.f, -1.f, 0.f, 1.f,
|
|
||||||
-1.f, 1.f, -1.f, 1.f, 1.f,
|
|
||||||
|
|
||||||
// Left face
|
|
||||||
-1.f, -1.f, -1.f, 0.f, 0.f,
|
|
||||||
-1.f, -1.f, 1.f, 1.f, 0.f,
|
|
||||||
-1.f, 1.f, 1.f, 1.f, 1.f,
|
|
||||||
-1.f, 1.f, -1.f, 0.f, 1.f,
|
|
||||||
|
|
||||||
// Right face
|
|
||||||
1.f, -1.f, -1.f, 1.f, 0.f,
|
|
||||||
1.f, -1.f, 1.f, 0.f, 0.f,
|
|
||||||
1.f, 1.f, 1.f, 0.f, 1.f,
|
|
||||||
1.f, 1.f, -1.f, 1.f, 1.f,
|
|
||||||
|
|
||||||
// Top face
|
|
||||||
-1.f, 1.f, -1.f, 0.f, 0.f,
|
|
||||||
1.f, 1.f, -1.f, 1.f, 0.f,
|
|
||||||
1.f, 1.f, 1.f, 1.f, 1.f,
|
|
||||||
-1.f, 1.f, 1.f, 0.f, 1.f,
|
|
||||||
|
|
||||||
// Bottom face
|
|
||||||
-1.f, -1.f, -1.f, 1.f, 0.f,
|
|
||||||
1.f, -1.f, -1.f, 0.f, 0.f,
|
|
||||||
1.f, -1.f, 1.f, 0.f, 1.f,
|
|
||||||
-1.f, -1.f, 1.f, 1.f, 1.f,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Define cube indices
|
|
||||||
static unsigned int g_CubeIndices[] =
|
|
||||||
{
|
|
||||||
// Front face
|
|
||||||
0, 1, 2, 2, 3, 0,
|
|
||||||
// Back face
|
|
||||||
4, 5, 6, 6, 7, 4,
|
|
||||||
// Left face
|
|
||||||
8, 9, 10, 10, 11, 8,
|
|
||||||
// Right face
|
|
||||||
12, 13, 14, 14, 15, 12,
|
|
||||||
// Top face
|
|
||||||
16, 17, 18, 18, 19, 16,
|
|
||||||
// Bottom face
|
|
||||||
20, 21, 22, 22, 23, 20
|
|
||||||
};
|
|
||||||
|
|
||||||
GLuint VAO, VBO, EBO;
|
|
||||||
|
|
||||||
// Generate and bind VAO
|
|
||||||
glGenVertexArrays(1, &VAO);
|
|
||||||
glBindVertexArray(VAO);
|
|
||||||
|
|
||||||
// Generate and bind VBO
|
|
||||||
glGenBuffers(1, &VBO);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(g_CubeVertices), g_CubeVertices, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
// Generate and bind EBO
|
|
||||||
glGenBuffers(1, &EBO);
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(g_CubeIndices), g_CubeIndices, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
// Define vertex attributes
|
|
||||||
// Position attribute (location = 0)
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,
|
|
||||||
5 * sizeof(float), (void*)0);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
|
|
||||||
// UV attribute (location = 1)
|
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,
|
|
||||||
5 * sizeof(float), (void*)(3 * sizeof(float)));
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
|
|
||||||
// Unbind VAO (not EBO!)
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
// Optionally, unbind VBO and EBO for cleanliness
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
||||||
|
|
||||||
// Debug: Print VAO ID
|
|
||||||
printf("[MeshUtils] Initialized CubeVAO with ID: %u\n", VAO);
|
|
||||||
|
|
||||||
return VAO;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyEngine::Run()
|
void MyEngine::Run()
|
||||||
{
|
{
|
||||||
@ -217,6 +134,8 @@ void MyEngine::Run()
|
|||||||
|
|
||||||
// Pseudocode:
|
// Pseudocode:
|
||||||
GameObject cube;
|
GameObject cube;
|
||||||
|
|
||||||
|
cube.name = std::string("Cube");
|
||||||
cube.transform.position = glm::vec3(0.f, 0.f, 0.f);
|
cube.transform.position = glm::vec3(0.f, 0.f, 0.f);
|
||||||
cube.transform.rotation = glm::vec3(0.f, 0.5f, 0.f);
|
cube.transform.rotation = glm::vec3(0.f, 0.5f, 0.f);
|
||||||
cube.transform.scale = glm::vec3(1.f, 1.f, 1.f);
|
cube.transform.scale = glm::vec3(1.f, 1.f, 1.f);
|
||||||
@ -227,7 +146,9 @@ void MyEngine::Run()
|
|||||||
cube.mesh.indexCount = 36;
|
cube.mesh.indexCount = 36;
|
||||||
cube.mesh.textureID = static_cast<GLuint>(reinterpret_cast<uintptr_t>(g_AssetManager.loadAsset(AssetType::TEXTURE, "assets/textures/wood.png")));
|
cube.mesh.textureID = static_cast<GLuint>(reinterpret_cast<uintptr_t>(g_AssetManager.loadAsset(AssetType::TEXTURE, "assets/textures/wood.png")));
|
||||||
|
|
||||||
m_GameObjects.push_back(cube);
|
g_GameObjects.push_back(cube);
|
||||||
|
|
||||||
|
//printf("%p\n", &g_GameObjects);
|
||||||
|
|
||||||
// Possibly create more GameObjects with different positions or textures
|
// Possibly create more GameObjects with different positions or textures
|
||||||
|
|
||||||
@ -263,6 +184,8 @@ void MyEngine::Run()
|
|||||||
m_PerformanceWindow->Show(m_Fps, m_Ms); // FPS & ms
|
m_PerformanceWindow->Show(m_Fps, m_Ms); // FPS & ms
|
||||||
m_LoggerWindow->Show(); // Logs
|
m_LoggerWindow->Show(); // Logs
|
||||||
|
|
||||||
|
m_SceneWindow->Show();
|
||||||
|
|
||||||
// After rendering
|
// After rendering
|
||||||
m_PerformanceWindow->UpdatePerformanceStats(-1, -1);
|
m_PerformanceWindow->UpdatePerformanceStats(-1, -1);
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
#include "Windows/LoggerWindow.h"
|
#include "Windows/LoggerWindow.h"
|
||||||
#include "Engine/AssetManager.h"
|
#include "Engine/AssetManager.h"
|
||||||
#include "Windows/InspectorWindow.h"
|
#include "Windows/InspectorWindow.h"
|
||||||
|
#include "Windows/SceneWindow.h"
|
||||||
|
|
||||||
|
|
||||||
#include "Componenets/GameObject.h"
|
#include "Componenets/GameObject.h"
|
||||||
#include "Componenets/Mesh.h"
|
#include "Componenets/Mesh.h"
|
||||||
@ -50,6 +52,8 @@ private:
|
|||||||
std::unique_ptr<PerformanceWindow> m_PerformanceWindow;
|
std::unique_ptr<PerformanceWindow> m_PerformanceWindow;
|
||||||
std::unique_ptr<LoggerWindow> m_LoggerWindow;
|
std::unique_ptr<LoggerWindow> m_LoggerWindow;
|
||||||
std::unique_ptr<InspectorWindow> m_InspectorWindow;
|
std::unique_ptr<InspectorWindow> m_InspectorWindow;
|
||||||
|
std::unique_ptr<SceneWindow> m_SceneWindow;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// For FPS calculation
|
// For FPS calculation
|
||||||
|
103
src/TestModel.cpp
Normal file
103
src/TestModel.cpp
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
#include "TestModel.h"
|
||||||
|
#include <GL/glew.h>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
|
||||||
|
GLuint CreateCubeVAO()
|
||||||
|
{
|
||||||
|
// Define cube vertices (Position + UVs)
|
||||||
|
static float g_CubeVertices[] =
|
||||||
|
{
|
||||||
|
// Front face
|
||||||
|
-1.f, -1.f, 1.f, 0.f, 0.f,
|
||||||
|
1.f, -1.f, 1.f, 1.f, 0.f,
|
||||||
|
1.f, 1.f, 1.f, 1.f, 1.f,
|
||||||
|
-1.f, 1.f, 1.f, 0.f, 1.f,
|
||||||
|
|
||||||
|
// Back face
|
||||||
|
-1.f, -1.f, -1.f, 1.f, 0.f,
|
||||||
|
1.f, -1.f, -1.f, 0.f, 0.f,
|
||||||
|
1.f, 1.f, -1.f, 0.f, 1.f,
|
||||||
|
-1.f, 1.f, -1.f, 1.f, 1.f,
|
||||||
|
|
||||||
|
// Left face
|
||||||
|
-1.f, -1.f, -1.f, 0.f, 0.f,
|
||||||
|
-1.f, -1.f, 1.f, 1.f, 0.f,
|
||||||
|
-1.f, 1.f, 1.f, 1.f, 1.f,
|
||||||
|
-1.f, 1.f, -1.f, 0.f, 1.f,
|
||||||
|
|
||||||
|
// Right face
|
||||||
|
1.f, -1.f, -1.f, 1.f, 0.f,
|
||||||
|
1.f, -1.f, 1.f, 0.f, 0.f,
|
||||||
|
1.f, 1.f, 1.f, 0.f, 1.f,
|
||||||
|
1.f, 1.f, -1.f, 1.f, 1.f,
|
||||||
|
|
||||||
|
// Top face
|
||||||
|
-1.f, 1.f, -1.f, 0.f, 0.f,
|
||||||
|
1.f, 1.f, -1.f, 1.f, 0.f,
|
||||||
|
1.f, 1.f, 1.f, 1.f, 1.f,
|
||||||
|
-1.f, 1.f, 1.f, 0.f, 1.f,
|
||||||
|
|
||||||
|
// Bottom face
|
||||||
|
-1.f, -1.f, -1.f, 1.f, 0.f,
|
||||||
|
1.f, -1.f, -1.f, 0.f, 0.f,
|
||||||
|
1.f, -1.f, 1.f, 0.f, 1.f,
|
||||||
|
-1.f, -1.f, 1.f, 1.f, 1.f,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Define cube indices
|
||||||
|
static unsigned int g_CubeIndices[] =
|
||||||
|
{
|
||||||
|
// Front face
|
||||||
|
0, 1, 2, 2, 3, 0,
|
||||||
|
// Back face
|
||||||
|
4, 5, 6, 6, 7, 4,
|
||||||
|
// Left face
|
||||||
|
8, 9, 10, 10, 11, 8,
|
||||||
|
// Right face
|
||||||
|
12, 13, 14, 14, 15, 12,
|
||||||
|
// Top face
|
||||||
|
16, 17, 18, 18, 19, 16,
|
||||||
|
// Bottom face
|
||||||
|
20, 21, 22, 22, 23, 20
|
||||||
|
};
|
||||||
|
|
||||||
|
GLuint VAO, VBO, EBO;
|
||||||
|
|
||||||
|
// Generate and bind VAO
|
||||||
|
glGenVertexArrays(1, &VAO);
|
||||||
|
glBindVertexArray(VAO);
|
||||||
|
|
||||||
|
// Generate and bind VBO
|
||||||
|
glGenBuffers(1, &VBO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(g_CubeVertices), g_CubeVertices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
// Generate and bind EBO
|
||||||
|
glGenBuffers(1, &EBO);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(g_CubeIndices), g_CubeIndices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
// Define vertex attributes
|
||||||
|
// Position attribute (location = 0)
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,
|
||||||
|
5 * sizeof(float), (void*)0);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
// UV attribute (location = 1)
|
||||||
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE,
|
||||||
|
5 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
|
||||||
|
// Unbind VAO (not EBO!)
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
// Optionally, unbind VBO and EBO for cleanliness
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
|
// Debug: Print VAO ID
|
||||||
|
printf("[MeshUtils] Initialized CubeVAO with ID: %u\n", VAO);
|
||||||
|
|
||||||
|
return VAO;
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once //
|
||||||
|
#include <GL/glew.h>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
|
||||||
|
GLuint CreateCubeVAO();
|
@ -6,7 +6,11 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
extern std::vector<GameObject> m_GameObjects;
|
extern std::vector<GameObject> g_GameObjects;
|
||||||
|
extern GameObject* g_SelectedObject; // Pointer to the currently selected object
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void InspectorWindow::Show()
|
void InspectorWindow::Show()
|
||||||
{
|
{
|
||||||
@ -30,10 +34,10 @@ void InspectorWindow::Show()
|
|||||||
bool transformOpen = ImGui::CollapsingHeader("Transform##Main", ImGuiTreeNodeFlags_DefaultOpen);
|
bool transformOpen = ImGui::CollapsingHeader("Transform##Main", ImGuiTreeNodeFlags_DefaultOpen);
|
||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor();
|
||||||
|
|
||||||
if (transformOpen)
|
if (transformOpen && g_SelectedObject) //! Funny: I did not put a null check here and it broke everything.
|
||||||
{
|
{
|
||||||
|
|
||||||
Transform* transform = &m_GameObjects[0].transform;
|
Transform* transform = &g_SelectedObject->transform;
|
||||||
if (ImGui::IsItemHovered())
|
if (ImGui::IsItemHovered())
|
||||||
{
|
{
|
||||||
ImGui::BeginTooltip();
|
ImGui::BeginTooltip();
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#include "Componenets/Mesh.h"
|
#include "Componenets/Mesh.h"
|
||||||
#include "Componenets/Transform.h"
|
#include "Componenets/Transform.h"
|
||||||
|
|
||||||
extern std::vector<GameObject> m_GameObjects;
|
extern std::vector<GameObject> g_GameObjects;
|
||||||
|
|
||||||
|
|
||||||
#define CAM_FOV 45.0f
|
#define CAM_FOV 45.0f
|
||||||
@ -209,7 +209,7 @@ void RenderWindow::RenderSceneToFBO()
|
|||||||
glm::mat4 proj = glm::perspective(glm::radians(CAM_FOV), aspect, CAM_NEAR_PLAIN, CAM_FAR_PLAIN);
|
glm::mat4 proj = glm::perspective(glm::radians(CAM_FOV), aspect, CAM_NEAR_PLAIN, CAM_FAR_PLAIN);
|
||||||
|
|
||||||
// Iterate over each GameObject and render it
|
// Iterate over each GameObject and render it
|
||||||
for (auto& obj : m_GameObjects)
|
for (auto& obj : g_GameObjects)
|
||||||
{
|
{
|
||||||
// -----------------------------------
|
// -----------------------------------
|
||||||
// 1) Build MVP from obj.transform
|
// 1) Build MVP from obj.transform
|
||||||
|
96
src/Windows/SceneWindow.cpp
Normal file
96
src/Windows/SceneWindow.cpp
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
#include "SceneWindow.h"
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "glm/vec3.hpp"
|
||||||
|
|
||||||
|
#include "Engine/AssetManager.h"
|
||||||
|
|
||||||
|
#include "TestModel.h"
|
||||||
|
|
||||||
|
// Globals
|
||||||
|
extern std::vector<GameObject> g_GameObjects;
|
||||||
|
extern GameObject* g_SelectedObject;
|
||||||
|
|
||||||
|
extern AssetManager g_AssetManager;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Helper: Create a default cube GameObject
|
||||||
|
GameObject CreateDefaultCube() {
|
||||||
|
GameObject cube;
|
||||||
|
cube.name = "Cube";
|
||||||
|
cube.transform.position = glm::vec3(0.f, 0.f, 0.f);
|
||||||
|
cube.transform.rotation = glm::vec3(0.f, 0.5f, 0.f);
|
||||||
|
cube.transform.scale = glm::vec3(1.f, 1.f, 1.f);
|
||||||
|
cube.mesh.vao = CreateCubeVAO(); // Implement your VAO creation logic
|
||||||
|
cube.mesh.indexCount = 36;
|
||||||
|
cube.mesh.textureID = static_cast<unsigned int>(reinterpret_cast<uintptr_t>(
|
||||||
|
g_AssetManager.loadAsset(AssetType::TEXTURE, "assets/textures/wood.png")));
|
||||||
|
return cube;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show function implementation
|
||||||
|
void SceneWindow::Show() {
|
||||||
|
if (ImGui::Begin("Scene Window")) {
|
||||||
|
// Add Button
|
||||||
|
if (ImGui::Button("Add Object")) {
|
||||||
|
AddGameObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
// List GameObjects
|
||||||
|
int index = 0;
|
||||||
|
for (auto it = g_GameObjects.begin(); it != g_GameObjects.end(); ++it, ++index) {
|
||||||
|
GameObject& obj = *it;
|
||||||
|
std::string uniqueID = obj.name + "##" + std::to_string(index);
|
||||||
|
|
||||||
|
if (ImGui::TreeNode(uniqueID.c_str())) {
|
||||||
|
// Select GameObject
|
||||||
|
if (ImGui::Selectable("Select", g_SelectedObject == &obj)) {
|
||||||
|
g_SelectedObject = &obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Right-click context menu to remove GameObject
|
||||||
|
if (ImGui::BeginPopupContextItem()) {
|
||||||
|
if (ImGui::MenuItem("Remove")) {
|
||||||
|
RemoveGameObject(index);
|
||||||
|
ImGui::EndPopup();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::TreePop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
// Show currently selected object details at the bottom
|
||||||
|
if (g_SelectedObject) {
|
||||||
|
ImGui::Text("Selected Object: %s", g_SelectedObject->name.c_str());
|
||||||
|
// Optionally add details or editable fields here
|
||||||
|
} else {
|
||||||
|
ImGui::Text("No Object Selected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddGameObject: Adds a new GameObject
|
||||||
|
void SceneWindow::AddGameObject() {
|
||||||
|
g_GameObjects.push_back(CreateDefaultCube());
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveGameObject: Removes a GameObject by index
|
||||||
|
void SceneWindow::RemoveGameObject(int index) {
|
||||||
|
if (index >= 0 && index < static_cast<int>(g_GameObjects.size())) {
|
||||||
|
g_GameObjects.erase(g_GameObjects.begin() + index);
|
||||||
|
g_SelectedObject = nullptr; // Clear selection if the removed object was selected
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSelectedObject function implementation
|
||||||
|
GameObject* SceneWindow::GetSelectedObject() const {
|
||||||
|
return g_SelectedObject;
|
||||||
|
}
|
19
src/Windows/SceneWindow.h
Normal file
19
src/Windows/SceneWindow.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
#include "Componenets/GameObject.h"
|
||||||
|
|
||||||
|
|
||||||
|
// SceneWindow class declaration
|
||||||
|
class SceneWindow {
|
||||||
|
public:
|
||||||
|
void Show();
|
||||||
|
GameObject* GetSelectedObject() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void AddGameObject(); // Adds a new game object
|
||||||
|
void RemoveGameObject(int index); // Removes a game object by index
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user