-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtweekend.h
57 lines (43 loc) · 1.16 KB
/
rtweekend.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef RAYTRACING_DEV_RTWEEKEND_H
#define RAYTRACING_DEV_RTWEEKEND_H
#include <cmath>
#include <cstdlib>
#include <limits>
#include <memory>
// Usings
using std::shared_ptr;
using std::make_shared;
// Constants
const double infinity = std::numeric_limits<double>::infinity();
const double pi = 3.1415926535897932385;
// Utility Function
inline double degree_to_radians(double degree) {
return degree * pi / 180;
}
inline double ffmin(double a,double b){
return a <= b ? a : b;
}
inline double ffmax(double a,double b){
return a >= b ? a : b;
}
inline double random_double() {
// Returns a random real in [0,1)
return rand() / (RAND_MAX + 1.0);
}
inline double random_double(double min,double max) {
// Returns a random real in [min,max)
return min + (max - min) * random_double();
}
inline double clamp(double x,double min,double max) {
if (x < min) return min;
if (x > max) return max;
return x;
}
inline int random_int(int min, int max) {
// Return a random integer in [min, max]
return static_cast<int>(random_double(min, max + 1));
}
// Common Headers
#include "ray.h"
#include "vec3.h"
#endif //RAYTRACING_DEV_RTWEEKEND_H