cpp-raytracer/rtweekend.hpp
2021-08-29 16:17:13 +02:00

65 lines
1.2 KiB
C++

#ifndef RTWEEKEND_H
#define RTWEEKEND_H
#include <math.h>
#include <memory>
#include "timer.hpp"
#include "random.h"
#define FAST_RANDOM 1
#ifdef FAST_RANDOM
pcg32_random_t pcg = { 0x853c49e6748fea9bULL, 0xda3e39cb94b95bdbULL };
#define rand() pcg32_random_r(&pcg)
#endif
/* Utility functions */
inline float degrees_to_radians(float d)
{
return d * M_PI / 180;
}
/* Returns a float in the range [0,1) */
inline float random_float()
{
return rand() * (1.0 / RAND_MAX);
}
/* Returns a float in the range [min,max) */
inline float random_float(float min, float max)
{
return min + (max-min) * random_float();
}
/* Clamps a value between [min,max] */
inline float clamp(float v, float min, float 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;
float 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