-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRay.h
81 lines (59 loc) · 1.29 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
#ifndef __RAY_H__
#define __RAY_H__
//////
//
// Includes
//
// API config
#include "_config.h"
// Local includes
#include "EigenTools.h"
//////
//
// Classes
//
/**
* @brief
* POD-type struct representing a ray in 3D space, defined via origin and direction.
*/
template <class flt_type>
struct APISPEC Ray
{
////
// Types
/** @brief Real number type. */
typedef flt_type real;
/** @brief 3D vector type. */
typename typedef EigenTypes<real>::Vec3 Vec3;
/** @brief Homogenous 3D vector type. */
typename typedef EigenTypes<real>::Vec4 Vec4;
////
// Data members
/** @brief Homogenous position vector of ray origin. */
Vec4 origin;
/** @brief Normalized ray direction vector. */
Vec3 direction;
////
// Methods
/**
* @brief Calculates the point on the ray that is @c t units away from the origin.
*/
inline Vec3 point3At (real t) const
{
return std::move(
Vec3(origin.x()/origin.w(), origin.y()/origin.w(), origin.z()/origin.w())
+ t*direction
);
}
/**
* @brief
* Calculates the point (as homogenous position vector) on the ray that is @c t
* units away from the origin.
*/
inline Vec4 point4At (real t) const
{
Vec3 point = std::move(point3At(t));
return std::move(Vec4(point.x(), point.y(), point.z(), 1));
}
};
#endif // ifndef __RAY_H__