-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ray.h
42 lines (34 loc) · 829 Bytes
/
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
#pragma once
#include "Vector3.h"
class Ray
{
public:
Ray() { }
Ray(const Vector3 &a, const Vector3 &b)
{
SetOrigin(a);
SetDirection(b);
}
Ray(const Ray& r) { *this = r; }
Vector3 Origin() const { return o; }
Vector3 Direction() const { return d; }
void SetOrigin(const Vector3 &v) { o = v; }
void SetDirection(const Vector3 &v)
{
d = v;
extra = Vector3(1.0f / v.x, 1.f / v.y, 1.f / v.z);
posneg[0] = (d.x > 0 ? 0 : 1);
posneg[1] = (d.y > 0 ? 0 : 1);
posneg[2] = (d.z > 0 ? 0 : 1);
}
Vector3 operator()(float t) const { return o + t*d; }
Ray& operator=(const Ray &r) { SetOrigin(r.o); SetDirection(r.d); return *this; }
public:
Vector3 o, d, extra;
int posneg[3];
};
inline std::ostream& operator<<(std::ostream &os, const Ray &r)
{
os << '(' << r.o << ") + t(" << r.d << ')';
return os;
}