-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGroup.h
More file actions
105 lines (85 loc) · 1.54 KB
/
Group.h
File metadata and controls
105 lines (85 loc) · 1.54 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef GROUP_H
#define GROUP_H
#include "Object3D.h"
#include "Ray.h"
#include "Hit.h"
#include <iostream>
#include <omp.h>
using namespace std;
///TODO:
///Implement Group
///Add data structure to store a list of Object*
class Group:public Object3D
{
public:
Group(){
size = 100;
collection = new Object3D*[size];
}
Group( int num_objects ){
size = num_objects;
collection = new Object3D*[size];
}
~Group(){
delete [] collection;
}
virtual bool intersect( const Ray& r , Hit& h , float tmin ) {
bool ret = false;
//#pragma omp critical
//{
for (register int i = 0 ; i < size ; ++ i)
{
if(collection[i] != nullptr)
{
if(collection[i]->intersect(r, h, tmin))
{
ret = true;
//printf("%c\t", collection[i]->getType());
}
}
}
//}
return ret;
}
bool intersectShadowRay( const Ray& r , Hit& h , float tmin ) {
bool toReturn = false;
//#pragma omp critical
//{
for (register int i = 0 ; i < size ; ++ i)
{
if(collection[i] != nullptr)
{
if(collection[i]->intersect(r, h, tmin))
{
toReturn = true;
break;
}
}
}
//}
return toReturn;
}
void addObject( int index , Object3D* obj ){
if (index > size-1)
{
printf("Invalid index while adding object to group\n");
exit(0);
}
collection[index] = obj;
}
int getGroupSize(){
int s;
for(register int i = 0 ; i < size ; i ++)
{
if(collection[i] != nullptr)
{
++s;
}
}
return s;
}
private:
int size;
Object3D** collection;
};
#endif