|
892 | 892 | sphere() {}
|
893 | 893 | sphere(point3 ctr, double r) : center(ctr), radius(r) {};
|
894 | 894 |
|
895 |
| - virtual bool hit(const ray& r, double ray_tmin, double ray_tmax, hit_record& rec) |
896 |
| - const override; |
| 895 | + bool hit(const ray& r, double ray_tmin, double ray_tmax, hit_record& rec) const override; |
897 | 896 |
|
898 | 897 | public:
|
899 | 898 | point3 center;
|
|
1067 | 1066 | void clear() { objects.clear(); }
|
1068 | 1067 | void add(shared_ptr<hittable> object) { objects.push_back(object); }
|
1069 | 1068 |
|
1070 |
| - virtual bool hit(const ray& r, double ray_tmin, double ray_tmax, hit_record& rec) |
1071 |
| - const override; |
| 1069 | + bool hit(const ray& r, double ray_tmin, double ray_tmax, hit_record& rec) const override; |
1072 | 1070 |
|
1073 | 1071 | public:
|
1074 | 1072 | std::vector<shared_ptr<hittable>> objects;
|
|
1326 | 1324 | class hittable_list : public hittable {
|
1327 | 1325 | ...
|
1328 | 1326 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
1329 |
| - virtual bool hit(const ray& r, interval ray_t, hit_record& rec) const override; |
| 1327 | + bool hit(const ray& r, interval ray_t, hit_record& rec) const override; |
1330 | 1328 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
1331 | 1329 | ...
|
1332 | 1330 | };
|
|
1362 | 1360 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
1363 | 1361 | class sphere : public hittable {
|
1364 | 1362 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
1365 |
| - virtual bool hit(const ray& r, interval ray_t, hit_record& rec) const override; |
| 1363 | + bool hit(const ray& r, interval ray_t, hit_record& rec) const override; |
1366 | 1364 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
1367 | 1365 | ...
|
1368 | 1366 | };
|
|
2106 | 2104 | : center(ctr), radius(r), mat_ptr(m) {};
|
2107 | 2105 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
2108 | 2106 |
|
2109 |
| - virtual bool hit(const ray& r, interval ray_t, hit_record& rec) const override; |
| 2107 | + bool hit(const ray& r, interval ray_t, hit_record& rec) const override; |
2110 | 2108 |
|
2111 | 2109 | public:
|
2112 | 2110 | point3 center;
|
|
2146 | 2144 | public:
|
2147 | 2145 | lambertian(const color& a) : albedo(a) {}
|
2148 | 2146 |
|
2149 |
| - virtual bool scatter( |
2150 |
| - const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered |
2151 |
| - ) const override { |
| 2147 | + bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) |
| 2148 | + const override { |
2152 | 2149 | auto scatter_direction = rec.normal + random_unit_vector();
|
2153 | 2150 | scattered = ray(rec.p, scatter_direction);
|
2154 | 2151 | attenuation = albedo;
|
|
2192 | 2189 | public:
|
2193 | 2190 | lambertian(const color& a) : albedo(a) {}
|
2194 | 2191 |
|
2195 |
| - virtual bool scatter( |
2196 |
| - const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered |
2197 |
| - ) const override { |
| 2192 | + bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) |
| 2193 | + const override { |
2198 | 2194 | auto scatter_direction = rec.normal + random_unit_vector();
|
2199 | 2195 |
|
2200 | 2196 |
|
|
2248 | 2244 | public:
|
2249 | 2245 | metal(const color& a) : albedo(a) {}
|
2250 | 2246 |
|
2251 |
| - virtual bool scatter( |
2252 |
| - const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered |
2253 |
| - ) const override { |
| 2247 | + bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) |
| 2248 | + const override { |
2254 | 2249 | vec3 reflected = reflect(unit_vector(r_in.direction()), rec.normal);
|
2255 | 2250 | scattered = ray(rec.p, reflected);
|
2256 | 2251 | attenuation = albedo;
|
|
2395 | 2390 | metal(const color& a, double f) : albedo(a), fuzz(f < 1 ? f : 1) {}
|
2396 | 2391 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
|
2397 | 2392 |
|
2398 |
| - virtual bool scatter( |
2399 |
| - const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered |
2400 |
| - ) const override { |
| 2393 | + bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) |
| 2394 | + const override { |
2401 | 2395 | vec3 reflected = reflect(unit_vector(r_in.direction()), rec.normal);
|
2402 | 2396 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
|
2403 | 2397 | scattered = ray(rec.p, reflected + fuzz*random_in_unit_sphere());
|
|
2533 | 2527 | public:
|
2534 | 2528 | dielectric(double index_of_refraction) : ir(index_of_refraction) {}
|
2535 | 2529 |
|
2536 |
| - virtual bool scatter( |
2537 |
| - const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered |
2538 |
| - ) const override { |
| 2530 | + bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) |
| 2531 | + const override { |
2539 | 2532 | attenuation = color(1.0, 1.0, 1.0);
|
2540 | 2533 | double refraction_ratio = rec.front_face ? (1.0/ir) : ir;
|
2541 | 2534 |
|
|
2645 | 2638 | public:
|
2646 | 2639 | dielectric(double index_of_refraction) : ir(index_of_refraction) {}
|
2647 | 2640 |
|
2648 |
| - virtual bool scatter( |
2649 |
| - const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered |
2650 |
| - ) const override { |
| 2641 | + bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) |
| 2642 | + const override { |
2651 | 2643 | attenuation = color(1.0, 1.0, 1.0);
|
2652 | 2644 | double refraction_ratio = rec.front_face ? (1.0/ir) : ir;
|
2653 | 2645 |
|
|
2709 | 2701 | public:
|
2710 | 2702 | dielectric(double index_of_refraction) : ir(index_of_refraction) {}
|
2711 | 2703 |
|
2712 |
| - virtual bool scatter( |
2713 |
| - const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered |
2714 |
| - ) const override { |
| 2704 | + bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) |
| 2705 | + const override { |
2715 | 2706 | attenuation = color(1.0, 1.0, 1.0);
|
2716 | 2707 | double refraction_ratio = rec.front_face ? (1.0/ir) : ir;
|
2717 | 2708 |
|
|
0 commit comments