-
Notifications
You must be signed in to change notification settings - Fork 1
/
Scene.cu
116 lines (90 loc) · 2.89 KB
/
Scene.cu
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
106
107
108
109
110
111
112
113
114
115
116
#include "Scene.h"
//default lamp
__host__ __device__ Scene::Scene(int totalMeshes, uint32_t* textureData)
:light(0, 0, 10, 10){
this->totalMeshes = totalMeshes;
this->textureData = textureData;
meshes = (Mesh**)malloc(totalMeshes*sizeof(Mesh*));
numOfMeshes = 0;
}
__host__ __device__ Mesh* Scene::getMesh(int number){
if(number<=numOfMeshes){
return meshes[number];
}else{
printf("ERROR: THAT MESH DOES NOT EXSIST, DEFAULT MESH RETURNED");
return *(meshes+0);
}
}
__host__ __device__ Camera Scene::getCamera(void){
return camera;
}
__host__ __device__ void Scene::addSphere(float centreX, float centreY, float centreZ, float radius, colour_t col, materialType_t material){
numOfMeshes++;
Sphere *s;
if(material!=TEXTURE){
s = new Sphere(centreX, centreY, centreZ, radius, col, material);
}else{
s = new Sphere(centreX, centreY, centreZ, radius, col, textureData);
}
Mesh *m = s;
meshes[numOfMeshes-1] = m;
}
__host__ __device__ void Scene::addPlane(vertex_t v1, vertex_t v2, vertex_t v3, vertex_t v4, colour_t colour, materialType_t material){
numOfMeshes++;
Plane *p;
if(material!=TEXTURE){
p = new Plane(v1, v2, v3, v4, colour, material);
}else{
p = new Plane(v1, v2, v3, v4, colour, textureData);
}
Mesh *m = p;
meshes[numOfMeshes-1] = m;
}
__host__ __device__ void Scene::addTri(vertex_t v1, vertex_t v2, vertex_t v3, colour_t colour, materialType_t material){
numOfMeshes++;
Tri *t = new Tri(v1, v2, v3, colour, material);
Mesh *m = t;
meshes[numOfMeshes-1] = m;
}
__host__ __device__ void Scene::addLight(float posX, float posY, float posZ, float intensity){
light = Light(posX, posY, posZ, intensity);
}
__host__ __device__ int Scene::getNumOfMeshes(void){
return numOfMeshes;
}
__host__ __device__ Light Scene::getLight(void){
return light;
}
__host__ __device__ uint32_t* Scene::getTexture(void){
return textureData;
}
__host__ __device__ void Scene::setHorizonColour(colour_t horizonColour){
this->horizonColour = horizonColour;
}
__host__ __device__ colour_t Scene::getHorizonColour(void){
return horizonColour;
}
__host__ __device__ Mesh** Scene::getMeshes(void){
return meshes;
}
//builds the binary space partioning bounding volume hierachy
__host__ void Scene::buildBSPBVH(int BSPBVH_DEPTH){
//DEFINE MAX TREE HEIGHT AS 4
partitioningHierachy = new BinTree(meshes, numOfMeshes, BSPBVH_DEPTH);
partitioningHierachy->buildTree();
}
__device__ void Scene::buildBSPBVH(int BSPBVH_DEPTH, Stack<BinTreeNode*> *d_unPropagatedNodes){
//DEFINE MAX TREE HEIGHT AS 4
partitioningHierachy = new BinTree(meshes, numOfMeshes, BSPBVH_DEPTH);
partitioningHierachy->buildTree(d_unPropagatedNodes);
}
__host__ __device__ float Scene::collisionDetect(vector_t ray, Mesh** mesh){
return partitioningHierachy->findCollisionMesh(ray, mesh);
}
__host__ __device__ Scene::~Scene(void){
for(int i=0;i<numOfMeshes;i++){
free(meshes[i]);
}
free(meshes);
delete(partitioningHierachy);
}