Introduce Math.hpp and use typedef to make replacing glm with something else in the future simpler

This commit is contained in:
2020-10-27 23:25:26 +01:00
parent c219fc3778
commit 78d24fbe41
16 changed files with 268 additions and 181 deletions

View File

@@ -9,8 +9,7 @@
#include "../Scene/Shader.hpp"
#include "../Input/InputManager.hpp"
#include "../Host/GraphicsAppManager.hpp"
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
#include "../Math/Math.hpp"
#pragma clang diagnostic push
#pragma ide diagnostic ignored "cert-msc50-cpp"
@@ -18,6 +17,7 @@
using namespace openVulkanoCpp::Scene;
using namespace openVulkanoCpp::Input;
using namespace openVulkanoCpp::Math;
uint32_t GEOS = 3000, OBJECTS = 10000, DYNAMIC = 1000;
@@ -46,13 +46,13 @@ public:
scene.Init();
cam.Init(70, 16, 9, 0.1f, 100);
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");
drawablesPool.resize(GEOS);
for(int i = 0; i < GEOS; i++)
{
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);
}
nodesPool.resize(OBJECTS);
@@ -62,7 +62,7 @@ public:
scene.GetRoot()->AddChild(&nodesPool[i]);
if (i < DYNAMIC) nodesPool[i].SetUpdateFrequency(UpdateFrequency::Always);
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;
@@ -88,7 +88,7 @@ public:
}
float yaw = 0, pitch = 0;
glm::vec3 position = {0,0,-10};
Vector3f_SIMD position = {0,0,-10};
void Tick() override
{
@@ -98,10 +98,10 @@ public:
}
auto input = InputManager::GetInstace();
glm::vec3 vec(input->GetAxis(actionSide), 0, -input->GetAxis(actionForward));
if(glm::length2(vec) > 1)
Vector3f_SIMD vec(input->GetAxis(actionSide), 0, -input->GetAxis(actionForward));
if(Utils::length2(vec) > 1.0f)
{
vec = glm::normalize(vec);
vec = Utils::normalize(vec);
}
float tiemScale = 0.004f;
@@ -111,12 +111,12 @@ public:
yaw += input->GetAxis(actionLookSide) * tiemScale * 0.5f;
pitch += input->GetAxis(actionLookUp) * tiemScale * 0.5f;
glm::quat rot(glm::vec3(pitch, yaw, 0));
glm::mat4 rotMat = glm::toMat4(rot);
QuaternionF rot(Vector3f(pitch, yaw, 0));
Matrix4f rotMat = Utils::toMat4(rot);
vec = glm::vec3(rot * glm::vec4(vec, 1));
vec = Vector3f_SIMD(rotMat * Vector4f(vec, 1));
position += vec;
cam.SetMatrix(glm::translate(glm::mat4(1), position) * rotMat);
cam.SetMatrix(Utils::translate(Matrix4f(1), position) * rotMat);
}
void Close() override{}