|
176 | 176 | public: |
177 | 177 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
178 | 178 | // Stationary Sphere |
179 | | - sphere(point3 _center, double _radius, shared_ptr<material> _material) |
| 179 | + sphere(const point3& _center, double _radius, shared_ptr<material> _material) |
180 | 180 | : center1(_center), radius(_radius), mat(_material), is_moving(false) {} |
181 | 181 |
|
182 | 182 | // Moving Sphere |
183 | | - sphere(point3 _center1, point3 _center2, double _radius, shared_ptr<material> _material) |
| 183 | + sphere(const point3& _center1, const point3& _center2, double _radius, |
| 184 | + shared_ptr<material> _material) |
184 | 185 | : center1(_center1), radius(_radius), mat(_material), is_moving(true) |
185 | 186 | { |
186 | 187 | center_vec = _center2 - _center1; |
|
735 | 736 | public: |
736 | 737 | // Stationary Sphere |
737 | 738 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
738 | | - sphere(point3 _center, double _radius, shared_ptr<material> _material) |
| 739 | + sphere(const point3& _center, double _radius, shared_ptr<material> _material) |
739 | 740 | : center1(_center), radius(_radius), mat(_material), is_moving(false) |
740 | 741 | { |
741 | 742 | auto rvec = vec3(radius, radius, radius); |
|
770 | 771 | public: |
771 | 772 | ... |
772 | 773 | // Moving Sphere |
773 | | - sphere(point3 _center1, point3 _center2, double _radius, shared_ptr<material> _material) |
| 774 | + sphere(const point3& _center1, const point3& _center2, double _radius, |
| 775 | + shared_ptr<material> _material) |
774 | 776 | : center1(_center1), radius(_radius), mat(_material), is_moving(true) |
775 | 777 | { |
776 | 778 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
|
1222 | 1224 |
|
1223 | 1225 | class solid_color : public texture { |
1224 | 1226 | public: |
1225 | | - solid_color(color c) : color_value(c) {} |
| 1227 | + solid_color(const color& c) : color_value(c) {} |
1226 | 1228 |
|
1227 | 1229 | solid_color(double red, double green, double blue) : solid_color(color(red,green,blue)) {} |
1228 | 1230 |
|
|
1290 | 1292 | checker_texture(double _scale, shared_ptr<texture> _even, shared_ptr<texture> _odd) |
1291 | 1293 | : inv_scale(1.0 / _scale), even(_even), odd(_odd) {} |
1292 | 1294 |
|
1293 | | - checker_texture(double _scale, color c1, color c2) |
| 1295 | + checker_texture(double _scale, const color& c1, const color& c2) |
1294 | 1296 | : inv_scale(1.0 / _scale), |
1295 | 1297 | even(make_shared<solid_color>(c1)), |
1296 | 1298 | odd(make_shared<solid_color>(c2)) |
|
1693 | 1695 |
|
1694 | 1696 | ~rtw_image() { STBI_FREE(data); } |
1695 | 1697 |
|
1696 | | - bool load(const std::string filename) { |
| 1698 | + bool load(const std::string& filename) { |
1697 | 1699 | // Loads image data from the given file name. Returns true if the load succeeded. |
1698 | 1700 | auto n = bytes_per_pixel; // Dummy out parameter: original components per pixel |
1699 | 1701 | data = stbi_load(filename.c_str(), &image_width, &image_height, &n, bytes_per_pixel); |
|
1749 | 1751 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1750 | 1752 | #include "rtw_stb_image.h" |
1751 | 1753 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1752 | | - #include "perlin.h" |
1753 | 1754 |
|
1754 | 1755 | ... |
1755 | 1756 |
|
|
1948 | 1949 | <div class='together'> |
1949 | 1950 | Now if we create an actual texture that takes these floats between 0 and 1 and creates grey colors: |
1950 | 1951 |
|
1951 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
| 1952 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1952 | 1953 | #include "perlin.h" |
| 1954 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
1953 | 1955 |
|
| 1956 | + ... |
| 1957 | + |
| 1958 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
1954 | 1959 | class noise_texture : public texture { |
1955 | 1960 | public: |
1956 | 1961 | noise_texture() {} |
|
2279 | 2284 | ... |
2280 | 2285 | private: |
2281 | 2286 | ... |
2282 | | - static double perlin_interp(vec3 c[2][2][2], double u, double v, double w) { |
| 2287 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete |
| 2288 | + static double trilinear_interp(double c[2][2][2], double u, double v, double w) { |
| 2289 | + ... |
| 2290 | + } |
| 2291 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
| 2292 | + |
| 2293 | + |
2283 | 2294 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
| 2295 | + static double perlin_interp(const vec3 c[2][2][2], double u, double v, double w) { |
2284 | 2296 | auto uu = u*u*(3-2*u); |
2285 | 2297 | auto vv = v*v*(3-2*v); |
2286 | 2298 | auto ww = w*w*(3-2*w); |
|
2297 | 2309 | } |
2298 | 2310 |
|
2299 | 2311 | return accum; |
2300 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2301 | 2312 | } |
2302 | | - ... |
| 2313 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
2303 | 2314 | }; |
2304 | 2315 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
2305 | 2316 | [Listing [perlin-interp]: <kbd>[perlin.h]</kbd> Perlin interpolation function so far] |
|
3050 | 3061 | class diffuse_light : public material { |
3051 | 3062 | public: |
3052 | 3063 | diffuse_light(shared_ptr<texture> a) : emit(a) {} |
3053 | | - diffuse_light(color c) : emit(make_shared<solid_color>(c)) {} |
| 3064 | + diffuse_light(const color& c) : emit(make_shared<solid_color>(c)) {} |
3054 | 3065 |
|
3055 | 3066 | bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) |
3056 | 3067 | const override { |
|
3842 | 3853 | : boundary(b), neg_inv_density(-1/d), phase_function(make_shared<isotropic>(a)) |
3843 | 3854 | {} |
3844 | 3855 |
|
3845 | | - constant_medium(shared_ptr<hittable> b, double d, color c) |
| 3856 | + constant_medium(shared_ptr<hittable> b, double d, const color& c) |
3846 | 3857 | : boundary(b), neg_inv_density(-1/d), phase_function(make_shared<isotropic>(c)) |
3847 | 3858 | {} |
3848 | 3859 |
|
|
3913 | 3924 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
3914 | 3925 | class isotropic : public material { |
3915 | 3926 | public: |
3916 | | - isotropic(color c) : albedo(make_shared<solid_color>(c)) {} |
| 3927 | + isotropic(const color& c) : albedo(make_shared<solid_color>(c)) {} |
3917 | 3928 | isotropic(shared_ptr<texture> a) : albedo(a) {} |
3918 | 3929 |
|
3919 | 3930 | bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) |
|
0 commit comments