-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathray.h
36 lines (28 loc) · 1.02 KB
/
ray.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
#ifndef __RAY_H__
#define __RAY_H__
#include "defines.h"
// RAY
typedef struct ray_s {
point3 orig; //! start point of the ray
vec3 dir; //! ray direction, normalized
float tmax; //! if no intersection computed, should be a large value, else contains the t of the intersection, so do not need to considere intersection if the founded t is more than tmax
float tmin; //! usefull to store entry point in a aabb
int depth; //! number of reflection/refraction
int sign[3]; //! sign of the x,y,z component of dir, 0 -> positive, 1->negative. To optimize aabb intersection
vec3 invdir; //! =1/dir, optimize aabb
} Ray;
inline void rayInit(Ray *r, point3 o, vec3 d, float tmin=0, float tmax=100000, int depth=0) {
r->orig = o;
r->dir = d;
r->tmin = tmin;
r->tmax = tmax;
r->depth = depth;
r->sign[0] = r->dir.x>=0?0:1;
r->sign[1] = r->dir.y>=0?0:1;
r->sign[2] = r->dir.z>=0?0:1;
r->invdir = 1.f/d;
}
inline point3 rayAt(const Ray r, float t) {
return r.orig + t*r.dir;
}
#endif