-
Notifications
You must be signed in to change notification settings - Fork 1
/
raytree.h
84 lines (67 loc) · 2.42 KB
/
raytree.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
#ifndef _RAY_TREE_H
#define _RAY_TREE_H
#include <vector>
#include "ray.h"
// ====================================================================
// ====================================================================
// data structure to store a segment
class Segment {
public:
// CONSTRUCTOR
Segment(const Ray &ray, double tstart, double tstop) {
// first clamp the segment to "reasonable" values
// to make sure it is drawn correctly in OpenGL
if (tstart < -1000) tstart = -1000;
if (tstop > 1000) tstop = 1000;
a = ray.pointAtParameter(tstart);
b = ray.pointAtParameter(tstop); }
// draw this ray on the screen
void paint();
private:
// REPRESENTATION
Vec3f a;
Vec3f b;
};
// ====================================================================
// ====================================================================
//
// This class only contains static variables and static member
// functions so there is no need to call the constructor, destructor
// etc. It's just a wrapper for the ray tree visualization data.
//
class RayTree {
public:
// most of the time the RayTree is NOT activated, so the segments are not updated
static void Activate() { Clear(); activated = 1; }
static void Deactivate() { activated = 0; }
// when activated, these function calls store the segments of the tree
static void AddMainSegment(const Ray &ray, double tstart, double tstop) {
if (!activated) return;
main_segments.push_back(Segment(ray,tstart,tstop));
}
static void AddShadowSegment(const Ray &ray, double tstart, double tstop) {
if (!activated) return;
shadow_segments.push_back(Segment(ray,tstart,tstop));
}
static void AddReflectedSegment(const Ray &ray, double tstart, double tstop) {
if (!activated) return;
reflected_segments.push_back(Segment(ray,tstart,tstop));
}
static void paint();
private:
// HELPER FUNCTIONS
static void paintHelper(const Vec4f &m,const Vec4f &s,const Vec4f &r,const Vec4f &t);
static void Clear() {
main_segments.clear();
shadow_segments.clear();
reflected_segments.clear();
}
// REPRESENTATION
static int activated;
static std::vector<Segment> main_segments;
static std::vector<Segment> shadow_segments;
static std::vector<Segment> reflected_segments;
};
// ====================================================================
// ====================================================================
#endif