25 RGB(): r(0.0),g(0.0),b(0.0){}
26 RGB(
double r,
double g,
double b): r(r),g(g),b(b){}
27 bool operator==(
const RGB& other)
const {
28 return (r == other.r && g == other.g && b == other.b);
30 RGB operator-(
const RGB& other)
const {
31 return RGB(r-other.r,g-other.g,b-other.b);
33 RGB operator*(
const RGB& other)
const {
34 return RGB(r*other.r,g*other.g,b*other.b);
45 RGBA(): r(0.0),g(0.0),b(0.0),a(0.0){}
46 RGBA(
double r,
double g,
double b,
double a): r(r),g(g),b(b),a(a){}
47 RGBA operator+(
const RGBA& other)
const {
48 return RGBA(r+other.r,g+other.g,b+other.b,a+other.a);
51 return RGBA(rgb.r*other.r,rgb.g*other.g,rgb.b*other.b,other.a);
54 return RGBA(r/aa,g/aa,b/aa,a/aa);
74 Ray(
double x,
double y);
75 Ray(
point3 eye,
vec3 dir,
int bounce): eye(eye), dir(dir.normalize()),bounce(bounce){}
95 float x_min,x_max,y_min,y_max,z_min,z_max;
97 x_min = std::min({a.x,b.x,c.x});x_max = std::max({a.x,b.x,c.x});
98 y_min = std::min({a.y,b.y,c.y});y_max = std::max({a.y,b.y,c.y});
99 z_min = std::min({a.z,b.z,c.z});z_max = std::max({a.z,b.z,c.z});
102 if(x.size() < 0.01) x = x.expand(0.01);
103 if(y.size() < 0.01) y = y.
expand(0.01);
104 if(z.size() < 0.01) z = z.
expand(0.01);
108 x =
Interval(std::min(a.x.min,b.x.min),std::max(a.x.max,b.x.max));
109 y =
Interval(std::min(a.y.min,b.y.min),std::max(a.y.max,b.y.max));
110 z =
Interval(std::min(a.z.min,b.z.min),std::max(a.z.max,b.z.max));
113 const Interval& getAxis(
int n)
const {
114 if (n == 0)
return x;
115 if (n == 1)
return y;
119 int longestAxis()
const {
120 if (x.size() > y.size())
121 return x.size() > z.size() ? 0 : 2;
123 return y.size() > z.size() ? 1 : 2;
127 bool hit(
const Ray& r)
const {
128 const point3& ray_eye = r.eye;
129 const vec3& ray_dir = r.dir;
131 double t_min = double(-INFINITY);
132 double t_max = double(INFINITY);
134 for (
int axis = 0; axis < 3; axis++) {
136 if (ax.min > ax.max)
return false;
138 const double adinv = 1.0 / ray_dir[axis];
140 double t0 = (ax.min - ray_eye[axis]) * adinv;
141 double t1 = (ax.max - ray_eye[axis]) * adinv;
143 if (t0 > t1) std::swap(t0, t1);
145 t_min = std::max(t_min, t0);
146 t_max = std::min(t_max, t1);
Definition: struct.hpp:79
Definition: interval.hpp:21
Interval expand(double delta) const
Expand the interval by delta on both ends.
Definition: interval.hpp:55
Definition: struct.hpp:39
Definition: struct.hpp:20
Class Ray, consists of a eye and direction.
Definition: struct.hpp:68
Definition: struct.hpp:60