Added glm
This commit is contained in:
parent
6864a907fe
commit
727ea3e5aa
16 changed files with 176 additions and 18 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -4,3 +4,6 @@
|
|||
[submodule "Dependencies/GLFW"]
|
||||
path = Dependencies/GLFW
|
||||
url = https://github.com/Light3039/glfw
|
||||
[submodule "Dependencies/glm"]
|
||||
path = Dependencies/glm
|
||||
url = https://github.com/g-truc/glm
|
||||
|
|
1
Dependencies/glm
vendored
Submodule
1
Dependencies/glm
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 66062497b104ca7c297321bd0e970869b1e6ece5
|
|
@ -23,10 +23,13 @@ project "Engine"
|
|||
-- Dependencies --
|
||||
includedirs
|
||||
{
|
||||
-- Engine
|
||||
"%{prj.location}/src/Engine/",
|
||||
|
||||
-- 3rd party
|
||||
(dependenciesdir .. "spdlog/include/"),
|
||||
(dependenciesdir .. "glfw/include/"),
|
||||
(dependenciesdir .. "glm/"),
|
||||
}
|
||||
|
||||
links
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace Light {
|
|||
}
|
||||
}
|
||||
|
||||
void Application::OnEvent(Event& event)
|
||||
void Application::OnEvent(const Event& event)
|
||||
{
|
||||
if (event.IsInCategory(WindowEventCategory))
|
||||
m_Window->OnEvent(event);
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace Light {
|
|||
virtual ~Application();
|
||||
|
||||
void GameLoop();
|
||||
void OnEvent(Event& event);
|
||||
void OnEvent(const Event& event);
|
||||
|
||||
// To be defined in client project
|
||||
friend Application* CreateApplication();
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace Light {
|
|||
inline bool IsOpen() const { return b_Open; }
|
||||
|
||||
virtual void OnUpdate() = 0;
|
||||
virtual void OnEvent(Event& event) = 0;
|
||||
virtual void OnEvent(const Event& event) = 0;
|
||||
|
||||
virtual unsigned int GetHeight() = 0;
|
||||
virtual unsigned int GetWidth() = 0;
|
||||
|
|
|
@ -13,11 +13,11 @@ namespace Light {
|
|||
None = 0,
|
||||
|
||||
// input
|
||||
MouseMoved, ButtonPressed, ButtonReleased, // mouse
|
||||
MouseMoved, WheelScrolled, ButtonPressed, ButtonReleased, // mouse
|
||||
KeyPressed, KeyReleased, // keyboard
|
||||
|
||||
// window
|
||||
WindowMoved, WindowResized, WindowClosed,
|
||||
WindowMoved, WindowResized, WindowClosed, WindowLostFocus, WindowGainFocus,
|
||||
};
|
||||
|
||||
enum EventCategory
|
||||
|
|
|
@ -48,5 +48,4 @@ namespace Light {
|
|||
EVENT_CATEGORY(InputEventCategory | KeyboardEventCategory)
|
||||
};
|
||||
|
||||
|
||||
}
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "Event.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace Light {
|
||||
|
@ -11,24 +13,46 @@ namespace Light {
|
|||
class MouseMovedEvent : public Event
|
||||
{
|
||||
private:
|
||||
const float m_PositionX, m_PositionY;
|
||||
const glm::vec2 m_Position;
|
||||
|
||||
public:
|
||||
MouseMovedEvent(float x, float y) : m_PositionX(x), m_PositionY(y) {}
|
||||
MouseMovedEvent(float x, float y) : m_Position(x, y) {}
|
||||
|
||||
inline float GetX() const { return m_PositionX; }
|
||||
inline float GetY() const { return m_PositionY; }
|
||||
inline const glm::vec2& GetPosition() const { return m_Position; }
|
||||
|
||||
inline float GetX() const { return m_Position.x; }
|
||||
inline float GetY() const { return m_Position.y; }
|
||||
|
||||
virtual std::string GetInfoLog() const override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "MouseMoved: " << m_PositionX << ", " << m_PositionY;
|
||||
ss << "MouseMoved: " << m_Position.x << ", " << m_Position.y;
|
||||
return ss.str();
|
||||
}
|
||||
EVENT_TYPE(MouseMoved)
|
||||
EVENT_CATEGORY(InputEventCategory | MouseEventCategory)
|
||||
};
|
||||
|
||||
class WheelScrolledEvent : public Event
|
||||
{
|
||||
private:
|
||||
const float m_Offset;
|
||||
|
||||
public:
|
||||
WheelScrolledEvent(float offset) : m_Offset(offset) {}
|
||||
|
||||
inline float GetOffset() const { return m_Offset; }
|
||||
|
||||
virtual std::string GetInfoLog() const override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "WheelScrolled: " << m_Offset;
|
||||
return ss.str();
|
||||
}
|
||||
EVENT_TYPE(WheelScrolled)
|
||||
EVENT_CATEGORY(InputEventCategory | MouseEventCategory)
|
||||
};
|
||||
|
||||
class ButtonPressedEvent : public Event
|
||||
{
|
||||
private:
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "Event.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace Light {
|
||||
|
@ -19,4 +21,66 @@ namespace Light {
|
|||
EVENT_CATEGORY(WindowEventCategory)
|
||||
};
|
||||
|
||||
class WindowMovedEvent : public Event
|
||||
{
|
||||
private:
|
||||
const glm::ivec2 m_Position;
|
||||
|
||||
public:
|
||||
WindowMovedEvent(int x, int y): m_Position(x, y) {}
|
||||
|
||||
const glm::ivec2& GetPosition() { return m_Position; }
|
||||
|
||||
virtual std::string GetInfoLog() const override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "WindwoMoved: " << m_Position.x << ", " << m_Position.y;
|
||||
return ss.str();
|
||||
; }
|
||||
EVENT_TYPE(WindowMoved)
|
||||
EVENT_CATEGORY(WindowEventCategory)
|
||||
};
|
||||
|
||||
class WindowResizedEvent : public Event
|
||||
{
|
||||
private:
|
||||
const glm::ivec2 m_Size;
|
||||
|
||||
public:
|
||||
WindowResizedEvent(int width, int height): m_Size(width, height) {}
|
||||
|
||||
const glm::ivec2& GetSize() { return m_Size; }
|
||||
|
||||
virtual std::string GetInfoLog() const override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "WindowResized: " << m_Size.x << ", " << m_Size.y;
|
||||
return ss.str();
|
||||
}
|
||||
EVENT_TYPE(WindowResized)
|
||||
EVENT_CATEGORY(WindowEventCategory)
|
||||
};
|
||||
|
||||
class WindowLostFocusEvent : public Event
|
||||
{
|
||||
public:
|
||||
virtual std::string GetInfoLog() const override
|
||||
{
|
||||
return "WindowLostFocus";
|
||||
}
|
||||
EVENT_TYPE(WindowLostFocus)
|
||||
EVENT_CATEGORY(WindowEventCategory)
|
||||
};
|
||||
|
||||
class WindowGainFocusEvent : public Event
|
||||
{
|
||||
public:
|
||||
virtual std::string GetInfoLog() const override
|
||||
{
|
||||
return "WindowGainFocus";
|
||||
}
|
||||
EVENT_TYPE(WindowGainFocus)
|
||||
EVENT_CATEGORY(WindowEventCategory)
|
||||
};
|
||||
|
||||
}
|
|
@ -24,6 +24,7 @@ namespace Light {
|
|||
virtual bool OnMouseMoved(const MouseMovedEvent& event) { return false; }
|
||||
virtual bool OnButtonPressed(const ButtonPressedEvent& event) { return false; }
|
||||
virtual bool OnButtonReleased(const ButtonReleasedEvent& event) { return false; }
|
||||
virtual bool OnWheelScrolled(const WheelScrolledEvent& event) { return false; }
|
||||
|
||||
// Keyboard events
|
||||
virtual bool OnKeyPressed(const KeyPressedEvent& event) { return false; }
|
||||
|
@ -31,7 +32,10 @@ namespace Light {
|
|||
|
||||
// Window Events
|
||||
virtual bool OnWindowClosed(const WindowClosedEvent& event) { return false; }
|
||||
|
||||
virtual bool OnWindowResized(const WindowResizedEvent& event) { return false; }
|
||||
virtual bool OnWindowMoved(const WindowMovedEvent& event) { return false; }
|
||||
virtual bool OnWindowLostFocus(const WindowLostFocusEvent& event) { return false; }
|
||||
virtual bool OnWindowGainFocus(const WindowGainFocusEvent& event) { return false; }
|
||||
};
|
||||
|
||||
class TestLayer : public Layer
|
||||
|
@ -43,6 +47,7 @@ namespace Light {
|
|||
virtual bool OnMouseMoved(const MouseMovedEvent& event) override { LT_ENGINE_TRACE("{}", event.GetInfoLog()); return false; }
|
||||
virtual bool OnButtonPressed(const ButtonPressedEvent& event) override { LT_ENGINE_TRACE(event.GetInfoLog()); return false; }
|
||||
virtual bool OnButtonReleased(const ButtonReleasedEvent& event) override { LT_ENGINE_TRACE(event.GetInfoLog()); return false; }
|
||||
virtual bool OnWheelScrolled(const WheelScrolledEvent& event) override { LT_ENGINE_TRACE(event.GetInfoLog()); return false; }
|
||||
|
||||
// Keyboard events
|
||||
virtual bool OnKeyPressed(const KeyPressedEvent& event) override { LT_ENGINE_TRACE(event.GetInfoLog()); return false; }
|
||||
|
@ -50,6 +55,10 @@ namespace Light {
|
|||
|
||||
// Window events
|
||||
virtual bool OnWindowClosed(const WindowClosedEvent& event) override { LT_ENGINE_TRACE(event.GetInfoLog()); return false; }
|
||||
virtual bool OnWindowResized(const WindowResizedEvent& event) { LT_ENGINE_TRACE(event.GetInfoLog()); return false; }
|
||||
virtual bool OnWindowMoved(const WindowMovedEvent& event) { LT_ENGINE_TRACE(event.GetInfoLog()); return false; }
|
||||
virtual bool OnWindowLostFocus(const WindowLostFocusEvent& event) { LT_ENGINE_TRACE(event.GetInfoLog()); return false; }
|
||||
virtual bool OnWindowGainFocus(const WindowGainFocusEvent& event) { LT_ENGINE_TRACE(event.GetInfoLog()); return false; }
|
||||
};
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
#include "LayerStack.h"
|
||||
|
||||
#include <functional>
|
||||
namespace Light {
|
||||
|
||||
LayerStack::~LayerStack()
|
||||
|
@ -26,14 +27,14 @@ namespace Light {
|
|||
LT_ENGINE_TRACE("LayerStack::PushLayer: Detatched[{}]", layer->GetName());
|
||||
}
|
||||
|
||||
void LayerStack::OnEvent(Event& event)
|
||||
void LayerStack::OnEvent(const Event& event)
|
||||
{
|
||||
switch (event.GetEventType())
|
||||
{
|
||||
// Mouse
|
||||
case EventType::MouseMoved:
|
||||
for (auto it = m_Begin; it != m_End; it++)
|
||||
if ((*it)->OnMouseMoved((MouseMovedEvent&)event)) return;
|
||||
return;
|
||||
if ((*it)->OnButtonPressed((ButtonPressedEvent&)event)) return;
|
||||
|
||||
case EventType::ButtonPressed:
|
||||
for (auto it = m_Begin; it != m_End; it++)
|
||||
|
@ -43,7 +44,12 @@ namespace Light {
|
|||
for (auto it = m_Begin; it != m_End; it++)
|
||||
if ((*it)->OnButtonReleased((ButtonReleasedEvent&)event)) return;
|
||||
return;
|
||||
case EventType::WheelScrolled:
|
||||
for (auto it = m_Begin; it != m_End; it++)
|
||||
if ((*it)->OnWheelScrolled((WheelScrolledEvent&)event)) return;
|
||||
return;
|
||||
|
||||
// Keyboard
|
||||
case EventType::KeyPressed:
|
||||
for (auto it = m_Begin; it != m_End; it++)
|
||||
if ((*it)->OnKeyPressed((KeyPressedEvent&)event)) return;
|
||||
|
@ -53,11 +59,29 @@ namespace Light {
|
|||
if ((*it)->OnKeyReleased((KeyReleasedEvent&)event)) return;
|
||||
return;
|
||||
|
||||
// Window
|
||||
case EventType::WindowClosed:
|
||||
for (auto it = m_Begin; it != m_End; it++)
|
||||
if ((*it)->OnWindowClosed((WindowClosedEvent&)event)) return;
|
||||
return;
|
||||
case EventType::WindowResized:
|
||||
for (auto it = m_Begin; it != m_End; it++)
|
||||
if ((*it)->OnWindowResized((WindowResizedEvent&)event)) return;
|
||||
return;
|
||||
case EventType::WindowMoved:
|
||||
for (auto it = m_Begin; it != m_End; it++)
|
||||
if ((*it)->OnWindowMoved((WindowMovedEvent&)event)) return;
|
||||
return;
|
||||
case EventType::WindowLostFocus:
|
||||
for (auto it = m_Begin; it != m_End; it++)
|
||||
if ((*it)->OnWindowLostFocus((WindowLostFocusEvent&)event)) return;
|
||||
return;
|
||||
case EventType::WindowGainFocus:
|
||||
for (auto it = m_Begin; it != m_End; it++)
|
||||
if ((*it)->OnWindowGainFocus((WindowGainFocusEvent&)event)) return;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -17,13 +17,15 @@ namespace Light {
|
|||
|
||||
std::vector<Layer*>::iterator m_Begin;
|
||||
std::vector<Layer*>::iterator m_End;
|
||||
|
||||
|
||||
public:
|
||||
~LayerStack();
|
||||
|
||||
void PushLayer(Layer* layer);
|
||||
void PopLayer(Layer* layer);
|
||||
|
||||
void OnEvent(Event& event);
|
||||
void OnEvent(const Event& event);
|
||||
|
||||
std::vector<Layer*>::iterator begin() { return m_Layers.begin(); }
|
||||
std::vector<Layer*>::iterator end() { return m_Layers.end(); }
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace Light {
|
|||
glfwSwapBuffers(m_Handle);
|
||||
}
|
||||
|
||||
void wWindow::OnEvent(Event& event)
|
||||
void wWindow::OnEvent(const Event& event)
|
||||
{
|
||||
switch (event.GetEventType())
|
||||
{
|
||||
|
@ -72,6 +72,12 @@ namespace Light {
|
|||
callback(ButtonReleasedEvent(button));
|
||||
});
|
||||
|
||||
glfwSetScrollCallback(m_Handle, [](GLFWwindow* window, double xoffset, double yoffset)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
callback(WheelScrolledEvent(yoffset));
|
||||
});
|
||||
|
||||
glfwSetKeyCallback(m_Handle, [](GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
@ -87,6 +93,28 @@ namespace Light {
|
|||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
callback(WindowClosedEvent());
|
||||
});
|
||||
|
||||
glfwSetWindowSizeCallback(m_Handle, [](GLFWwindow* window, int width, int height)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
callback(WindowResizedEvent(width, height));
|
||||
});
|
||||
|
||||
glfwSetWindowPosCallback(m_Handle, [](GLFWwindow* window, int xpos, int ypos)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
callback(WindowMovedEvent(xpos, ypos));
|
||||
});
|
||||
|
||||
glfwSetWindowFocusCallback(m_Handle, [](GLFWwindow* window, int focus)
|
||||
{
|
||||
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
|
||||
|
||||
if(focus == GLFW_TRUE)
|
||||
callback(WindowGainFocusEvent());
|
||||
else
|
||||
callback(WindowLostFocusEvent());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -25,7 +25,7 @@ namespace Light {
|
|||
~wWindow();
|
||||
|
||||
virtual void OnUpdate() override;
|
||||
virtual void OnEvent(Event& event) override;
|
||||
virtual void OnEvent(const Event& event) override;
|
||||
|
||||
virtual unsigned int GetWidth() override;
|
||||
virtual unsigned int GetHeight() override;
|
||||
|
|
|
@ -29,6 +29,7 @@ project "Sandbox"
|
|||
|
||||
-- 3rd party
|
||||
(dependenciesdir .. "spdlog/include/"),
|
||||
(dependenciesdir .. "glm/"),
|
||||
}
|
||||
|
||||
links
|
||||
|
|
Loading…
Add table
Reference in a new issue