Add box.
This commit is contained in:
parent
085a9fcce8
commit
7c4872c4e2
4
Makefile
4
Makefile
@ -2,8 +2,8 @@ CXX = g++
|
||||
|
||||
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
|
||||
OBJ = main.o material.o vec3.o lodepng.o sphere.o moving_sphere.o bvh.o aarect.o hittable_list.o
|
||||
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 box.h
|
||||
OBJ = main.o material.o vec3.o lodepng.o sphere.o moving_sphere.o bvh.o aarect.o box.o hittable_list.o
|
||||
|
||||
TARGET = toytracer
|
||||
|
||||
|
25
box.cpp
Normal file
25
box.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include "box.h"
|
||||
#include "aarect.h"
|
||||
|
||||
Box::Box(const Point3& p0, const Point3& p1, std::shared_ptr<Material> ptr) {
|
||||
box_min = p0;
|
||||
box_max = p1;
|
||||
|
||||
sides.add(std::make_shared<Xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p1.z(), ptr));
|
||||
sides.add(std::make_shared<Flip_face>(std::make_shared<Xy_rect>(p0.x(), p1.x(), p0.y(), p1.y(), p0.z(), ptr)));
|
||||
|
||||
sides.add(std::make_shared<Xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p1.y(), ptr));
|
||||
sides.add(std::make_shared<Flip_face>(std::make_shared<Xz_rect>(p0.x(), p1.x(), p0.z(), p1.z(), p0.y(), ptr)));
|
||||
|
||||
sides.add(std::make_shared<Yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p1.x(), ptr));
|
||||
sides.add(std::make_shared<Flip_face>(std::make_shared<Yz_rect>(p0.y(), p1.y(), p0.z(), p1.z(), p0.x(), ptr)));
|
||||
}
|
||||
|
||||
bool Box::hit(const Ray& r, double t0, double t1, hit_record& rec) const {
|
||||
return sides.hit(r, t0, t1, rec);
|
||||
}
|
||||
|
||||
bool Box::bounding_box(double t0, double t1, Aabb& output_box) const {
|
||||
output_box = Aabb(box_min, box_max);
|
||||
return true;
|
||||
}
|
24
box.h
Normal file
24
box.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef BOX_H
|
||||
#define BOX_H
|
||||
|
||||
#include "vec3.h"
|
||||
#include "hittable.h"
|
||||
#include "hittable_list.h"
|
||||
|
||||
class Box : public Hittable {
|
||||
public:
|
||||
Box() {}
|
||||
|
||||
Box(const Point3& p0, const Point3& p1, std::shared_ptr<Material> ptr);
|
||||
|
||||
virtual bool hit(const Ray& r, double t0, double t1, hit_record& rec) const;
|
||||
|
||||
virtual bool bounding_box(double t0, double t1, Aabb& output_box) const;
|
||||
|
||||
private:
|
||||
Point3 box_min;
|
||||
Point3 box_max;
|
||||
Hittable_list sides;
|
||||
};
|
||||
|
||||
#endif // BOX_H
|
Loading…
Reference in New Issue
Block a user