Editor Layer + Updating Camera System
Started updating the camera system, Moving editor logic to an Editor layer
This commit is contained in:
@ -1,20 +1,7 @@
|
||||
#include "../../YoggieEngine/src/EntryPoint.h"
|
||||
#include <mini/ini.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include "AssetManagement/SceneSerializer.h"
|
||||
#include "AssetManagement/AssetManager.h"
|
||||
#include "Views/Viewport.h"
|
||||
#include "PropertyPanels/SceneExplorer.h"
|
||||
#include "AssetManagement/AssetFinder.h"
|
||||
#include "MainMenuBar.h"
|
||||
#include "PropertyPanels/Inspector.h"
|
||||
#include "Project/ProjectInfo.h"
|
||||
#include "Runtime/RuntimeControls.h"
|
||||
#include "AssetManagement/uuid.h"
|
||||
#include "Project/Settings.h"
|
||||
#include "Console.h"
|
||||
#include <stack>
|
||||
#include "EditorLayer.h"
|
||||
|
||||
|
||||
using namespace YoggieEngine;
|
||||
|
||||
@ -24,175 +11,42 @@ public:
|
||||
|
||||
void Run() override
|
||||
{
|
||||
std::string path = (std::filesystem::current_path()).string();
|
||||
project.setProjectDirectory(path);
|
||||
|
||||
LoadLastOrEmptyProject();
|
||||
|
||||
//ProjectInfo projectInfo(project);
|
||||
RuntimeControls rc = RuntimeControls();
|
||||
|
||||
Viewport sceneview = Viewport(scene);
|
||||
SceneExplorer explorer(Selected, scene);
|
||||
Inspector inspector = Inspector(Selected);
|
||||
//Settings settings = Settings();
|
||||
AssetFinder assetsView = AssetFinder();
|
||||
//Console console = Console();
|
||||
|
||||
// Create EditorLayer
|
||||
EditorLayer* firstLayer = new EditorLayer();
|
||||
|
||||
firstLayer->OnStartup();
|
||||
|
||||
Selected = YoggieEngine::Entity((entt::entity) -1, &scene);
|
||||
|
||||
double previous = glfwGetTime();
|
||||
double lag = 0.0;
|
||||
while (!appWindow->WindowShouldClose())
|
||||
{
|
||||
while (!appWindow->WindowShouldClose()) {
|
||||
PollEvents();
|
||||
double now = glfwGetTime();
|
||||
double elapsed = now - previous ;
|
||||
double elapsed = now - previous;
|
||||
previous = now;
|
||||
lag += elapsed;
|
||||
|
||||
scene.Update();
|
||||
|
||||
if (sceneview.isFocused) {
|
||||
UpdateSceneCamera(sceneview);
|
||||
|
||||
std::cout << "Scene view in Focus!\r" ;
|
||||
}
|
||||
|
||||
GuiBegin();
|
||||
|
||||
|
||||
{
|
||||
MainMenuBar menuBar = MainMenuBar();
|
||||
|
||||
// Show a menu bar
|
||||
menuBar.ApplicationMenu(project);
|
||||
menuBar.SceneMenu(project, scene);
|
||||
menuBar.SelectMenu();
|
||||
menuBar.WindowMenu();
|
||||
menuBar.DebugMenu();
|
||||
menuBar.Help();
|
||||
|
||||
}
|
||||
|
||||
//projectInfo.Update();
|
||||
sceneview.Update();
|
||||
rc.Update();
|
||||
explorer.Update();
|
||||
//settings.Update();
|
||||
inspector.Update();
|
||||
//console.Update();
|
||||
|
||||
assetsView.Update();
|
||||
|
||||
ImGui::ShowDemoWindow();
|
||||
//ImGui::ShowMetricsWindow();
|
||||
|
||||
|
||||
firstLayer->OnUpdate();
|
||||
firstLayer->OnUI();
|
||||
GuiEnd();
|
||||
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
firstLayer->OnDestroy();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void LoadLastOrEmptyProject() {
|
||||
// Check if there is a last known loaded project and
|
||||
// load that one .
|
||||
|
||||
// Otherwise load no project..
|
||||
// OR
|
||||
// Load an empty project.
|
||||
mINI::INIStructure ini;
|
||||
|
||||
if (std::filesystem::exists("build\\Debug\\Editor.ini"))
|
||||
{
|
||||
mINI::INIFile file("build\\Debug\\Editor.ini");
|
||||
file.read(ini);
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::debug("Could not find an `Editor.ini` file.");
|
||||
}
|
||||
|
||||
if (ini["editor"]["openlastproject"] == "TRUE")
|
||||
{
|
||||
Project::LoadProject(ini["cache"]["project"], project);
|
||||
LoadScene(ini["cache"]["scene"], scene);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::debug("Starting without a project. Please create one.");
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool SimulatePhysics = true;
|
||||
YoggieEngine::Entity Selected;
|
||||
Project project;
|
||||
Scene scene;
|
||||
|
||||
|
||||
void UpdateSceneCamera(Viewport& sceneview) {
|
||||
const float movement_speed = 0.1f;
|
||||
static float lastX = 400, lastY = 300;
|
||||
const float sensitivity = 0.1;
|
||||
static bool firstMouse = true;
|
||||
|
||||
if (MouseButtonPressed(YOGGIE_MOUSE_BUTTON_RIGHT)) {
|
||||
|
||||
glfwSetInputMode((GLFWwindow*)appWindow->GetHandle(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
auto newX = getCursorPosX(appWindow);
|
||||
auto newY = getCursorPosY(appWindow);
|
||||
|
||||
if (firstMouse)
|
||||
{
|
||||
lastX = newX;
|
||||
lastY = newY;
|
||||
firstMouse = false;
|
||||
}
|
||||
|
||||
|
||||
float xoffset = newX - lastX;
|
||||
float yoffset = newY - lastY;
|
||||
|
||||
lastX = newX;
|
||||
lastY = newY;
|
||||
|
||||
xoffset *= sensitivity;
|
||||
yoffset *= sensitivity;
|
||||
|
||||
sceneview.cam.yaw += xoffset;
|
||||
sceneview.cam.pitch += yoffset;
|
||||
|
||||
if (sceneview.cam.pitch > 89.0f)
|
||||
sceneview.cam.pitch = 89.0f;
|
||||
if (sceneview.cam.pitch < -89.0f)
|
||||
sceneview.cam.pitch = -89.0f;
|
||||
|
||||
}
|
||||
else if (firstMouse == false)
|
||||
{
|
||||
glfwSetInputMode((GLFWwindow*)appWindow->GetHandle(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
firstMouse = true;
|
||||
}
|
||||
|
||||
// Check for Camara movement input here!
|
||||
if (keyIsPressed(YOGGIE_KEY_W)) {
|
||||
sceneview.cam.Position += sceneview.cam.Front * movement_speed;
|
||||
std::cout << "Pressed W !" << std::endl;
|
||||
}
|
||||
|
||||
if (keyIsPressed(YOGGIE_KEY_A))
|
||||
sceneview.cam.Position -= sceneview.cam.Right * movement_speed;
|
||||
|
||||
if (keyIsPressed(YOGGIE_KEY_S))
|
||||
sceneview.cam.Position -= sceneview.cam.Front * movement_speed;
|
||||
|
||||
if (keyIsPressed(YOGGIE_KEY_D))
|
||||
sceneview.cam.Position += sceneview.cam.Right * movement_speed;
|
||||
}
|
||||
std::vector<Layer*> layers = std::vector<Layer*>();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user