58 lines
1 KiB
C++
58 lines
1 KiB
C++
#ifndef RTWEEKEND_H
|
|
#define RTWEEKEND_H
|
|
|
|
#include <math.h>
|
|
#include <memory>
|
|
#include "timer.hpp"
|
|
|
|
/* Utility functions */
|
|
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
|