From a556b45abf18f1bd509daaf63b66b7d55e9fd291 Mon Sep 17 00:00:00 2001 From: jjesswan Date: Mon, 22 Apr 2024 21:56:26 -0400 Subject: add engine version --- engine-ocean/Engine/core.cpp | 46 +++++++++++++++ engine-ocean/Engine/core.h | 32 ++++++++++ engine-ocean/Engine/window.cpp | 129 +++++++++++++++++++++++++++++++++++++++++ engine-ocean/Engine/window.h | 26 +++++++++ 4 files changed, 233 insertions(+) create mode 100644 engine-ocean/Engine/core.cpp create mode 100644 engine-ocean/Engine/core.h create mode 100644 engine-ocean/Engine/window.cpp create mode 100644 engine-ocean/Engine/window.h (limited to 'engine-ocean/Engine') diff --git a/engine-ocean/Engine/core.cpp b/engine-ocean/Engine/core.cpp new file mode 100644 index 0000000..a0f8557 --- /dev/null +++ b/engine-ocean/Engine/core.cpp @@ -0,0 +1,46 @@ +#include "core.h" + +Core::Core() +{ +} + +Core::~Core(){ + +} + +void Core::update(double deltaTime){ + m_app.update(deltaTime); + +} + +void Core::draw(){ + m_app.draw(); +} + +void Core::keyEvent(int key, int action){ + m_app.keyEvent(key, action); +} + +void Core::mousePosEvent(double xpos, double ypos){ + + m_app.mousePosEvent(xpos,ypos); + +} + +void Core::mouseButtonEvent(int button, int action){ + m_app.mouseButtonEvent(button, action); + +} + +void Core::scrollEvent(double distance){ + m_app.scrollEvent(distance); + +} + +void Core::framebufferResizeEvent(int width, int height){ + m_app.framebufferResizeEvent(width, height); +} + +void Core::windowResizeEvent(int width, int height){ + m_app.windowResizeEvent(width, height); +} diff --git a/engine-ocean/Engine/core.h b/engine-ocean/Engine/core.h new file mode 100644 index 0000000..e6f0672 --- /dev/null +++ b/engine-ocean/Engine/core.h @@ -0,0 +1,32 @@ +#pragma once + +#include "Game/Application.h" +#include "Graphics/global.h" + +#include + +class Core +{ +public: + Core(); + ~Core(); + void update(double deltaTime); + void draw(); + void keyEvent(int key, int action); + void mousePosEvent(double xpos, double ypos); + void mouseButtonEvent(int button, int action); + void scrollEvent(double distance); + void windowResizeEvent(int width, int height); + void framebufferResizeEvent(int width, int height); + +private: + std::shared_ptr camera; + std::shared_ptr shape; + std::shared_ptr modelTransform; + + bool w_down, a_down, s_down, d_down; + bool right_mouse_down = false; + glm::vec2 prev_mouse_pos; + float m_velocity = .05f; + Application m_app; +}; diff --git a/engine-ocean/Engine/window.cpp b/engine-ocean/Engine/window.cpp new file mode 100644 index 0000000..f1d7637 --- /dev/null +++ b/engine-ocean/Engine/window.cpp @@ -0,0 +1,129 @@ +#include "window.h" + +Window::Window(){ + std::cout<<"Start"<update(difference); + m_core->draw(); + glfwSwapBuffers(m_GLFWwindow); + + } +} + +void Window::end(){ + glfwDestroyWindow(m_GLFWwindow); + glfwTerminate(); + exit(EXIT_SUCCESS); +} + +void Window::keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods){ + if(key == GLFW_KEY_ESCAPE){ + glfwSetWindowShouldClose(window, true); + } + Core* ptr = (Core*)glfwGetWindowUserPointer(window); + ptr->keyEvent(key, action); +} + +void Window::cursorPosCallback(GLFWwindow* window, double xpos, double ypos){ + Core* ptr = (Core*)glfwGetWindowUserPointer(window); + ptr->mousePosEvent(xpos, ypos); +} + +void Window::mouseButtonCallback(GLFWwindow* window, int button, int action, int mods){ + Core* ptr = (Core*)glfwGetWindowUserPointer(window); + ptr->mouseButtonEvent(button, action); +} + +void Window::scrollCallback(GLFWwindow* window, double xoffset, double yoffset){ + Core* ptr = (Core*)glfwGetWindowUserPointer(window); + ptr->scrollEvent(yoffset); +} + +void Window::windowSizeCallback(GLFWwindow* window, int width, int height){ + Core* ptr = (Core*)glfwGetWindowUserPointer(window); + ptr->windowResizeEvent(width, height); +} + +void Window::framebufferSizeCallback(GLFWwindow* window, int width, int height){ + Core* ptr = (Core*)glfwGetWindowUserPointer(window); + ptr->framebufferResizeEvent(width, height); +} diff --git a/engine-ocean/Engine/window.h b/engine-ocean/Engine/window.h new file mode 100644 index 0000000..743cf0d --- /dev/null +++ b/engine-ocean/Engine/window.h @@ -0,0 +1,26 @@ +#pragma once + +#include "core.h" + +class Window +{ +public: + Window(); + ~Window(); + +private: + void start(); + void loop(); + void end(); + static void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); + static void cursorPosCallback(GLFWwindow* window, double xpos, double ypos); + static void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods); + static void scrollCallback(GLFWwindow* window, double xoffset, double yoffset); + static void windowSizeCallback(GLFWwindow* window, int width, int height); + static void framebufferSizeCallback(GLFWwindow* window, int width, int height); + + GLFWwindow* m_GLFWwindow; + Core* m_core; + //Application* m_app; + const double m_secPerUpdate = 1.0/60; +}; -- cgit v1.2.3-70-g09d2