@@ -119,42 +119,42 @@ inline vec3 unit_vector(vec3 v) {
119
119
return v / v.length ();
120
120
}
121
121
122
- vec3 random_unit_vector () {
122
+ inline vec3 random_unit_vector () {
123
123
auto a = random_double (0 , 2 *pi);
124
124
auto z = random_double (-1 , 1 );
125
125
auto r = sqrt (1 - z*z);
126
126
return vec3 (r*cos (a), r*sin (a), z);
127
127
}
128
128
129
- vec3 random_in_unit_disk () {
129
+ inline vec3 random_in_unit_disk () {
130
130
while (true ) {
131
131
auto p = vec3 (random_double (-1 ,1 ), random_double (-1 ,1 ), 0 );
132
132
if (p.length_squared () >= 1 ) continue ;
133
133
return p;
134
134
}
135
135
}
136
136
137
- vec3 random_in_unit_sphere () {
137
+ inline vec3 random_in_unit_sphere () {
138
138
while (true ) {
139
139
auto p = vec3::random (-1 ,1 );
140
140
if (p.length_squared () >= 1 ) continue ;
141
141
return p;
142
142
}
143
143
}
144
144
145
- vec3 random_in_hemisphere (const vec3& normal) {
145
+ inline vec3 random_in_hemisphere (const vec3& normal) {
146
146
vec3 in_unit_sphere = random_in_unit_sphere ();
147
147
if (dot (in_unit_sphere, normal) > 0.0 ) // In the same hemisphere as the normal
148
148
return in_unit_sphere;
149
149
else
150
150
return -in_unit_sphere;
151
151
}
152
152
153
- vec3 reflect (const vec3& v, const vec3& n) {
153
+ inline vec3 reflect (const vec3& v, const vec3& n) {
154
154
return v - 2 *dot (v,n)*n;
155
155
}
156
156
157
- vec3 refract (const vec3& uv, const vec3& n, double etai_over_etat) {
157
+ inline vec3 refract (const vec3& uv, const vec3& n, double etai_over_etat) {
158
158
auto cos_theta = fmin (dot (-uv, n), 1.0 );
159
159
vec3 r_out_perp = etai_over_etat * (uv + cos_theta*n);
160
160
vec3 r_out_parallel = -sqrt (fabs (1.0 - r_out_perp.length_squared ())) * n;
0 commit comments