-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathray.h
94 lines (70 loc) · 2.85 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#pragma once
#include <embree3/rtcore_ray.h>
#include "vector3.h"
/************************************************* Declaration **************************************************/
class Ray {
public:
// Initialize with default values
explicit Ray();
// Initialize with 2 vectors
explicit Ray(Vec3 o, Vec3 d);
~Ray() = default;
// Default copy constructor and assignment operator
Ray(const Ray &v) = default;
Ray &operator=(const Ray &v) = default;
Vec3 operator()(double t) const{
Vec3 res_vec = org + dir * t;
return res_vec;
}
Vec3 org;
Vec3 dir;
Vec3::value_type tnear;
Vec3::value_type tfar;
};
/************************************************ Implementation ************************************************/
inline Ray::Ray() : org(),
dir(),
tnear(std::numeric_limits<Vec3::value_type>::min()),
tfar(std::numeric_limits<Vec3::value_type>::max()) { }
inline Ray::Ray(Vec3 o, Vec3 d) : org(o),
dir(d),
tnear(std::numeric_limits<Vec3::value_type>::min()),
tfar(std::numeric_limits<Vec3::value_type>::max()) { }
/*
* Functions for copying data from Ray to RTC Ray structures and vice versa.
* RTCRayHit is used for normal ray intersections. Now contains two sub-structures ray and hit (compared to Embree2).
* RTCRay is used for occlusion ray intersections.
*/
inline void Ray_to_RTCRayHit(const Ray& ray, RTCRayHit& rtc_ray, unsigned int geomID = (int)RTC_INVALID_GEOMETRY_ID,
unsigned int primID = (int)RTC_INVALID_GEOMETRY_ID, unsigned int mask = -1, float time = 0.0f) {
rtc_ray.ray.org_x = ray.org.x;
rtc_ray.ray.org_y = ray.org.y;
rtc_ray.ray.org_z = ray.org.z;
rtc_ray.ray.dir_x = ray.dir.x;
rtc_ray.ray.dir_y = ray.dir.y;
rtc_ray.ray.dir_z = ray.dir.z;
rtc_ray.ray.tnear = ray.tnear;
rtc_ray.ray.tfar = ray.tfar;
rtc_ray.hit.geomID = geomID;
rtc_ray.hit.primID = primID;
rtc_ray.ray.mask = mask;
rtc_ray.ray.time = time;
}
inline void Ray_to_RTCRay(const Ray& ray, RTCRay& rtc_ray, unsigned int mask = -1, float time = 0.0f) {
rtc_ray.org_x = ray.org.x;
rtc_ray.org_y = ray.org.y;
rtc_ray.org_z = ray.org.z;
rtc_ray.dir_x = ray.dir.x;
rtc_ray.dir_y = ray.dir.y;
rtc_ray.dir_z = ray.dir.z;
rtc_ray.tnear = ray.tnear;
rtc_ray.tfar = ray.tfar;
rtc_ray.mask = mask;
rtc_ray.time = time;
}
inline void RTCRayHit_to_Ray(const RTCRayHit& rtcray, Ray& ray) {
ray.org = Vec3(rtcray.ray.org_x, rtcray.ray.org_y, rtcray.ray.org_z);
ray.dir = Vec3(rtcray.ray.dir_x, rtcray.ray.dir_y, rtcray.ray.dir_z);
ray.tfar = rtcray.ray.tfar;
ray.tnear = rtcray.ray.tnear;
}