Some refactoring.

This commit is contained in:
2022-02-27 23:45:20 +01:00
parent 14caf36c53
commit f03a0bd98b
23 changed files with 134 additions and 101 deletions

View File

@@ -1,6 +1,7 @@
#include <Planet.h>
#include <Logger.h>
#include <core/Logger.h>
#include <cassert>
#include <vector>

View File

@@ -1,6 +1,7 @@
#pragma once
#include <core.h>
#include <core/math.h>
#include <core/ArrayView.h>
#include <memory>
#include <cassert>

View File

@@ -1,6 +1,7 @@
#pragma once
#include <core.h>
#include <core/math.h>
#include <core/ArrayView.h>
class Simplex {

View File

@@ -1,7 +1,7 @@
#include <VkExpe.h>
#include <utils.h>
#include <Logger.h>
#include <core/utils.h>
#include <core/Logger.h>
#include <stdexcept>
#include <iostream>

View File

@@ -1,8 +1,9 @@
#pragma once
#include <core.h>
#include <VulkanTutorial.h>
#include <core/math.h>
#include <SDL2/SDL.h>
#include <memory>

View File

@@ -1,9 +1,10 @@
#include <VulkanTutorial.h>
#include <utils.h>
#include <Logger.h>
#include <Planet.h>
#include <core/utils.h>
#include <core/Logger.h>
#include <SDL2/SDL_vulkan.h>
#include <Eigen/Geometry>

View File

@@ -1,14 +1,17 @@
#pragma once
#include <core.h>
#include <vk/Context.h>
#include <vk/Swapchain.h>
#include <vk/Buffer.h>
#include <core/math.h>
#include <SDL2/SDL.h>
#include <vulkan/vulkan.h>
#include <Eigen/Dense>
#include <vector>
#include <chrono>

View File

@@ -1,51 +1,7 @@
#pragma once
#include <Eigen/Dense>
#include <type_traits>
using Byte = unsigned char;
using Index = uint32_t;
using Real = float;
using Vector2 = Eigen::Matrix<Real, 2, 1>;
using Vector3 = Eigen::Matrix<Real, 3, 1>;
using Vector4 = Eigen::Matrix<Real, 4, 1>;
using Matrix2 = Eigen::Matrix<Real, 2, 2>;
using Matrix3 = Eigen::Matrix<Real, 3, 3>;
using Matrix4 = Eigen::Matrix<Real, 4, 4>;
using Transform = Eigen::Transform<Real, 3, Eigen::Affine>;
using AngleAxis = Eigen::AngleAxis<Real>;
using Quaternion = Eigen::Quaternion<Real>;
using Triangle = Eigen::Array<Index, 3, 1>;
template<typename Scalar, typename Derived0, typename Derived1>
auto lerp(
Scalar factor,
const Eigen::MatrixBase<Derived0>& m0,
const Eigen::MatrixBase<Derived1>& m1
) -> std::enable_if_t<
Derived0::RowsAtCompileTime == Derived1::RowsAtCompileTime &&
Derived0::ColsAtCompileTime == Derived1::ColsAtCompileTime,
Eigen::Matrix<
std::common_type_t<
Scalar,
typename Derived0::Scalar,
typename Derived1::Scalar
>,
Derived0::RowsAtCompileTime,
Derived0::ColsAtCompileTime
>
> {
return (Scalar(1) - factor) * m0 + factor * m1;
}
#include <core/types.h>
template<typename T>

View File

@@ -1,4 +1,4 @@
#include <Logger.h>
#include <core/Logger.h>
#include <iostream>

View File

@@ -1,28 +1,5 @@
#include <utils.h>
#include <core/math.h>
#include <cstring>
#include <fstream>
Uuid make_uuid(uint8_t const* bytes) {
Uuid uuid;
std::memcpy(uuid.data(), bytes, UUID_SIZE);
return uuid;
}
std::vector<char> read_binary_file(const char* path) {
std::ifstream istream(path, std::ios_base::ate | std::ios_base::binary);
if(!istream.is_open())
throw std::runtime_error(cat("failed to open '", path, "'"));
std::vector<char> buffer(size_t(istream.tellg()));
istream.seekg(0);
istream.read(buffer.data(), buffer.size());
istream.close();
return buffer;
}
Eigen::Matrix4f projection_matrix(float x_min, float x_max, float y_min, float y_max, float z_min, float z_max) {
auto const cx = x_max + x_min;

54
src/core/math.h Normal file
View File

@@ -0,0 +1,54 @@
#pragma once
#include <core/types.h>
#include <Eigen/Dense>
#include <type_traits>
using Real = float;
using Vector2 = Eigen::Matrix<Real, 2, 1>;
using Vector3 = Eigen::Matrix<Real, 3, 1>;
using Vector4 = Eigen::Matrix<Real, 4, 1>;
using Matrix2 = Eigen::Matrix<Real, 2, 2>;
using Matrix3 = Eigen::Matrix<Real, 3, 3>;
using Matrix4 = Eigen::Matrix<Real, 4, 4>;
using Transform = Eigen::Transform<Real, 3, Eigen::Affine>;
using AngleAxis = Eigen::AngleAxis<Real>;
using Quaternion = Eigen::Quaternion<Real>;
using Triangle = Eigen::Array<Index, 3, 1>;
template<typename Scalar, typename Derived0, typename Derived1>
auto lerp(
Scalar factor,
const Eigen::MatrixBase<Derived0>& m0,
const Eigen::MatrixBase<Derived1>& m1
) -> std::enable_if_t<
Derived0::RowsAtCompileTime == Derived1::RowsAtCompileTime &&
Derived0::ColsAtCompileTime == Derived1::ColsAtCompileTime,
Eigen::Matrix<
std::common_type_t<
Scalar,
typename Derived0::Scalar,
typename Derived1::Scalar
>,
Derived0::RowsAtCompileTime,
Derived0::ColsAtCompileTime
>
> {
return (Scalar(1) - factor) * m0 + factor * m1;
}
Eigen::Matrix4f projection_matrix(float x_min, float x_max, float y_min, float y_max, float z_min, float z_max);
Eigen::Matrix4f look_at_matrix(
const Eigen::Vector3f& cam_pos,
const Eigen::Vector3f& look_at,
const Eigen::Vector3f& up
);

10
src/core/types.h Normal file
View File

@@ -0,0 +1,10 @@
#pragma once
#include <Eigen/Dense>
#include <type_traits>
using Byte = unsigned char;
using Index = uint32_t;

26
src/core/utils.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include <core/utils.h>
#include <cstring>
#include <fstream>
Uuid make_uuid(uint8_t const* bytes) {
Uuid uuid;
std::memcpy(uuid.data(), bytes, UUID_SIZE);
return uuid;
}
std::vector<char> read_binary_file(const char* path) {
std::ifstream istream(path, std::ios_base::ate | std::ios_base::binary);
if(!istream.is_open())
throw std::runtime_error(cat("failed to open '", path, "'"));
std::vector<char> buffer(size_t(istream.tellg()));
istream.seekg(0);
istream.read(buffer.data(), buffer.size());
istream.close();
return buffer;
}

View File

@@ -1,7 +1,5 @@
#pragma once
#include <Eigen/Dense>
#include <cassert>
#include <vector>
#include <string>
@@ -33,6 +31,7 @@ Guard<T> make_guard(T&& teardown) {
return Guard<T>(std::move(teardown));
}
template<typename... Args>
std::string cat(Args&&... args) {
std::ostringstream ostream;
@@ -40,8 +39,10 @@ std::string cat(Args&&... args) {
return ostream.str();
}
std::vector<char> read_binary_file(const char* path);
template<typename T>
class Array {
public:
@@ -76,10 +77,3 @@ private:
size_t m_size = 0;
T* m_data = nullptr;
};
Eigen::Matrix4f projection_matrix(float x_min, float x_max, float y_min, float y_max, float z_min, float z_max);
Eigen::Matrix4f look_at_matrix(
const Eigen::Vector3f& cam_pos,
const Eigen::Vector3f& look_at,
const Eigen::Vector3f& up
);

View File

@@ -1,6 +1,7 @@
#include <Logger.h>
#include <VkExpe.h>
#include <core/Logger.h>
int main(int argc, char** argv) {
VkExpe vk_expe(argc, argv);

View File

@@ -1,6 +1,7 @@
#include <vk/Buffer.h>
#include <vk/Context.h>
#include <Logger.h>
#include <core/Logger.h>
#include <stdexcept>
#include <algorithm>

View File

@@ -1,10 +1,10 @@
#pragma once
#include <utils.h>
#include <vk/forward.h>
#include <vk/Memory.h>
#include <core/utils.h>
#include <vulkan/vulkan.h>
#include <memory>

View File

@@ -1,8 +1,8 @@
#include <vk/Context.h>
#include <vk/Memory.h>
#include <utils.h>
#include <Logger.h>
#include <core/utils.h>
#include <core/Logger.h>
#include <SDL2/SDL_vulkan.h>

View File

@@ -1,10 +1,12 @@
#pragma once
#include <utils.h>
#include <Logger.h>
#include <vk/forward.h>
#include <core/utils.h>
#include <core/Logger.h>
#include <SDL2/SDL.h>
#include <vulkan/vulkan.h>
#include <optional>

View File

@@ -1,6 +1,6 @@
#include <vk/Swapchain.h>
#include <Logger.h>
#include <core/Logger.h>
#include <SDL2/SDL_vulkan.h>

View File

@@ -1,9 +1,11 @@
#pragma once
#include <vk/Context.h>
#include <utils.h>
#include <core/utils.h>
#include <SDL2/SDL.h>
#include <vulkan/vulkan.h>
#include <optional>