-
Notifications
You must be signed in to change notification settings - Fork 1
/
aggregateprimitive.cpp
68 lines (59 loc) · 1.83 KB
/
aggregateprimitive.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
#include "aggregateprimitive.h"
AggregatePrimitive::AggregatePrimitive() {
}
AggregatePrimitive::AggregatePrimitive(vector<Primitive*> ilist){//, vector<Transformation*> itrans) {
list_primitives = ilist;
//list_transformations = itrans;
}
bool AggregatePrimitive::intersect(Ray& ray, float* thit, Intersection* in) {
float current_hit;
float min_hit = INFINITY;
bool intersected = false;
Intersection inter;
for(int i = 0; i < list_primitives.size(); i++) {
Primitive* shape = list_primitives[i];
// cout << "Segfault here???\n";
if(shape->intersect(ray, ¤t_hit, &inter)) {
if(current_hit < min_hit) {
min_hit = current_hit;
*in = inter;
}
intersected = true;
}
}
*thit = min_hit;
return intersected;
}
bool AggregatePrimitive::intersectE(Ray& ray, float* thit, Intersection* in, Transformation& trans) {
float current_hit;
float min_hit = INFINITY;
bool intersected = false;
Intersection inter;
// cout << "passed to aggregateprimitive\n";
for(int i = 0; i < list_primitives.size(); i++) {
Primitive* shape = list_primitives[i];
if(shape->intersectE(ray, ¤t_hit, &inter, trans)) {
if(current_hit < min_hit) {
min_hit = current_hit;
*in = inter;
}
intersected = true;
}
}
*thit = min_hit;
// cout << "Segfaulting after intersect\n";
return intersected;
}
bool AggregatePrimitive::intersectP(Ray& ray, Primitive* currShape) {
bool intersected = false;
//cout << "lray1: "; ray.print(); cout << endl;
for(int i = 0; i < list_primitives.size(); i++) {
Primitive* shape = list_primitives[i];
if(shape != currShape && shape->intersectP(ray)) {
//cout << "lray2: "; ray.print(); cout << endl; cout << "currShape: "; currShape->print(); cout << "intersected shape: "; shape->print();
intersected = true;
}
}
//cout << "-----------------------------" << endl;
return intersected;
}