From 3ae3ae7e6d514abefef12be67939b2945af0c1f0 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Wed, 25 Sep 2024 10:40:38 +0200 Subject: [PATCH] Remove hardcoded PI constant, remove const in declarations --- include/scene.h | 14 +++++++------- src/scene.cpp | 12 +++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/include/scene.h b/include/scene.h index 8ce23ad..fe8093b 100644 --- a/include/scene.h +++ b/include/scene.h @@ -26,8 +26,8 @@ struct TriangleBox { struct Object; -glm::vec3 fetch_position(const Object& object, const tinyobj::mesh_t& mesh, const int32_t index, const int32_t vertex); -glm::vec3 fetch_normal(const Object& object, const tinyobj::mesh_t& mesh, const int32_t index, const int32_t vertex); +glm::vec3 fetch_position(const Object& object, const tinyobj::mesh_t& mesh, int32_t index, int32_t vertex); +glm::vec3 fetch_normal(const Object& object, const tinyobj::mesh_t& mesh, int32_t index, int32_t vertex); struct Object { glm::vec3 position = glm::vec3(0); @@ -48,7 +48,7 @@ struct Object { const glm::vec3 v1 = fetch_position(*this, shape.mesh, i, 1); const glm::vec3 v2 = fetch_position(*this, shape.mesh, i, 2); - AABB extent; + AABB extent{}; extent.min = glm::min(v0, v1); extent.min = glm::min(extent.min, v2); @@ -101,13 +101,13 @@ struct HitResult { const Object* object = nullptr; }; -std::optional test_mesh(const Ray ray, const Object& object, const tinyobj::mesh_t& mesh, float& tClosest); -std::optional test_scene(const Ray ray, const Scene& scene); -std::optional test_scene_octree(const Ray ray, const Scene& scene); +std::optional test_mesh(Ray ray, const Object& object, const tinyobj::mesh_t& mesh, float& tClosest); +std::optional test_scene(Ray ray, const Scene& scene); +std::optional test_scene_octree(Ray ray, const Scene& scene); struct SceneResult { HitResult hit; glm::vec3 direct, indirect, reflect, combined; }; -std::optional cast_scene(const Ray ray, Scene& scene, const bool use_bvh, const int depth = 0); +std::optional cast_scene(Ray ray, Scene& scene, bool use_bvh, int depth = 0); diff --git a/src/scene.cpp b/src/scene.cpp index 602d605..e83c563 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -1,9 +1,7 @@ #include "scene.h" #include -#include - -constexpr double pi = 3.14159265358979323846l; +#include glm::vec3 fetch_position(const Object& object, const tinyobj::mesh_t& mesh, const int32_t index, const int32_t vertex) { const tinyobj::index_t idx = mesh.indices[(index * 3) + vertex]; @@ -12,7 +10,7 @@ glm::vec3 fetch_position(const Object& object, const tinyobj::mesh_t& mesh, cons const auto vy = object.attrib.vertices[3 * idx.vertex_index + 1]; const auto vz = object.attrib.vertices[3 * idx.vertex_index + 2]; - return glm::vec3(vx, vy, vz); + return {vx, vy, vz}; } glm::vec3 fetch_normal(const Object& object, const tinyobj::mesh_t& mesh, const int32_t index, const int32_t vertex) { @@ -22,7 +20,7 @@ glm::vec3 fetch_normal(const Object& object, const tinyobj::mesh_t& mesh, const const auto ny = object.attrib.normals[3 * idx.normal_index + 1]; const auto nz = object.attrib.normals[3 * idx.normal_index + 2]; - return glm::vec3(nx, ny, nz); + return {nx, ny, nz}; } bool test_triangle( @@ -178,7 +176,7 @@ std::pair orthogonal_system(const glm::vec3& v1) { glm::vec3 hemisphere(const double u1, const double u2) { const double r = sqrt(1.0 - u1 * u1); - const double phi = 2 * pi * u2; + const double phi = 2 * std::numbers::pi * u2; return {cos(phi) * r, sin(phi) * r, u1}; } @@ -218,7 +216,7 @@ std::optional cast_scene(const Ray ray, Scene& scene, const bool us // and naive monte carlo without PDF if (num_indirect_samples > 0) { for (int i = 0; i < num_indirect_samples; i++) { - const float theta = scene.distribution() * pi; + const float theta = scene.distribution() * std::numbers::pi; const float cos_theta = cos(theta); const float sin_theta = sin(theta);