-
Notifications
You must be signed in to change notification settings - Fork 1
/
raytree.cpp
74 lines (61 loc) · 2.08 KB
/
raytree.cpp
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
#include <cstdio>
#include <cstdlib>
// Included files for OpenGL Rendering
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#endif
#include "raytree.h"
// ====================================================================
// Initialize the static variables
int RayTree::activated = 0;
std::vector<Segment> RayTree::main_segments;
std::vector<Segment> RayTree::shadow_segments;
std::vector<Segment> RayTree::reflected_segments;
// ====================================================================
void Segment::paint() {
glVertex3f(a.x(),a.y(),a.z());
glVertex3f(b.x(),b.y(),b.z());
}
// ====================================================================
void RayTree::paintHelper(const Vec4f &m,const Vec4f &s,const Vec4f &r,const Vec4f &t) {
glBegin(GL_LINES);
unsigned int i;
glColor4f(m.r(),m.g(),m.b(),m.a());
for (i = 0; i < main_segments.size(); i++) {
main_segments[i].paint(); }
glColor4f(s.r(),s.g(),s.b(),s.a());
for (i = 0; i < shadow_segments.size(); i++) {
shadow_segments[i].paint(); }
glColor4f(r.r(),r.g(),r.b(),r.a());
for (i = 0; i < reflected_segments.size(); i++) {
reflected_segments[i].paint(); }
glColor4f(t.r(),t.g(),t.b(),t.a());
glEnd();
}
// ====================================================================
void RayTree::paint() {
glLineWidth(2);
glDisable(GL_LIGHTING);
// this allows you to see rays passing through objects
// turn off the depth test and blend with the current pixel color
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
paintHelper(Vec4f(0.7,0.7,0.7,0.3),
Vec4f(0.1,0.9,0.1,0.3),
Vec4f(0.9,0.1,0.1,0.3),
Vec4f(0.1,0.1,0.9,0.3));
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
// with the depth test enabled, draw the lines solid
paintHelper(Vec4f(0.7,0.7,0.7,1.0),
Vec4f(0.1,0.9,0.1,1.0),
Vec4f(0.9,0.1,0.1,1.0),
Vec4f(0.1,0.1,0.9,1.0));
glEnable(GL_LIGHTING);
}
// ====================================================================