-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimitive.cpp
More file actions
74 lines (62 loc) · 1.56 KB
/
Copy pathPrimitive.cpp
File metadata and controls
74 lines (62 loc) · 1.56 KB
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
#include "Primitive.h"
bool GeometricPrimitive::intersect(Ray &ray, float* thit, Intersection* in){
LocalGeo lgeo;
if(!shape->intersect(ray, thit, &lgeo)){
return false;
}
in->primitive = this;
in->localGeo = lgeo;
return true;
}
bool GeometricPrimitive::intersectP(Ray &ray){
return shape->intersectP(ray);
}
void GeometricPrimitive::getBRDF(LocalGeo &geo, BRDF* brdf){
mat->getBRDF(brdf);
return;
}
AggregatePrimitive::AggregatePrimitive(std::vector<GeometricPrimitive*> list){
this->primitives = list;
std::cout << "Size of primitives: " << this->primitives.size() << "\n";
}
bool AggregatePrimitive::intersect(Ray &ray, float* thit, Intersection* in){
float least_t;
int location;
LocalGeo final_localGeo;
bool hit = false;
int hit_num = 0;
for(int i = 0; i < primitives.size(); i++){
float res_t;
LocalGeo localGeo;
GeometricPrimitive* geoprim = primitives[i];
if(geoprim->shape->intersect(ray, &res_t, &localGeo)){
hit = true;
if(res_t < least_t || hit_num == 0){
least_t = res_t;
final_localGeo = localGeo;
location = i;
}
hit_num++;
}
}
//std::cout << "No seg fault here\n";
if(hit){
in->primitive = dynamic_cast<Primitive*>(primitives[location]);
in->localGeo = final_localGeo;
}
return hit;
}
bool AggregatePrimitive::intersectP(Ray &ray){
bool hit = false;
for(int i = 0; i < primitives.size(); i++){
GeometricPrimitive* geoprim = primitives[i];
if(geoprim->shape->intersectP(ray)){
hit = true;
break;
}
}
return hit;
}
void AggregatePrimitive::getBRDF(LocalGeo &geo, BRDF* brdf){
exit(1);
}