-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriangle.hh
47 lines (40 loc) · 1.54 KB
/
triangle.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include <cmath>
#include "hitable.hh"
// #include "material.hxx"
namespace partou
{
class Triangle : public Hitable
{
public:
Triangle() = default; // should never be used actually
Triangle(const math::Vec3f& v0,
const math::Vec3f& v1,
const math::Vec3f& v2,
std::shared_ptr<Material> matp = nullptr);
Triangle(const math::Vec3f& v0,
const math::Vec3f& v1,
const math::Vec3f& v2,
const math::Vec3f& vn0,
const math::Vec3f& vn1,
const math::Vec3f& vn2,
std::shared_ptr<Material> matp = nullptr);
auto hit(const Ray& r, const math::Float t_min, const math::Float t_max, hit_info& info) const
-> bool final override;
auto transformModel(const math::spatial::Transform& tModel) -> void final override;
auto pdf_value(const math::Point3f& origin, const math::Vec3f& dir) const
-> math::Float final override;
auto random(const math::Point3f& origin) const -> math::Vec3f final override;
auto precomputeValues() -> void;
auto computeBoundingBox() -> void;
auto interpolatedNormal(const math::Vec2f& st) const -> math::Vec3f;
// protected:
// underscore at the end of the name means it'll be precomputed (for example, in the constructor)
math::Float area_;
math::Vec3f v0, v1, v2;
math::Vec3f E01_, E02_; // precomputed barycentric axis
// math::Vec3f normal_; // precomputed normal of the plane in which the triangle resides
math::Vec3f vn0, vn1, vn2;
std::shared_ptr<Material> mat_ptr;
};
} // namespace partou