Moving hittable_list methods to cpp file.

This commit is contained in:
Faerbit 2020-06-13 22:21:27 +02:00
parent af86494d89
commit 085a9fcce8
3 changed files with 47 additions and 47 deletions

View File

@ -3,7 +3,7 @@ CXX = g++
CXXFLAGS = -std=c++20 -Wall -Wextra -Wno-unused-parameter -march=native -O3 -flto -fopenmp CXXFLAGS = -std=c++20 -Wall -Wextra -Wno-unused-parameter -march=native -O3 -flto -fopenmp
DEPS = util.h vec3.h color.h ray.h camera.h hittable.h hittable_list.h sphere.h material.h lodepng.h moving_sphere.h bvh.h aabb.h texture.h aarect.h DEPS = util.h vec3.h color.h ray.h camera.h hittable.h hittable_list.h sphere.h material.h lodepng.h moving_sphere.h bvh.h aabb.h texture.h aarect.h
OBJ = main.o material.o vec3.o lodepng.o sphere.o moving_sphere.o bvh.o aarect.o OBJ = main.o material.o vec3.o lodepng.o sphere.o moving_sphere.o bvh.o aarect.o hittable_list.o
TARGET = toytracer TARGET = toytracer

35
hittable_list.cpp Normal file
View File

@ -0,0 +1,35 @@
#include "hittable_list.h"
bool Hittable_list::hit(const Ray &r, double tmin, double tmax, hit_record &rec) const {
hit_record temp_rec;
bool hit_anything = false;
auto closest_so_far = tmax;
for (const auto& object : objects) {
if (object->hit(r, tmin, closest_so_far, temp_rec)) {
hit_anything = true;
closest_so_far = temp_rec.t;
rec = temp_rec;
}
}
return hit_anything;
}
bool Hittable_list::bounding_box(double t0, double t1, Aabb& output_box) const {
if (objects.empty()) return false;
Aabb temp_box;
bool first_box = true;
for (const auto& object : objects) {
if (!object->bounding_box(t0, t1, temp_box)) return false;
output_box = first_box ? temp_box : surrounding_box(output_box, temp_box);
first_box = false;
}
return true;
}
Bvh_node Hittable_list::generate_bvh(double t0, double t1) {
return Bvh_node(objects, 0, objects.size(), t0, t1);
}

View File

@ -4,8 +4,8 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "hittable.h"
#include "bvh.h" #include "bvh.h"
#include "hittable.h"
class Hittable_list : public Hittable { class Hittable_list : public Hittable {
public: public:
@ -22,41 +22,6 @@ public:
private: private:
std::vector<std::shared_ptr<Hittable>> objects; std::vector<std::shared_ptr<Hittable>> objects;
}; };
bool Hittable_list::hit(const Ray &r, double tmin, double tmax, hit_record &rec) const {
hit_record temp_rec;
bool hit_anything = false;
auto closest_so_far = tmax;
for (const auto& object : objects) {
if (object->hit(r, tmin, closest_so_far, temp_rec)) {
hit_anything = true;
closest_so_far = temp_rec.t;
rec = temp_rec;
}
}
return hit_anything;
}
bool Hittable_list::bounding_box(double t0, double t1, Aabb& output_box) const {
if (objects.empty()) return false;
Aabb temp_box;
bool first_box = true;
for (const auto& object : objects) {
if (!object->bounding_box(t0, t1, temp_box)) return false;
output_box = first_box ? temp_box : surrounding_box(output_box, temp_box);
first_box = false;
}
return true;
}
Bvh_node Hittable_list::generate_bvh(double t0, double t1) {
return Bvh_node(objects, 0, objects.size(), t0, t1);
}
#endif // HITTABLE_LIST_H #endif // HITTABLE_LIST_H