-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworld.cpp
35 lines (30 loc) · 800 Bytes
/
world.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
#include <iostream>
#include "world.h"
#include "pointlightsource.h"
#include "pathtracer_params.h"
using namespace std;
float World::firstIntersection(Ray& ray)
{
for (auto &i : objectList)
i->intersect(ray);
return ray.getParameter();
}
Color World::shade_ray(Ray& ray)
{
if(ray.getLevel() > MAX_LEVEL) return Color(ambient);
firstIntersection(ray);
if(ray.didHit()) {
Color c = (ray.intersected())->shade(ray);
return c;
}
return background;
}
void World::addLight(PointLightSource *ls, float radius) {
Material *m = new Material(this); m->ka = 1; m->color = Color(ls->getIntensity());
Sphere *sphere = new Sphere(ls->getPosition(), radius, m);
sphere->setLightSource(ls);
addObject(sphere);
}
const vector<Object *> &World::getObjectList() const {
return objectList;
}