diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/utils.cpp | 50 | ||||
| -rw-r--r-- | src/vec3.cpp | 14 |
2 files changed, 39 insertions, 25 deletions
diff --git a/src/utils.cpp b/src/utils.cpp index 6db101c..a754b1d 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -59,34 +59,34 @@ uint32_t random_scene(sphere *world) { uint32_t world_sphere_index = 1; int32_t spheres_count = 11; - // for (int a = -spheres_count; a < spheres_count; a++) { - // for (int b = -spheres_count; b < spheres_count; b++) { - // auto choose_mat = randd(); - // point3 center(a + 0.9 * randd(), 0.2, b + 0.9 * randd()); + for (int a = -spheres_count; a < spheres_count; a++) { + for (int b = -spheres_count; b < spheres_count; b++) { + auto choose_mat = randd(); + point3 center(a + 0.9 * randd(), 0.2, b + 0.9 * randd()); - // if ((center - point3{ 4, 0.2, 0 }).length() > 0.9) { - // material sphere_material = {}; + if ((center - point3{ 4, 0.2, 0 }).length() > 0.9) { + material sphere_material = {}; - // if (choose_mat < 0.8) { - // // diffuse - // sphere_material.albedo = color::random() * color::random(); - // sphere_material.type = MATERIAL_TYPE::LAMBERTIAN; - // } else if (choose_mat < 0.95) { - // // metal - // sphere_material.albedo = color::random(0.5, 1); - // sphere_material.fuzz = randd(0, 0.5); - // sphere_material.type = MATERIAL_TYPE::METAL; - // } else { - // // glass - // sphere_material.ior = 1.5; - // sphere_material.type = MATERIAL_TYPE::DIELECTRIC; - // } + if (choose_mat < 0.8) { + // diffuse + sphere_material.albedo = color::random() * color::random(); + sphere_material.type = MATERIAL_TYPE::LAMBERTIAN; + } else if (choose_mat < 0.95) { + // metal + sphere_material.albedo = color::random(0.5, 1); + sphere_material.fuzz = randd(0, 0.5); + sphere_material.type = MATERIAL_TYPE::METAL; + } else { + // glass + sphere_material.ior = 1.5; + sphere_material.type = MATERIAL_TYPE::DIELECTRIC; + } - // world[world_sphere_index] = { center, sphere_material, 0.2 }; - // world_sphere_index++; - // } - // } - // } + world[world_sphere_index] = { center, sphere_material, 0.2 }; + world_sphere_index++; + } + } + } material material1 = {}; material1.ior = 1.5; diff --git a/src/vec3.cpp b/src/vec3.cpp index 8e27a98..8f7a720 100644 --- a/src/vec3.cpp +++ b/src/vec3.cpp @@ -1,4 +1,5 @@ #include <cmath> +#include <limits.h> #include "vec3.hpp" #include "utils.hpp" @@ -40,6 +41,19 @@ vec3& vec3::operator/=(float numerator) { return *this; } +float vec3::operator[](int axis) { + switch (axis) { + case 0: + return x; + case 1: + return y; + case 2: + return z; + default: + return std::numeric_limits<float>::infinity(); + } +} + float vec3::length() const { return sqrt(length_sq()); } |
