Introduce Math.hpp and use typedef to make replacing glm with something else in the future simpler
This commit is contained in:
@@ -46,6 +46,7 @@ endif()
|
|||||||
|
|
||||||
# glm
|
# glm
|
||||||
include_directories(external/glm)
|
include_directories(external/glm)
|
||||||
|
add_compile_definitions(GLM_FORCE_INTRINSICS)
|
||||||
|
|
||||||
# fmt
|
# fmt
|
||||||
#add_subdirectory(external/fmt EXCLUDE_FROM_ALL)
|
#add_subdirectory(external/fmt EXCLUDE_FROM_ALL)
|
||||||
|
|||||||
@@ -25,68 +25,8 @@ namespace openVulkanoCpp
|
|||||||
return windowConfig;
|
return windowConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetSize(int* width, int* height) override = 0;
|
|
||||||
|
|
||||||
void GetSize(uint32_t* width, uint32_t* height) override
|
|
||||||
{
|
|
||||||
int w, h;
|
|
||||||
GetSize(&w, &h);
|
|
||||||
*width = w;
|
|
||||||
*height = h;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t GetWidth() override
|
|
||||||
{
|
|
||||||
uint32_t width, height;
|
|
||||||
GetSize(&width, &height);
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t GetHeight() override
|
|
||||||
{
|
|
||||||
uint32_t width, height;
|
|
||||||
GetSize(&width, &height);
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::ivec2 GetSize() override
|
|
||||||
{
|
|
||||||
glm::ivec2 size;
|
|
||||||
this->GetSize(&size.x, &size.y);
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetSize(uint32_t width, uint32_t height) override = 0;
|
void SetSize(uint32_t width, uint32_t height) override = 0;
|
||||||
|
|
||||||
void SetSize(glm::ivec2 size) override
|
|
||||||
{
|
|
||||||
SetSize(size.x, size.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GetPosition(int* x, int* y) override = 0;
|
|
||||||
|
|
||||||
int GetPositionX() override
|
|
||||||
{
|
|
||||||
int x, y;
|
|
||||||
GetPosition(&x, &y);
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
int GetPositionY() override
|
|
||||||
{
|
|
||||||
int x, y;
|
|
||||||
GetPosition(&x, &y);
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
glm::ivec2 GetPosition() override
|
|
||||||
{
|
|
||||||
glm::ivec2 position;
|
|
||||||
GetPosition(&position.x, &position.y);
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HasTitle() override
|
bool HasTitle() override
|
||||||
{
|
{
|
||||||
return WindowMode::WINDOWED == GetWindowMode();
|
return WindowMode::WINDOWED == GetWindowMode();
|
||||||
@@ -104,8 +44,6 @@ namespace openVulkanoCpp
|
|||||||
|
|
||||||
void SetPosition(int posX, int posY) override = 0;
|
void SetPosition(int posX, int posY) override = 0;
|
||||||
|
|
||||||
void SetPosition(glm::ivec2 pos) override { SetPosition(pos.x, pos.y); }
|
|
||||||
|
|
||||||
void Show() override = 0;
|
void Show() override = 0;
|
||||||
void Hide() override = 0;
|
void Hide() override = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include "../../Math/Math.hpp"
|
||||||
#include "../PlatformEnums.hpp"
|
#include "../PlatformEnums.hpp"
|
||||||
#include "../ICloseable.hpp"
|
#include "../ICloseable.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -28,8 +28,8 @@ namespace openVulkanoCpp
|
|||||||
|
|
||||||
struct WindowConfiguration
|
struct WindowConfiguration
|
||||||
{
|
{
|
||||||
uint32_t width = 1280, height = 720;
|
Math::Vector2ui size{1280, 720};
|
||||||
int posX = 0, posY = 0;
|
Math::Vector2i position{0, 0};
|
||||||
std::string title = "Window Title";
|
std::string title = "Window Title";
|
||||||
WindowMode windowMode = WINDOWED;
|
WindowMode windowMode = WINDOWED;
|
||||||
};
|
};
|
||||||
@@ -47,25 +47,20 @@ namespace openVulkanoCpp
|
|||||||
|
|
||||||
virtual WindowMode GetWindowMode() = 0;
|
virtual WindowMode GetWindowMode() = 0;
|
||||||
virtual void SetWindowMode(WindowMode) = 0;
|
virtual void SetWindowMode(WindowMode) = 0;
|
||||||
virtual void SetFullscreen() { SetWindowMode(FULLSCREEN); }
|
inline void SetFullscreen() { SetWindowMode(FULLSCREEN); }
|
||||||
virtual void SetWindowed() { SetWindowMode(WINDOWED); }
|
inline void SetWindowed() { SetWindowMode(WINDOWED); }
|
||||||
|
|
||||||
virtual const WindowConfiguration& GetWindowConfiguration() = 0;
|
virtual const WindowConfiguration& GetWindowConfiguration() = 0;
|
||||||
virtual uint32_t GetWidth() = 0;
|
inline uint32_t GetWidth() { return GetSize().x; }
|
||||||
virtual uint32_t GetHeight() = 0;
|
inline uint32_t GetHeight() { return GetSize().y; }
|
||||||
virtual void GetSize(int* width, int* height) = 0;
|
virtual Math::Vector2ui GetSize() = 0;
|
||||||
virtual void GetSize(uint32_t* width, uint32_t* height) = 0;
|
|
||||||
virtual glm::ivec2 GetSize() = 0;
|
|
||||||
virtual void SetSize(uint32_t width, uint32_t height) = 0;
|
virtual void SetSize(uint32_t width, uint32_t height) = 0;
|
||||||
virtual void SetSize(glm::ivec2 size) { SetSize(size.x, size.y); }
|
inline void SetSize(Math::Vector2ui size) { SetSize(size.x, size.y); }
|
||||||
virtual void SetSizeLimits(int minWidth, int minHeight, int maxWidth, int maxHeight) = 0;
|
virtual void SetSizeLimits(int minWidth, int minHeight, int maxWidth, int maxHeight) = 0;
|
||||||
|
|
||||||
virtual int GetPositionX() = 0;
|
virtual Math::Vector2i GetPosition() = 0;
|
||||||
virtual int GetPositionY() = 0;
|
|
||||||
virtual void GetPosition(int* x, int* y) = 0;
|
|
||||||
virtual glm::ivec2 GetPosition() = 0;
|
|
||||||
virtual void SetPosition(int posX, int posY) = 0;
|
virtual void SetPosition(int posX, int posY) = 0;
|
||||||
virtual void SetPosition(glm::ivec2 pos) = 0;
|
inline void SetPosition(Math::Vector2i pos) { SetPosition(pos.x, pos.y); };
|
||||||
|
|
||||||
virtual void Show() = 0;
|
virtual void Show() = 0;
|
||||||
virtual void Hide() = 0;
|
virtual void Hide() = 0;
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
#include "../Scene/Shader.hpp"
|
#include "../Scene/Shader.hpp"
|
||||||
#include "../Input/InputManager.hpp"
|
#include "../Input/InputManager.hpp"
|
||||||
#include "../Host/GraphicsAppManager.hpp"
|
#include "../Host/GraphicsAppManager.hpp"
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include "../Math/Math.hpp"
|
||||||
#include <glm/gtx/quaternion.hpp>
|
|
||||||
|
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma ide diagnostic ignored "cert-msc50-cpp"
|
#pragma ide diagnostic ignored "cert-msc50-cpp"
|
||||||
@@ -18,6 +17,7 @@
|
|||||||
|
|
||||||
using namespace openVulkanoCpp::Scene;
|
using namespace openVulkanoCpp::Scene;
|
||||||
using namespace openVulkanoCpp::Input;
|
using namespace openVulkanoCpp::Input;
|
||||||
|
using namespace openVulkanoCpp::Math;
|
||||||
|
|
||||||
uint32_t GEOS = 3000, OBJECTS = 10000, DYNAMIC = 1000;
|
uint32_t GEOS = 3000, OBJECTS = 10000, DYNAMIC = 1000;
|
||||||
|
|
||||||
@@ -46,13 +46,13 @@ public:
|
|||||||
scene.Init();
|
scene.Init();
|
||||||
cam.Init(70, 16, 9, 0.1f, 100);
|
cam.Init(70, 16, 9, 0.1f, 100);
|
||||||
scene.SetCamera(&cam);
|
scene.SetCamera(&cam);
|
||||||
cam.SetMatrix(glm::translate(glm::mat4(1), glm::vec3(0,0,-10)));
|
cam.SetMatrix(Utils::translate(Matrix4f(1), Vector3f_SIMD(0,0,-10)));
|
||||||
shader.Init("Shader/basic", "Shader/basic");
|
shader.Init("Shader/basic", "Shader/basic");
|
||||||
drawablesPool.resize(GEOS);
|
drawablesPool.resize(GEOS);
|
||||||
for(int i = 0; i < GEOS; i++)
|
for(int i = 0; i < GEOS; i++)
|
||||||
{
|
{
|
||||||
Geometry* geo = new Geometry();
|
Geometry* geo = new Geometry();
|
||||||
geo->InitCube(std::rand() % 1000 / 1000.0f + 0.01f, std::rand() % 1000 / 1000.0f + 0.01f, std::rand() % 1000 / 1000.0f + 0.01f, glm::vec4((std::rand() % 255) / 255.0f, (std::rand() % 255) / 255.0f, (std::rand() % 255) / 255.0f, 1));
|
geo->InitCube(std::rand() % 1000 / 1000.0f + 0.01f, std::rand() % 1000 / 1000.0f + 0.01f, std::rand() % 1000 / 1000.0f + 0.01f, Vector4f((std::rand() % 255) / 255.0f, (std::rand() % 255) / 255.0f, (std::rand() % 255) / 255.0f, 1));
|
||||||
drawablesPool[i].Init(geo, &mat);
|
drawablesPool[i].Init(geo, &mat);
|
||||||
}
|
}
|
||||||
nodesPool.resize(OBJECTS);
|
nodesPool.resize(OBJECTS);
|
||||||
@@ -62,7 +62,7 @@ public:
|
|||||||
scene.GetRoot()->AddChild(&nodesPool[i]);
|
scene.GetRoot()->AddChild(&nodesPool[i]);
|
||||||
if (i < DYNAMIC) nodesPool[i].SetUpdateFrequency(UpdateFrequency::Always);
|
if (i < DYNAMIC) nodesPool[i].SetUpdateFrequency(UpdateFrequency::Always);
|
||||||
nodesPool[i].AddDrawable(&drawablesPool[std::rand() % GEOS]);
|
nodesPool[i].AddDrawable(&drawablesPool[std::rand() % GEOS]);
|
||||||
nodesPool[i].SetMatrix(glm::translate(glm::mat4x4(1), glm::vec3((std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5)));
|
nodesPool[i].SetMatrix(Utils::translate(glm::mat4x4(1), Vector3f((std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5)));
|
||||||
}
|
}
|
||||||
|
|
||||||
scene.shader = &shader;
|
scene.shader = &shader;
|
||||||
@@ -88,7 +88,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
float yaw = 0, pitch = 0;
|
float yaw = 0, pitch = 0;
|
||||||
glm::vec3 position = {0,0,-10};
|
Vector3f_SIMD position = {0,0,-10};
|
||||||
|
|
||||||
void Tick() override
|
void Tick() override
|
||||||
{
|
{
|
||||||
@@ -98,10 +98,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto input = InputManager::GetInstace();
|
auto input = InputManager::GetInstace();
|
||||||
glm::vec3 vec(input->GetAxis(actionSide), 0, -input->GetAxis(actionForward));
|
Vector3f_SIMD vec(input->GetAxis(actionSide), 0, -input->GetAxis(actionForward));
|
||||||
if(glm::length2(vec) > 1)
|
if(Utils::length2(vec) > 1.0f)
|
||||||
{
|
{
|
||||||
vec = glm::normalize(vec);
|
vec = Utils::normalize(vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
float tiemScale = 0.004f;
|
float tiemScale = 0.004f;
|
||||||
@@ -111,12 +111,12 @@ public:
|
|||||||
yaw += input->GetAxis(actionLookSide) * tiemScale * 0.5f;
|
yaw += input->GetAxis(actionLookSide) * tiemScale * 0.5f;
|
||||||
pitch += input->GetAxis(actionLookUp) * tiemScale * 0.5f;
|
pitch += input->GetAxis(actionLookUp) * tiemScale * 0.5f;
|
||||||
|
|
||||||
glm::quat rot(glm::vec3(pitch, yaw, 0));
|
QuaternionF rot(Vector3f(pitch, yaw, 0));
|
||||||
glm::mat4 rotMat = glm::toMat4(rot);
|
Matrix4f rotMat = Utils::toMat4(rot);
|
||||||
|
|
||||||
vec = glm::vec3(rot * glm::vec4(vec, 1));
|
vec = Vector3f_SIMD(rotMat * Vector4f(vec, 1));
|
||||||
position += vec;
|
position += vec;
|
||||||
cam.SetMatrix(glm::translate(glm::mat4(1), position) * rotMat);
|
cam.SetMatrix(Utils::translate(Matrix4f(1), position) * rotMat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Close() override{}
|
void Close() override{}
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ namespace openVulkanoCpp::GLFW
|
|||||||
{
|
{
|
||||||
int posX, posY, sizeX, sizeY;
|
int posX, posY, sizeX, sizeY;
|
||||||
glfwGetMonitorWorkarea(monitors[i], &posX, &posY, &sizeX, &sizeY);
|
glfwGetMonitorWorkarea(monitors[i], &posX, &posY, &sizeX, &sizeY);
|
||||||
if (windowConfig.posX >= posX && windowConfig.posX < posX + sizeX &&
|
if (windowConfig.position.x >= posX && windowConfig.position.x < posX + sizeX &&
|
||||||
windowConfig.posY >= posY && windowConfig.posY < posY + sizeY)
|
windowConfig.position.y >= posY && windowConfig.position.y < posY + sizeY)
|
||||||
{
|
{
|
||||||
return monitors[i];
|
return monitors[i];
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ namespace openVulkanoCpp::GLFW
|
|||||||
{
|
{
|
||||||
glfwWindowHint(GLFW_DECORATED, (~windowConfig.windowMode) & 1);
|
glfwWindowHint(GLFW_DECORATED, (~windowConfig.windowMode) & 1);
|
||||||
//TODO handle full screen resolutions
|
//TODO handle full screen resolutions
|
||||||
window = glfwCreateWindow(windowConfig.width, windowConfig.height, windowConfig.title.c_str(), GetTargetMonitor(), nullptr);
|
window = glfwCreateWindow(windowConfig.size.x, windowConfig.size.y, windowConfig.title.c_str(), GetTargetMonitor(), nullptr);
|
||||||
if (!window) return;
|
if (!window) return;
|
||||||
glfwSetWindowUserPointer(window, this);
|
glfwSetWindowUserPointer(window, this);
|
||||||
RegisterCallbacks();
|
RegisterCallbacks();
|
||||||
@@ -142,8 +142,8 @@ namespace openVulkanoCpp::GLFW
|
|||||||
|
|
||||||
void WindowGLFW::SetSize(uint32_t width, uint32_t height)
|
void WindowGLFW::SetSize(uint32_t width, uint32_t height)
|
||||||
{
|
{
|
||||||
windowConfig.width = width;
|
windowConfig.size.x = width;
|
||||||
windowConfig.height = height;
|
windowConfig.size.y = height;
|
||||||
if (window)
|
if (window)
|
||||||
{
|
{
|
||||||
glfwSetWindowSize(window, width, height);
|
glfwSetWindowSize(window, width, height);
|
||||||
@@ -152,14 +152,28 @@ namespace openVulkanoCpp::GLFW
|
|||||||
|
|
||||||
void WindowGLFW::SetPosition(int posX, int posY)
|
void WindowGLFW::SetPosition(int posX, int posY)
|
||||||
{
|
{
|
||||||
windowConfig.posX = posX;
|
windowConfig.position.x = posX;
|
||||||
windowConfig.posY = posY;
|
windowConfig.position.y = posY;
|
||||||
if (window)
|
if (window)
|
||||||
{
|
{
|
||||||
glfwSetWindowPos(window, posX, posY);
|
glfwSetWindowPos(window, posX, posY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Math::Vector2ui WindowGLFW::GetSize()
|
||||||
|
{
|
||||||
|
Math::Vector2i size;
|
||||||
|
glfwGetWindowSize(window, &size.x, &size.y);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
Math::Vector2i WindowGLFW::GetPosition()
|
||||||
|
{
|
||||||
|
Math::Vector2i pos;
|
||||||
|
glfwGetWindowPos(window, &pos.x, &pos.y);
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
void WindowGLFW::SetSizeLimits(int minWidth, int minHeight, int maxWidth, int maxHeight)
|
void WindowGLFW::SetSizeLimits(int minWidth, int minHeight, int maxWidth, int maxHeight)
|
||||||
{
|
{
|
||||||
minWidth = (minWidth < 0) ? GLFW_DONT_CARE : minWidth;
|
minWidth = (minWidth < 0) ? GLFW_DONT_CARE : minWidth;
|
||||||
@@ -185,10 +199,10 @@ namespace openVulkanoCpp::GLFW
|
|||||||
glfwWindowHint(GLFW_DECORATED, (~windowMode) & 1);
|
glfwWindowHint(GLFW_DECORATED, (~windowMode) & 1);
|
||||||
if (windowMode == WINDOWED || windowMode == BORDERLESS)
|
if (windowMode == WINDOWED || windowMode == BORDERLESS)
|
||||||
{
|
{
|
||||||
sizeX = windowConfig.width;
|
sizeX = windowConfig.size.x;
|
||||||
sizeY = windowConfig.height;
|
sizeY = windowConfig.size.y;
|
||||||
posX = windowConfig.posX;
|
posX = windowConfig.position.x;
|
||||||
posY = windowConfig.posY;
|
posY = windowConfig.position.y;
|
||||||
monitor = nullptr;
|
monitor = nullptr;
|
||||||
if (windowMode == WINDOWED)
|
if (windowMode == WINDOWED)
|
||||||
{
|
{
|
||||||
@@ -201,7 +215,7 @@ namespace openVulkanoCpp::GLFW
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // Fullscreen
|
{ // Fullscreen
|
||||||
GetPosition(&windowConfig.posX, &windowConfig.posY); // Backup current window position
|
windowConfig.position = GetPosition(); // Backup current window position
|
||||||
monitor = GetCurrentMonitor();
|
monitor = GetCurrentMonitor();
|
||||||
if (!monitor) monitor = GetPrimaryMonitor();
|
if (!monitor) monitor = GetPrimaryMonitor();
|
||||||
if (!monitor) return; // We don't have a monitor to set the fullscreen window to
|
if (!monitor) return; // We don't have a monitor to set the fullscreen window to
|
||||||
@@ -229,16 +243,6 @@ namespace openVulkanoCpp::GLFW
|
|||||||
this->handler = handler;
|
this->handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowGLFW::GetSize(int* width, int* height)
|
|
||||||
{
|
|
||||||
glfwGetWindowSize(window, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WindowGLFW::GetPosition(int* x, int* y)
|
|
||||||
{
|
|
||||||
glfwGetWindowPos(window, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
vk::SurfaceKHR WindowGLFW::CreateSurface(const vk::Instance& instance, const vk::AllocationCallbacks* pAllocator)
|
vk::SurfaceKHR WindowGLFW::CreateSurface(const vk::Instance& instance, const vk::AllocationCallbacks* pAllocator)
|
||||||
{
|
{
|
||||||
VkSurfaceKHR rawSurface;
|
VkSurfaceKHR rawSurface;
|
||||||
@@ -286,8 +290,8 @@ namespace openVulkanoCpp::GLFW
|
|||||||
Logger::WINDOW->debug("Window (id: {0}) moved (x: {1}, y: {2})", GetWindowId(), posX, posY);
|
Logger::WINDOW->debug("Window (id: {0}) moved (x: {1}, y: {2})", GetWindowId(), posX, posY);
|
||||||
if (windowConfig.windowMode == WINDOWED || windowConfig.windowMode == BORDERLESS)
|
if (windowConfig.windowMode == WINDOWED || windowConfig.windowMode == BORDERLESS)
|
||||||
{ // Don't save window position for fullscreen
|
{ // Don't save window position for fullscreen
|
||||||
windowConfig.posX = posX;
|
windowConfig.position.x = posX;
|
||||||
windowConfig.posY = posY;
|
windowConfig.position.y = posY;
|
||||||
}
|
}
|
||||||
handler->OnWindowMove(this, posX, posY);
|
handler->OnWindowMove(this, posX, posY);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,9 +72,9 @@ namespace openVulkanoCpp::GLFW
|
|||||||
IOpenGlWindow* GetOpenGlWindow() override { return this; };
|
IOpenGlWindow* GetOpenGlWindow() override { return this; };
|
||||||
|
|
||||||
// Status getter
|
// Status getter
|
||||||
void GetSize(int* width, int* height) override;
|
Math::Vector2ui GetSize() override;
|
||||||
|
|
||||||
void GetPosition(int* x, int* y) override;
|
Math::Vector2i GetPosition() override;
|
||||||
|
|
||||||
IWindowHandler* GetWindowHandler() override { return handler; }
|
IWindowHandler* GetWindowHandler() override { return handler; }
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "InputDevice.hpp"
|
#include "InputDevice.hpp"
|
||||||
#include "glm/vec2.hpp"
|
#include "../Math/Math.hpp"
|
||||||
|
|
||||||
namespace openVulkanoCpp
|
namespace openVulkanoCpp
|
||||||
{
|
{
|
||||||
@@ -100,7 +100,7 @@ namespace openVulkanoCpp
|
|||||||
return GetAxis(InputKey::Mouse::Axis::AXIS_WHEEL_Y);
|
return GetAxis(InputKey::Mouse::Axis::AXIS_WHEEL_Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] glm::vec2 GetMousePosition() const
|
[[nodiscard]] Math::Vector2d GetMousePosition() const
|
||||||
{
|
{
|
||||||
return { mousePosX, mousePosY };
|
return { mousePosX, mousePosY };
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ namespace openVulkanoCpp
|
|||||||
posY = mousePosY;
|
posY = mousePosY;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec2 GetMousePosition(const IWindow* window) const
|
[[nodiscard]] Math::Vector2d GetMousePosition(const IWindow* window) const
|
||||||
{
|
{
|
||||||
if (window == lastWindow)
|
if (window == lastWindow)
|
||||||
{
|
{
|
||||||
|
|||||||
138
openVulkanoCpp/Math/Math.hpp
Normal file
138
openVulkanoCpp/Math/Math.hpp
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define GLM_FORECE_DEPTH_ZERO_TO_ONE // TODO handle this better
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/quaternion.hpp>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include <glm/gtx/quaternion.hpp>
|
||||||
|
|
||||||
|
namespace openVulkanoCpp::Math
|
||||||
|
{
|
||||||
|
namespace Utils
|
||||||
|
{
|
||||||
|
using namespace glm;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> using Matrix2_SIMD = glm::tmat2x2<T, glm::aligned>;
|
||||||
|
template<typename T> using Matrix3_SIMD = glm::tmat3x3<T, glm::aligned>;
|
||||||
|
template<typename T> using Matrix4_SIMD = glm::tmat4x4<T, glm::aligned>;
|
||||||
|
template<typename T> using Matrix2 = glm::tmat2x2<T, glm::packed>;
|
||||||
|
template<typename T> using Matrix3 = glm::tmat3x3<T, glm::packed>;
|
||||||
|
template<typename T> using Matrix4 = Matrix4_SIMD<T>;
|
||||||
|
//template<typename T> using Matrix4 = glm::tmat4x4<T, glm::packed>;
|
||||||
|
|
||||||
|
typedef Matrix2<float> Matrix2f;
|
||||||
|
typedef Matrix2<double> Matrix2d;
|
||||||
|
typedef Matrix2<int32_t> Matrix2i;
|
||||||
|
typedef Matrix2<int64_t> Matrix2l;
|
||||||
|
|
||||||
|
typedef Matrix3<float> Matrix3f;
|
||||||
|
typedef Matrix3<double> Matrix3d;
|
||||||
|
typedef Matrix3<int32_t> Matrix3i;
|
||||||
|
typedef Matrix3<int64_t> Matrix3l;
|
||||||
|
|
||||||
|
typedef Matrix4<float> Matrix4f;
|
||||||
|
typedef Matrix4<double> Matrix4d;
|
||||||
|
typedef Matrix4<int32_t> Matrix4i;
|
||||||
|
typedef Matrix4<int64_t> Matrix4l;
|
||||||
|
|
||||||
|
typedef Matrix2_SIMD<float> Matrix2f_SIMD;
|
||||||
|
typedef Matrix2_SIMD<double> Matrix2d_SIMD;
|
||||||
|
typedef Matrix2_SIMD<int32_t> Matrix2i_SIMD;
|
||||||
|
typedef Matrix2_SIMD<int64_t> Matrix2l_SIMD;
|
||||||
|
|
||||||
|
typedef Matrix3_SIMD<float> Matrix3f_SIMD;
|
||||||
|
typedef Matrix3_SIMD<double> Matrix3d_SIMD;
|
||||||
|
typedef Matrix3_SIMD<int32_t> Matrix3i_SIMD;
|
||||||
|
typedef Matrix3_SIMD<int64_t> Matrix3l_SIMD;
|
||||||
|
|
||||||
|
typedef Matrix4_SIMD<float> Matrix4f_SIMD;
|
||||||
|
typedef Matrix4_SIMD<double> Matrix4d_SIMD;
|
||||||
|
typedef Matrix4_SIMD<int32_t> Matrix4i_SIMD;
|
||||||
|
typedef Matrix4_SIMD<int64_t> Matrix4l_SIMD;
|
||||||
|
|
||||||
|
template<typename T> using Vector2_SIMD = glm::tvec2<T, glm::aligned>;
|
||||||
|
template<typename T> using Vector3_SIMD = glm::tvec3<T, glm::aligned>;
|
||||||
|
template<typename T> using Vector4_SIMD = glm::tvec4<T, glm::aligned>;
|
||||||
|
template<typename T> using Vector2 = glm::tvec2<T, glm::packed>;
|
||||||
|
template<typename T> using Vector3 = glm::tvec3<T, glm::packed>;
|
||||||
|
template<typename T> using Vector4 = Vector4_SIMD<T>;
|
||||||
|
//template<typename T> using Vector4 = glm::tvec4<T, glm::packed>;
|
||||||
|
|
||||||
|
typedef Vector2<float> Vector2f;
|
||||||
|
typedef Vector2<double> Vector2d;
|
||||||
|
typedef Vector2<int8_t> Vector2c;
|
||||||
|
typedef Vector2<int16_t> Vector2s;
|
||||||
|
typedef Vector2<int32_t> Vector2i;
|
||||||
|
typedef Vector2<int64_t> Vector2l;
|
||||||
|
typedef Vector2<uint8_t> Vector2uc;
|
||||||
|
typedef Vector2<uint16_t> Vector2us;
|
||||||
|
typedef Vector2<uint32_t> Vector2ui;
|
||||||
|
typedef Vector2<uint64_t> Vector2ul;
|
||||||
|
|
||||||
|
typedef Vector3<float> Vector3f;
|
||||||
|
typedef Vector3<double> Vector3d;
|
||||||
|
typedef Vector3<int8_t> Vector3c;
|
||||||
|
typedef Vector3<int16_t> Vector3s;
|
||||||
|
typedef Vector3<int32_t> Vector3i;
|
||||||
|
typedef Vector3<int64_t> Vector3l;
|
||||||
|
typedef Vector3<uint8_t> Vector3uc;
|
||||||
|
typedef Vector3<uint16_t> Vector3us;
|
||||||
|
typedef Vector3<uint32_t> Vector3ui;
|
||||||
|
typedef Vector3<uint64_t> Vector3ul;
|
||||||
|
|
||||||
|
typedef Vector4<float> Vector4f;
|
||||||
|
typedef Vector4<double> Vector4d;
|
||||||
|
typedef Vector4<int8_t> Vector4c;
|
||||||
|
typedef Vector4<int16_t> Vector4s;
|
||||||
|
typedef Vector4<int32_t> Vector4i;
|
||||||
|
typedef Vector4<int64_t> Vector4l;
|
||||||
|
typedef Vector4<uint8_t> Vector4uc;
|
||||||
|
typedef Vector4<uint16_t> Vector4us;
|
||||||
|
typedef Vector4<uint32_t> Vector4ui;
|
||||||
|
typedef Vector4<uint64_t> Vector4ul;
|
||||||
|
|
||||||
|
typedef Vector2_SIMD<float> Vector2f_SIMD;
|
||||||
|
typedef Vector2_SIMD<double> Vector2d_SIMD;
|
||||||
|
typedef Vector2_SIMD<int8_t> Vector2c_SIMD;
|
||||||
|
typedef Vector2_SIMD<int16_t> Vector2s_SIMD;
|
||||||
|
typedef Vector2_SIMD<int32_t> Vector2i_SIMD;
|
||||||
|
typedef Vector2_SIMD<int64_t> Vector2l_SIMD;
|
||||||
|
typedef Vector2_SIMD<uint8_t> Vector2uc_SIMD;
|
||||||
|
typedef Vector2_SIMD<uint16_t> Vector2us_SIMD;
|
||||||
|
typedef Vector2_SIMD<uint32_t> Vector2ui_SIMD;
|
||||||
|
typedef Vector2_SIMD<uint64_t> Vector2ul_SIMD;
|
||||||
|
|
||||||
|
typedef Vector3_SIMD<float> Vector3f_SIMD;
|
||||||
|
typedef Vector3_SIMD<double> Vector3d_SIMD;
|
||||||
|
typedef Vector3_SIMD<int8_t> Vector3c_SIMD;
|
||||||
|
typedef Vector3_SIMD<int16_t> Vector3s_SIMD;
|
||||||
|
typedef Vector3_SIMD<int32_t> Vector3i_SIMD;
|
||||||
|
typedef Vector3_SIMD<int64_t> Vector3l_SIMD;
|
||||||
|
typedef Vector3_SIMD<uint8_t> Vector3uc_SIMD;
|
||||||
|
typedef Vector3_SIMD<uint16_t> Vector3us_SIMD;
|
||||||
|
typedef Vector3_SIMD<uint32_t> Vector3ui_SIMD;
|
||||||
|
typedef Vector3_SIMD<uint64_t> Vector3ul_SIMD;
|
||||||
|
|
||||||
|
typedef Vector4_SIMD<float> Vector4f_SIMD;
|
||||||
|
typedef Vector4_SIMD<double> Vector4d_SIMD;
|
||||||
|
typedef Vector4_SIMD<int8_t> Vector4c_SIMD;
|
||||||
|
typedef Vector4_SIMD<int16_t> Vector4s_SIMD;
|
||||||
|
typedef Vector4_SIMD<int32_t> Vector4i_SIMD;
|
||||||
|
typedef Vector4_SIMD<int64_t> Vector4l_SIMD;
|
||||||
|
typedef Vector4_SIMD<uint8_t> Vector4uc_SIMD;
|
||||||
|
typedef Vector4_SIMD<uint16_t> Vector4us_SIMD;
|
||||||
|
typedef Vector4_SIMD<uint32_t> Vector4ui_SIMD;
|
||||||
|
typedef Vector4_SIMD<uint64_t> Vector4ul_SIMD;
|
||||||
|
|
||||||
|
template<typename T> using Quaternion = glm::tquat<T, glm::aligned>;
|
||||||
|
typedef Quaternion<float> QuaternionF;
|
||||||
|
typedef Quaternion<double> QuaternionD;
|
||||||
|
typedef Quaternion<int> QuaternionI;
|
||||||
|
}
|
||||||
@@ -1,5 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
#include "../Math/Math.hpp"
|
||||||
#include "../Base/IInitable.hpp"
|
#include "../Base/IInitable.hpp"
|
||||||
|
|
||||||
namespace openVulkanoCpp
|
namespace openVulkanoCpp
|
||||||
@@ -11,7 +18,7 @@ namespace openVulkanoCpp
|
|||||||
*/
|
*/
|
||||||
class AABB final : public virtual IInitable
|
class AABB final : public virtual IInitable
|
||||||
{
|
{
|
||||||
glm::vec3 min, max;
|
Math::Vector3f min, max;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AABB() : min(INFINITY), max(-INFINITY) {}
|
AABB() : min(INFINITY), max(-INFINITY) {}
|
||||||
@@ -22,15 +29,15 @@ namespace openVulkanoCpp
|
|||||||
*/
|
*/
|
||||||
void Init() override
|
void Init() override
|
||||||
{
|
{
|
||||||
min = glm::vec3(INFINITY);
|
min = Math::Vector3f(INFINITY);
|
||||||
max = glm::vec3(-INFINITY);
|
max = Math::Vector3f(-INFINITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Initiates the AABB to a single point (min=max=point)
|
* \brief Initiates the AABB to a single point (min=max=point)
|
||||||
* \param point The point that should be used as min and max of the AABB
|
* \param point The point that should be used as min and max of the AABB
|
||||||
*/
|
*/
|
||||||
void Init(const glm::vec3& point)
|
void Init(const Math::Vector3f& point)
|
||||||
{
|
{
|
||||||
min = max = point;
|
min = max = point;
|
||||||
}
|
}
|
||||||
@@ -45,33 +52,33 @@ namespace openVulkanoCpp
|
|||||||
max = other.GetMax();
|
max = other.GetMax();
|
||||||
}
|
}
|
||||||
|
|
||||||
const glm::vec3& GetMin() const { return min; }
|
[[nodiscard]] inline const Math::Vector3f& GetMin() const { return min; }
|
||||||
|
|
||||||
const glm::vec3& GetMax() const { return max; }
|
[[nodiscard]] inline const Math::Vector3f& GetMax() const { return max; }
|
||||||
|
|
||||||
void Grow(const glm::vec3& point)
|
void Grow(const Math::Vector3f& point)
|
||||||
{
|
{
|
||||||
min = glm::min(min, point);
|
min = Math::Utils::min(min, point);
|
||||||
max = glm::max(max, point);
|
max = Math::Utils::max(max, point);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Grow(const AABB& otherAABB)
|
void Grow(const AABB& otherAABB)
|
||||||
{
|
{
|
||||||
min = glm::min(min, otherAABB.GetMin());
|
min = Math::Utils::min(min, otherAABB.GetMin());
|
||||||
max = glm::max(max, otherAABB.GetMax());
|
max = Math::Utils::max(max, otherAABB.GetMax());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Grow(const AABB& otherAABB, glm::mat4x4 transformation)
|
void Grow(const AABB& otherAABB, Math::Matrix4f transformation)
|
||||||
{
|
{
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 GetDiagonal() const
|
[[nodiscard]] Math::Vector3f GetDiagonal() const
|
||||||
{
|
{
|
||||||
return max - min;
|
return max - min;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 GetCenter() const
|
[[nodiscard]] Math::Vector3f GetCenter() const
|
||||||
{
|
{
|
||||||
return min + (GetDiagonal() * 0.5f);
|
return min + (GetDiagonal() * 0.5f);
|
||||||
}
|
}
|
||||||
@@ -81,7 +88,7 @@ namespace openVulkanoCpp
|
|||||||
* \param other The other AABB that should be checked
|
* \param other The other AABB that should be checked
|
||||||
* \return true if the AABB overlaps with the other, false if not
|
* \return true if the AABB overlaps with the other, false if not
|
||||||
*/
|
*/
|
||||||
bool IsOverlapping(const AABB& other) const
|
[[nodiscard]] bool IsOverlapping(const AABB& other) const
|
||||||
{
|
{
|
||||||
return !(other.min.x > max.x || other.max.x < min.x || other.min.y > max.y || other.max.y < min.y || other.min.z > max.z || other.max.z < min.z);
|
return !(other.min.x > max.x || other.max.x < min.x || other.min.y > max.y || other.max.y < min.y || other.min.z > max.z || other.max.z < min.z);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define _USE_MATH_DEFINES
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
|
||||||
#include "Node.hpp"
|
#include "Node.hpp"
|
||||||
#define GLM_FORECE_DEPTH_ZERO_TO_ONE
|
#include "../Math/Math.hpp"
|
||||||
|
|
||||||
namespace openVulkanoCpp
|
namespace openVulkanoCpp
|
||||||
{
|
{
|
||||||
@@ -21,7 +18,7 @@ namespace openVulkanoCpp
|
|||||||
protected:
|
protected:
|
||||||
float width, height, nearPlane, farPlane;
|
float width, height, nearPlane, farPlane;
|
||||||
|
|
||||||
glm::mat4x4 projection, view, viewProjection;
|
Math::Matrix4f projection, view, viewProjection;
|
||||||
|
|
||||||
Camera() : width(0), height(0), nearPlane(0), farPlane(0), projection(1), view(1), viewProjection(1) {}
|
Camera() : width(0), height(0), nearPlane(0), farPlane(0), projection(1), view(1), viewProjection(1) {}
|
||||||
|
|
||||||
@@ -76,17 +73,17 @@ namespace openVulkanoCpp
|
|||||||
|
|
||||||
void UpdateViewProjectionMatrix()
|
void UpdateViewProjectionMatrix()
|
||||||
{ // In vulkan the screen space is defined as y=0=top and y=1=bottom and thus the coordinate have to be flipped
|
{ // In vulkan the screen space is defined as y=0=top and y=1=bottom and thus the coordinate have to be flipped
|
||||||
viewProjection = projection * glm::mat4x4(1,0,0,0,0,-1,0,0,0,0,1,0,0,0,0,1) * view;
|
viewProjection = projection * Math::Matrix4f(1,0,0,0,0,-1,0,0,0,0,1,0,0,0,0,1) * view;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateWorldMatrix(const glm::mat4x4& parentWorldMat) override
|
void UpdateWorldMatrix(const Math::Matrix4f& parentWorldMat) override
|
||||||
{
|
{
|
||||||
Node::UpdateWorldMatrix(parentWorldMat);
|
Node::UpdateWorldMatrix(parentWorldMat);
|
||||||
view = glm::inverse(GetWorldMatrix());
|
view = Math::Utils::inverse(GetWorldMatrix());
|
||||||
UpdateViewProjectionMatrix();
|
UpdateViewProjectionMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] const glm::mat4x4& GetViewProjectionMatrix() const
|
[[nodiscard]] const Math::Matrix4f& GetViewProjectionMatrix() const
|
||||||
{
|
{
|
||||||
return viewProjection;
|
return viewProjection;
|
||||||
}
|
}
|
||||||
@@ -109,7 +106,7 @@ namespace openVulkanoCpp
|
|||||||
|
|
||||||
void Init(float fovDegrees, float width, float height, float nearPlane, float farPlane)
|
void Init(float fovDegrees, float width, float height, float nearPlane, float farPlane)
|
||||||
{
|
{
|
||||||
this->fov = glm::radians(fovDegrees);
|
this->fov = Math::Utils::radians(fovDegrees);
|
||||||
aspect = width / height;
|
aspect = width / height;
|
||||||
Camera::Init(width, height, nearPlane, farPlane);
|
Camera::Init(width, height, nearPlane, farPlane);
|
||||||
}
|
}
|
||||||
@@ -138,7 +135,7 @@ namespace openVulkanoCpp
|
|||||||
|
|
||||||
void SetFov(const float fov)
|
void SetFov(const float fov)
|
||||||
{
|
{
|
||||||
SetFovRad(glm::radians(fov));
|
SetFovRad(Math::Utils::radians(fov));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetFovRad(const float fov)
|
void SetFovRad(const float fov)
|
||||||
@@ -148,7 +145,7 @@ namespace openVulkanoCpp
|
|||||||
|
|
||||||
[[nodiscard]] float GetFov() const
|
[[nodiscard]] float GetFov() const
|
||||||
{
|
{
|
||||||
return glm::degrees(fov);
|
return Math::Utils::degrees(fov);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] float GetFovX() const
|
[[nodiscard]] float GetFovX() const
|
||||||
@@ -168,7 +165,7 @@ namespace openVulkanoCpp
|
|||||||
|
|
||||||
void UpdateProjectionMatrix() override
|
void UpdateProjectionMatrix() override
|
||||||
{
|
{
|
||||||
projection = glm::perspectiveLH_ZO(fov, aspect, nearPlane, farPlane);
|
projection = Math::Utils::perspectiveLH_ZO(fov, aspect, nearPlane, farPlane);
|
||||||
UpdateViewProjectionMatrix();
|
UpdateViewProjectionMatrix();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -179,7 +176,7 @@ namespace openVulkanoCpp
|
|||||||
void UpdateProjectionMatrix() override
|
void UpdateProjectionMatrix() override
|
||||||
{
|
{
|
||||||
const float widthHalf = width * 0.5f, heightHalf = height * 0.5f;
|
const float widthHalf = width * 0.5f, heightHalf = height * 0.5f;
|
||||||
projection = glm::orthoLH_ZO(-widthHalf, widthHalf, -heightHalf, heightHalf, nearPlane, farPlane);
|
projection = Math::Utils::orthoLH_ZO(-widthHalf, widthHalf, -heightHalf, heightHalf, nearPlane, farPlane);
|
||||||
UpdateViewProjectionMatrix();
|
UpdateViewProjectionMatrix();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ namespace openVulkanoCpp
|
|||||||
//TODO load materials
|
//TODO load materials
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitCube(float x = 1, float y = 1, float z = 1, glm::vec4 color = glm::vec4(1))
|
void InitCube(float x = 1, float y = 1, float z = 1, Math::Vector4f color = Math::Vector4f(1))
|
||||||
{
|
{
|
||||||
Init(24, 36);
|
Init(24, 36);
|
||||||
SetIndices(new uint32_t[indexCount]{
|
SetIndices(new uint32_t[indexCount]{
|
||||||
@@ -196,7 +196,7 @@ namespace openVulkanoCpp
|
|||||||
|
|
||||||
void Free()
|
void Free()
|
||||||
{
|
{
|
||||||
if(vertices) delete[] vertices;
|
delete[] vertices;
|
||||||
free(indices);
|
free(indices);
|
||||||
vertices = nullptr;
|
vertices = nullptr;
|
||||||
indices = nullptr;
|
indices = nullptr;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace openVulkanoCpp::Scene
|
|||||||
void Node::Init()
|
void Node::Init()
|
||||||
{
|
{
|
||||||
if (parent || scene || !children.empty() || !drawables.empty()) throw std::runtime_error("Node already initialized");
|
if (parent || scene || !children.empty() || !drawables.empty()) throw std::runtime_error("Node already initialized");
|
||||||
localMat = worldMat = glm::mat4x4(1);
|
localMat = worldMat = Math::Matrix4f(1);
|
||||||
enabled = true;
|
enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,13 +79,13 @@ namespace openVulkanoCpp::Scene
|
|||||||
Utils::Remove(drawables, drawable);
|
Utils::Remove(drawables, drawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::SetMatrix(glm::mat4x4 mat)
|
void Node::SetMatrix(const Math::Matrix4f& mat)
|
||||||
{
|
{
|
||||||
localMat = mat;
|
localMat = mat;
|
||||||
UpdateWorldMatrix(parent ? parent->GetWorldMatrix() : glm::mat4x4(1));
|
UpdateWorldMatrix(parent ? parent->GetWorldMatrix() : Math::Matrix4f(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::UpdateWorldMatrix(const glm::mat4x4& parentWorldMat)
|
void Node::UpdateWorldMatrix(const Math::Matrix4f& parentWorldMat)
|
||||||
{
|
{
|
||||||
worldMat = parentWorldMat * localMat;
|
worldMat = parentWorldMat * localMat;
|
||||||
for (const auto& node : children)
|
for (const auto& node : children)
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include "../Base/ICloseable.hpp"
|
#include "../Base/ICloseable.hpp"
|
||||||
|
#include "../Math/Math.hpp"
|
||||||
#include "Drawable.hpp"
|
#include "Drawable.hpp"
|
||||||
|
|
||||||
namespace openVulkanoCpp
|
namespace openVulkanoCpp
|
||||||
@@ -22,12 +22,12 @@ namespace openVulkanoCpp
|
|||||||
Always, Sometimes, Never
|
Always, Sometimes, Never
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Node : virtual IInitable, virtual ICloseable
|
class Node : public virtual IInitable, public virtual ICloseable
|
||||||
{
|
{
|
||||||
friend Scene;
|
friend Scene;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
glm::mat4x4 localMat, worldMat;
|
Math::Matrix4f localMat, worldMat;
|
||||||
bool enabled = true;
|
bool enabled = true;
|
||||||
Node* parent = nullptr;
|
Node* parent = nullptr;
|
||||||
Scene* scene = nullptr;
|
Scene* scene = nullptr;
|
||||||
@@ -57,11 +57,11 @@ namespace openVulkanoCpp
|
|||||||
|
|
||||||
void RemoveDrawable(Drawable* drawable);
|
void RemoveDrawable(Drawable* drawable);
|
||||||
|
|
||||||
void SetMatrix(glm::mat4x4 mat);
|
void SetMatrix(const Math::Matrix4f& mat);
|
||||||
|
|
||||||
[[nodiscard]] const glm::mat4x4& GetMatrix() const { return localMat; }
|
[[nodiscard]] const Math::Matrix4f& GetMatrix() const { return localMat; }
|
||||||
|
|
||||||
[[nodiscard]] const glm::mat4x4& GetWorldMatrix() const { return worldMat; }
|
[[nodiscard]] const Math::Matrix4f& GetWorldMatrix() const { return worldMat; }
|
||||||
|
|
||||||
[[nodiscard]] bool IsEnabled() const { return enabled; }
|
[[nodiscard]] bool IsEnabled() const { return enabled; }
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ namespace openVulkanoCpp
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void UpdateWorldMatrix(const glm::mat4x4& parentWorldMat);
|
virtual void UpdateWorldMatrix(const Math::Matrix4f& parentWorldMat);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SetParent(Node* parent);
|
void SetParent(Node* parent);
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
#include "../Math/Math.hpp"
|
||||||
#include <assimp/vector2.h>
|
#include <assimp/vector2.h>
|
||||||
#include <assimp/vector3.h>
|
#include <assimp/vector3.h>
|
||||||
#include <assimp/color4.h>
|
#include <assimp/color4.h>
|
||||||
@@ -8,8 +15,8 @@ namespace openVulkanoCpp
|
|||||||
{
|
{
|
||||||
struct Vertex
|
struct Vertex
|
||||||
{
|
{
|
||||||
glm::vec3 position, normal, tangent, biTangent, textureCoordinates;
|
Math::Vector3f position, normal, tangent, biTangent, textureCoordinates;
|
||||||
glm::vec4 color;
|
Math::Vector4f color;
|
||||||
|
|
||||||
Vertex() = default;
|
Vertex() = default;
|
||||||
|
|
||||||
@@ -20,11 +27,11 @@ namespace openVulkanoCpp
|
|||||||
: position({ x, y, z }), normal({ nx, ny, nz }), tangent(), biTangent(), textureCoordinates({ u, v, 0 }), color()
|
: position({ x, y, z }), normal({ nx, ny, nz }), tangent(), biTangent(), textureCoordinates({ u, v, 0 }), color()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Vertex(const glm::vec3& position, const glm::vec3& normal, const glm::vec3& tangent, const glm::vec3& biTangent, const glm::vec2& textureCoordinates)
|
Vertex(const Math::Vector3f& position, const Math::Vector3f& normal, const Math::Vector3f& tangent, const Math::Vector3f& biTangent, const Math::Vector2f& textureCoordinates)
|
||||||
: position(position), normal(normal), tangent(tangent), biTangent(biTangent), textureCoordinates(textureCoordinates, 0), color()
|
: position(position), normal(normal), tangent(tangent), biTangent(biTangent), textureCoordinates(textureCoordinates, 0), color()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Vertex(const glm::vec3 & position, const glm::vec3 & normal, const glm::vec3 & tangent, const glm::vec3 & biTangent, const glm::vec3 & textureCoordinates)
|
Vertex(const Math::Vector3f & position, const Math::Vector3f & normal, const Math::Vector3f & tangent, const Math::Vector3f & biTangent, const Math::Vector3f & textureCoordinates)
|
||||||
: position(position), normal(normal), tangent(tangent), biTangent(biTangent), textureCoordinates(textureCoordinates), color()
|
: position(position), normal(normal), tangent(tangent), biTangent(biTangent), textureCoordinates(textureCoordinates), color()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -35,7 +42,7 @@ namespace openVulkanoCpp
|
|||||||
position = { x, y, z };
|
position = { x, y, z };
|
||||||
}
|
}
|
||||||
|
|
||||||
void Set(const glm::vec3& position)
|
void Set(const Math::Vector3f& position)
|
||||||
{
|
{
|
||||||
this->position = position;
|
this->position = position;
|
||||||
}
|
}
|
||||||
@@ -52,14 +59,14 @@ namespace openVulkanoCpp
|
|||||||
this->textureCoordinates = { u, v, 0 };
|
this->textureCoordinates = { u, v, 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
void Set(const glm::vec3& position, const glm::vec3& normal, const glm::vec2& textureCoordinates)
|
void Set(const Math::Vector3f& position, const Math::Vector3f& normal, const Math::Vector2f& textureCoordinates)
|
||||||
{
|
{
|
||||||
this->position = position;
|
this->position = position;
|
||||||
this->normal = normal;
|
this->normal = normal;
|
||||||
this->textureCoordinates = { textureCoordinates, 0 };
|
this->textureCoordinates = { textureCoordinates, 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
void Set(const glm::vec3& position, const glm::vec3& normal, const glm::vec3& tangent, const glm::vec3& biTangent, const glm::vec2& textureCoordinates)
|
void Set(const Math::Vector3f& position, const Math::Vector3f& normal, const Math::Vector3f& tangent, const Math::Vector3f& biTangent, const Math::Vector2f& textureCoordinates)
|
||||||
{
|
{
|
||||||
this->position = position;
|
this->position = position;
|
||||||
this->normal = normal;
|
this->normal = normal;
|
||||||
@@ -73,7 +80,7 @@ namespace openVulkanoCpp
|
|||||||
this->normal = { nx, ny, nz };
|
this->normal = { nx, ny, nz };
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetNormal(const glm::vec3& normal)
|
void SetNormal(const Math::Vector3f& normal)
|
||||||
{
|
{
|
||||||
this->normal = normal;
|
this->normal = normal;
|
||||||
}
|
}
|
||||||
@@ -88,7 +95,7 @@ namespace openVulkanoCpp
|
|||||||
this->tangent = { tx, ty, tz };
|
this->tangent = { tx, ty, tz };
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetTangent(const glm::vec3& tangent)
|
void SetTangent(const Math::Vector3f& tangent)
|
||||||
{
|
{
|
||||||
this->tangent = tangent;
|
this->tangent = tangent;
|
||||||
}
|
}
|
||||||
@@ -104,7 +111,7 @@ namespace openVulkanoCpp
|
|||||||
this->tangent = { tx, ty, tz };
|
this->tangent = { tx, ty, tz };
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetTangentAndBiTangent(const glm::vec3& tangent, const glm::vec3& biTangent)
|
void SetTangentAndBiTangent(const Math::Vector3f& tangent, const Math::Vector3f& biTangent)
|
||||||
{
|
{
|
||||||
this->biTangent = biTangent;
|
this->biTangent = biTangent;
|
||||||
this->tangent = tangent;
|
this->tangent = tangent;
|
||||||
@@ -121,7 +128,7 @@ namespace openVulkanoCpp
|
|||||||
this->biTangent = { bx, by, bz };
|
this->biTangent = { bx, by, bz };
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetBiTangent(const glm::vec3& biTangent)
|
void SetBiTangent(const Math::Vector3f& biTangent)
|
||||||
{
|
{
|
||||||
this->biTangent = biTangent;
|
this->biTangent = biTangent;
|
||||||
}
|
}
|
||||||
@@ -141,12 +148,12 @@ namespace openVulkanoCpp
|
|||||||
this->textureCoordinates = { u, v, w };
|
this->textureCoordinates = { u, v, w };
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetTextureCoordinates(const glm::vec2& textureCoordinates)
|
void SetTextureCoordinates(const Math::Vector2f& textureCoordinates)
|
||||||
{
|
{
|
||||||
this->textureCoordinates = { textureCoordinates, 0 };
|
this->textureCoordinates = { textureCoordinates, 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetTextureCoordinates(const glm::vec3& textureCoordinates)
|
void SetTextureCoordinates(const Math::Vector3f& textureCoordinates)
|
||||||
{
|
{
|
||||||
this->textureCoordinates = textureCoordinates;
|
this->textureCoordinates = textureCoordinates;
|
||||||
}
|
}
|
||||||
@@ -166,7 +173,7 @@ namespace openVulkanoCpp
|
|||||||
color = { r,g,b,a };
|
color = { r,g,b,a };
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetColor(const glm::vec4& color)
|
void SetColor(const Math::Vector4f& color)
|
||||||
{
|
{
|
||||||
this->color = color;
|
this->color = color;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ namespace openVulkanoCpp::Vulkan
|
|||||||
UniformBuffer* uBuffer = new UniformBuffer();
|
UniformBuffer* uBuffer = new UniformBuffer();
|
||||||
ManagedBuffer* buffer;
|
ManagedBuffer* buffer;
|
||||||
VulkanNode* vkNode;
|
VulkanNode* vkNode;
|
||||||
const vk::DeviceSize allocSize = Utils::Align(sizeof(glm::mat4x4), uniformBufferAlignment);
|
const vk::DeviceSize allocSize = Utils::Align(sizeof(Math::Matrix4f), uniformBufferAlignment);
|
||||||
if (node->GetUpdateFrequency() != Scene::UpdateFrequency::Never)
|
if (node->GetUpdateFrequency() != Scene::UpdateFrequency::Never)
|
||||||
{
|
{
|
||||||
vkNode = new VulkanNodeDynamic();
|
vkNode = new VulkanNodeDynamic();
|
||||||
@@ -123,7 +123,7 @@ namespace openVulkanoCpp::Vulkan
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
vkNode = new VulkanNode();
|
vkNode = new VulkanNode();
|
||||||
buffer = CreateDeviceOnlyBufferWithData(sizeof(glm::mat4), vk::BufferUsageFlagBits::eUniformBuffer, &node->worldMat);
|
buffer = CreateDeviceOnlyBufferWithData(sizeof(Math::Matrix4f), vk::BufferUsageFlagBits::eUniformBuffer, &node->worldMat);
|
||||||
}
|
}
|
||||||
uBuffer->Init(buffer, allocSize, &context->pipeline.descriptorSetLayout, context->pipeline.pipelineLayout);
|
uBuffer->Init(buffer, allocSize, &context->pipeline.descriptorSetLayout, context->pipeline.pipelineLayout);
|
||||||
vkNode->Init(node, uBuffer);
|
vkNode->Init(node, uBuffer);
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace openVulkanoCpp
|
|||||||
if(bufferId != lastUpdate)
|
if(bufferId != lastUpdate)
|
||||||
{
|
{
|
||||||
lastUpdate = bufferId;
|
lastUpdate = bufferId;
|
||||||
buffer->Update(&node->worldMat, sizeof(glm::mat4x4), bufferId);
|
buffer->Update(&node->worldMat, sizeof(Math::Matrix4f), bufferId);
|
||||||
}
|
}
|
||||||
buffer->Record(cmdBuffer, bufferId);
|
buffer->Record(cmdBuffer, bufferId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user