Adding shadows!

This commit is contained in:
Godzil
2020-02-20 17:46:03 +00:00
parent 5198888df6
commit cf5597ad6d
11 changed files with 145 additions and 24 deletions

View File

@@ -94,7 +94,12 @@ Intersect World::intersect(Ray r)
Tuple World::shadeHit(Computation comps)
{
return comps.object->material.lighting(*this->lightList[0], comps.hitPoint, comps.eyeVector, comps.normalVector);
/* TODO: Add support for more than one light */
bool isThereAnObstacle = this->isShadowed(comps.overHitPoint);
return comps.object->material.lighting(*this->lightList[0], comps.overHitPoint, comps.eyeVector,
comps.normalVector, isThereAnObstacle);
}
Tuple World::colourAt(Ray r)
@@ -109,4 +114,23 @@ Tuple World::colourAt(Ray r)
{
return this->shadeHit(hit.prepareComputation(r));
}
}
}
bool World::isShadowed(Tuple point)
{
/* TODO: Add support for more than one light */
Tuple v = this->lightList[0]->position - point;
double distance = v.magnitude();
Tuple direction = v.normalise();
Ray r = Ray(point, direction);
Intersection h = this->intersect(r).hit();
if (!h.nothing() && h.t < distance)
{
return true;
}
return false;
}