diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/aabb.hpp | 16 | ||||
| -rw-r--r-- | include/gltf.hpp | 32 | ||||
| -rw-r--r-- | include/scene.hpp | 5 | ||||
| -rw-r--r-- | include/utils.hpp | 6 | ||||
| -rw-r--r-- | include/vec3.hpp | 1 |
5 files changed, 29 insertions, 31 deletions
diff --git a/include/aabb.hpp b/include/aabb.hpp index 475c04e..85b3c21 100644 --- a/include/aabb.hpp +++ b/include/aabb.hpp @@ -4,7 +4,7 @@ #include "vec3.hpp"
#include "triangle.hpp"
#include <cmath>
-#include <limits.h>
+#include <climits>
class aabb {
public:
@@ -36,27 +36,27 @@ class aabb { maximum.max(point);
}
- int32_t maximum_axis() {
+ int32_t maximum_axis() const {
vec3 diag = diagonal();
if (diag.v[0] > diag.v[1] && diag.v[0] > diag.v[2]) {
return 0;
- } else if (diag.v[1] > diag.v[2]) {
+ }
+ if (diag.v[1] > diag.v[2]) {
return 1;
- } else {
- return 2;
}
+ return 2;
}
- vec3 diagonal() {
+ vec3 diagonal() const {
return maximum - minimum;
}
- vec3 center() {
+ vec3 center() const {
return diagonal() / 2.f;
}
- float surface_area() {
+ float surface_area() const {
auto diag = diagonal();
return 2.f * (diag.v[0] * diag.v[1] + diag.v[0] * diag.v[2] + diag.v[1] * diag.v[2]);
}
diff --git a/include/gltf.hpp b/include/gltf.hpp index 7df5e7a..0364ca8 100644 --- a/include/gltf.hpp +++ b/include/gltf.hpp @@ -10,46 +10,46 @@ using json = nlohmann::json;
#include "material.hpp"
-#include "vec3.hpp"
#include "vk-renderer.hpp"
struct mesh_part {
- std::vector<uint16_t> indices;
- std::vector<float> positions;
- std::vector<float> normals;
- std::vector<float> uvs;
- material mat;
- uint32_t triangles_count = 0;
- uint32_t vertices_count = 0;
+ std::vector<uint16_t> indices;
+ std::vector<float> positions;
+ std::vector<float> normals;
+ std::vector<float> uvs;
+ material mat;
+ uint32_t triangles_count = 0;
+ uint32_t vertices_count = 0;
};
struct mesh {
std::vector<mesh_part> parts;
- uint32_t triangles_count = 0;
- uint32_t vertices_count = 0;
+ uint32_t triangles_count = 0;
+ uint32_t vertices_count = 0;
};
struct node {
- std::vector<node> children;
+ std::vector<node> children;
std::optional<mesh> mesh;
};
class gltf {
-public:
+ public:
static node load(std::filesystem::path &path, std::string &filename, vkrenderer &renderer);
-private:
-
+ private:
static void load_node(json &gltf_json, uint32_t index, node &parent, std::vector<mesh> &meshes);
- static std::vector<mesh> load_meshes(json &gltf_json, std::vector<std::vector<uint8_t>> &buffers_content, std::vector<material> &materials);
+ static std::vector<mesh> load_meshes(
+ json &gltf_json, std::vector<std::vector<uint8_t>> &buffers_content, std::vector<material> &materials);
static std::vector<texture> load_textures(json &gltf_json, std::filesystem::path &path, vkrenderer &renderer);
static std::vector<material> load_materials(json &gltf_json, std::vector<texture> &textures);
- static mesh_part load_primitive(json &gltf_json, json &primitive, std::vector<std::vector<uint8_t>> &buffers_content, std::vector<material> &materials);
+ static mesh_part load_primitive(json &gltf_json, json &primitive,
+ std::vector<std::vector<uint8_t>> &buffers_content, std::vector<material> &materials);
};
#endif
diff --git a/include/scene.hpp b/include/scene.hpp index 4bce1a7..8e47ab0 100644 --- a/include/scene.hpp +++ b/include/scene.hpp @@ -1,9 +1,6 @@ #ifndef __SCENE_HPP_
#define __SCENE_HPP_
-#include "vec3.hpp"
-#include "sphere.hpp"
-#include "triangle.hpp"
#include "camera.hpp"
#include "bvh-node.hpp"
@@ -26,7 +23,7 @@ class scene { int32_t downscale_factor = 1;
metadata(camera cam, uint32_t width, uint32_t height)
- : cam(cam), width(width), height(height) {}
+ : cam(std::move(cam)), width(width), height(height) {}
};
// void random_scene();
diff --git a/include/utils.hpp b/include/utils.hpp index 8548a5f..201976f 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -12,11 +12,11 @@ std::vector<uint8_t> read_file(std::string& path); #define EPSILON 0.000001 inline float deg_to_rad(float deg) { - return deg * PI / 180.0; + return deg * PI / 180.f; } inline float randd() { - return rand() / (RAND_MAX + 1.0); + return rand() / (RAND_MAX + 1.f); } inline float randd(float min, float max) { @@ -24,7 +24,7 @@ inline float randd(float min, float max) { } inline int32_t randi(int32_t min, int32_t max) { - return static_cast<int32_t>(randd(min, max + 1)); + return (int32_t)(randd(min, max + 1.f)); } inline float clamp(float x, float min, float max) { diff --git a/include/vec3.hpp b/include/vec3.hpp index 429d747..0250345 100644 --- a/include/vec3.hpp +++ b/include/vec3.hpp @@ -13,6 +13,7 @@ class vec3 { vec3(__m128& v); vec3(__m128&& v); vec3(const vec3& vec); + vec3(const vec3&& vec); vec3 operator-() const; |
