use snake_case

This commit is contained in:
K Tyl 2020-06-06 04:09:13 +01:00
parent a7268a2a83
commit 590d48b6c6
3 changed files with 27 additions and 27 deletions

View File

@ -4,10 +4,10 @@
#include <iostream> #include <iostream>
void writeColour(std::ostream &out, colour pixelColour) void write_colour(std::ostream &out, colour pixel_colour)
{ {
// write the translated [0,255] value of each colour component. // write the translated [0,255] value of each colour component.
out << static_cast<int>(255.999 * pixelColour.x()) << ' ' out << static_cast<int>(255.999 * pixel_colour.x()) << ' '
<< static_cast<int>(255.999 * pixelColour.y()) << ' ' << static_cast<int>(255.999 * pixel_colour.y()) << ' '
<< static_cast<int>(255.999 * pixelColour.z()) << '\n'; << static_cast<int>(255.999 * pixel_colour.z()) << '\n';
} }

View File

@ -8,15 +8,15 @@ const double ASPECT_RATIO = 16.0 / 9.0;
const int WIDTH = 384; const int WIDTH = 384;
const int HEIGHT = static_cast<int>(WIDTH / ASPECT_RATIO); const int HEIGHT = static_cast<int>(WIDTH / ASPECT_RATIO);
double hitSphere(const point3& centre, double radius, const ray& r) double hit_sphere(const point3& centre, double radius, const ray& r)
{ {
vec3 oc = r.origin() - centre; vec3 oc = r.origin() - centre;
auto a = r.direction().lengthSquared(); auto a = r.direction().length_squared();
auto halfB = dot(oc, r.direction()); auto half_b = dot(oc, r.direction());
auto c = oc.lengthSquared() - radius*radius; auto c = oc.length_squared() - radius*radius;
auto discriminant = halfB*halfB - a*c; auto discriminant = half_b*half_b - a*c;
if (discriminant < 0) if (discriminant < 0)
{ {
@ -24,21 +24,21 @@ double hitSphere(const point3& centre, double radius, const ray& r)
} }
else else
{ {
return (-halfB - sqrt(discriminant)) / a; return (-half_b - sqrt(discriminant)) / a;
} }
} }
colour rayColour(const ray& r) colour ray_colour(const ray& r)
{ {
auto t = hitSphere(point3(0,0,-1), 0.5, r); auto t = hit_sphere(point3(0,0,-1), 0.5, r);
if (t > 0.0) if (t > 0.0)
{ {
vec3 N = unitVector(r.at(t) - vec3(0,0,-1)); vec3 N = unit_vector(r.at(t) - vec3(0,0,-1));
return 0.5*colour(N.x()+1, N.y()+1, N.z()+1); return 0.5*colour(N.x()+1, N.y()+1, N.z()+1);
} }
vec3 unitDirection = unitVector(r.direction()); vec3 unit_direction = unit_vector(r.direction());
t = 0.5 * (unitDirection.y() + 1.0); t = 0.5 * (unit_direction.y() + 1.0);
auto a = colour(1.0, 0.5, 0.6); auto a = colour(1.0, 0.5, 0.6);
auto b = colour(0.0, 0.0, 0.0); auto b = colour(0.0, 0.0, 0.0);
@ -48,14 +48,14 @@ colour rayColour(const ray& r)
int main() int main()
{ {
auto viewportHeight = 2.0; auto viewport_height = 2.0;
auto viewportWidth = ASPECT_RATIO * viewportHeight; auto viewport_width = ASPECT_RATIO * viewport_height;
auto focalLength = 1.0; auto focal_length = 1.0;
auto origin = point3(0, 0, 0); auto origin = point3(0, 0, 0);
auto horizontal = vec3(viewportWidth, 0, 0); auto horizontal = vec3(viewport_width, 0, 0);
auto vertical = vec3(0, viewportHeight, 0); auto vertical = vec3(0, viewport_height, 0);
auto lowerLeftCorner = origin - horizontal/2 - vertical/2 - vec3(0,0,focalLength); auto lower_left_corner = origin - horizontal/2 - vertical/2 - vec3(0,0,focal_length);
std::cout << "P3\n" << WIDTH << ' ' << HEIGHT << "\n255\n"; std::cout << "P3\n" << WIDTH << ' ' << HEIGHT << "\n255\n";
@ -66,10 +66,10 @@ int main()
{ {
auto u = double(x) / (WIDTH-1); auto u = double(x) / (WIDTH-1);
auto v = double(y) / (HEIGHT-1); auto v = double(y) / (HEIGHT-1);
ray r(origin, lowerLeftCorner + u*horizontal + v*vertical - origin); ray r(origin, lower_left_corner + u*horizontal + v*vertical - origin);
colour pixelColour = rayColour(r); colour pixel_colour = ray_colour(r);
writeColour(std::cout, pixelColour); write_colour(std::cout, pixel_colour);
} }
} }

View File

@ -40,10 +40,10 @@ public:
double length() const double length() const
{ {
return std::sqrt(lengthSquared()); return std::sqrt(length_squared());
} }
double lengthSquared() const double length_squared() const
{ {
return e[0]*e[0] + e[1]*e[1] + e[2]*e[2]; return e[0]*e[0] + e[1]*e[1] + e[2]*e[2];
} }
@ -112,7 +112,7 @@ inline vec3 lerp(const vec3 &a, const vec3 &b, double t)
return (1.0 - t) * a + t * b; return (1.0 - t) * a + t * b;
} }
inline vec3 unitVector(vec3 v) inline vec3 unit_vector(vec3 v)
{ {
return v / v.length(); return v / v.length();
} }