cpp-raytracer/rtweekend.hpp
2021-08-22 17:24:33 +02:00

57 lines
1 KiB
C++

#ifndef RTWEEKEND_H
#define RTWEEKEND_H
#include <math.h>
#include <memory>
/* Utility functions */
double degrees_to_radians(double d)
{
return d * M_PI / 180;
}
/* Returns a double in the range [0,1) */
inline double random_double()
{
return rand() * (1.0 / RAND_MAX);
}
/* Returns a double in the range [min,max) */
inline double random_double(double min, double max)
{
return min + (max-min) * random_double();
}
/* Clamps a value between [min,max] */
inline double clamp(double v, double min, double max)
{
return v < min ? min : v > max ? max : v;
}
/* Common internal headers */
#include "ray.hpp"
#include "vec3.hpp"
struct material;
/* Common data structures */
struct hit_record {
point3 p;
vec3 normal;
std::shared_ptr<material> mat_ptr;
double t;
bool front_face;
inline void set_face_normal(const ray& r, const vec3& outward_normal)
{
front_face = dot(r.direction, outward_normal) < 0;
normal = front_face ? outward_normal : -outward_normal;
}
};
#endif