Working on refraction & transparency.

Lots of work left to do!
This commit is contained in:
Godzil
2020-02-21 18:59:14 +00:00
parent 89dd74fa7c
commit df52cb36db
9 changed files with 219 additions and 9 deletions

View File

@@ -8,9 +8,13 @@
*/
#include <intersection.h>
#include <shape.h>
#include <list.h>
Computation Intersection::prepareComputation(Ray r)
Computation Intersection::prepareComputation(Ray r, Intersect *xs)
{
double n1 = 1.0;
double n2 = 1.0;
Tuple hitP = r.position(this->t);
Tuple normalV = this->object->normalAt(hitP);
Tuple eyeV = -r.direction;
@@ -25,6 +29,46 @@ Computation Intersection::prepareComputation(Ray r)
Tuple overHitP = hitP + normalV * getEpsilon();
Tuple reflectV = r.direction.reflect(normalV);
if (xs != nullptr)
{
List containers;
int j, k;
Intersection hit = xs->hit();
for(j = 0; j < xs->count(); j++)
{
Intersection i = (*xs)[j];
if (hit == i)
{
if (!containers.isEmpty())
{
n1 = containers.last()->material.refractiveIndex;
}
}
if (containers.doesInclude(i.object))
{
containers.remove(i.object);
}
else
{
containers.append(i.object);
}
if (hit == i)
{
if (!containers.isEmpty())
{
Shape *cur = containers.last();
n2 = cur->material.refractiveIndex;
}
/* End the loop */
break;
}
}
}
return Computation(this->object,
this->t,
hitP,
@@ -32,5 +76,7 @@ Computation Intersection::prepareComputation(Ray r)
normalV,
overHitP,
inside,
reflectV);
reflectV,
n1,
n2);
}