-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorld.cpp
More file actions
46 lines (39 loc) · 876 Bytes
/
World.cpp
File metadata and controls
46 lines (39 loc) · 876 Bytes
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
#include "World.h"
#include <iterator>
World::World(){
};
void World::addObject(WorldObject* w){
objects.push_back(w);
}
void World::addLightSource(Light v){
lights.push_back(v);
}
Color World::processRay(Ray r, int recursionCount){
if(recursionCount < MAX_REFLECT){
if(recursionCount != 0){
recursionCount;
}
double dist = -1;
WorldObject* index = nullptr;
for(std::vector<WorldObject*>::iterator it = objects.begin(); it != objects.end(); it++){
double d = (*it)->rayTouching(r);
if(d > 0 && (d < dist || dist < 0)){
dist = d;
index = *it;
}
}
if(index != nullptr){
return index->rayInteract(r, dist, *this, recursionCount);
}else{
return SKY_COLOR;
}
}else{
return SKY_COLOR;
}
}
std::vector<Light> World::getLights(){
return this->lights;
}
std::vector<WorldObject*> World::getObjects(){
return this->objects;
}