Refraction seems to work. Still need to do a nice scene.
This commit is contained in:
@@ -18,14 +18,16 @@ class Intersect;
|
||||
struct Computation
|
||||
{
|
||||
Computation(Shape *object, double t, Tuple point, Tuple eyev, Tuple normalv, Tuple overHitP,
|
||||
bool inside, Tuple reflectV = Vector(0, 0, 0), double n1 = 1.0, double n2 = 1.0) :
|
||||
bool inside, Tuple reflectV = Vector(0, 0, 0), double n1 = 1.0, double n2 = 1.0,
|
||||
Tuple underHitP = Point(0, 0, 0)) :
|
||||
object(object), t(t), hitPoint(point), eyeVector(eyev), normalVector(normalv), inside(inside),
|
||||
overHitPoint(overHitP), reflectVector(reflectV), n1(n1), n2(n2) { };
|
||||
overHitPoint(overHitP), underHitPoint(underHitP), reflectVector(reflectV), n1(n1), n2(n2) { };
|
||||
|
||||
Shape *object;
|
||||
double t;
|
||||
Tuple hitPoint;
|
||||
Tuple overHitPoint;
|
||||
Tuple underHitPoint;
|
||||
Tuple eyeVector;
|
||||
Tuple normalVector;
|
||||
Tuple reflectVector;
|
||||
|
||||
@@ -44,13 +44,31 @@ public:
|
||||
{
|
||||
ChainList *p = this->head;
|
||||
if (p == nullptr) { return; }
|
||||
|
||||
if ((p->next == nullptr) && (p->shape == s))
|
||||
{
|
||||
/* First element */
|
||||
this->tail = nullptr;
|
||||
free(this->head);
|
||||
this->head = nullptr;
|
||||
this->count = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
while(p->next != nullptr)
|
||||
{
|
||||
if (p->next->shape == s)
|
||||
{
|
||||
this->count --;
|
||||
ChainList *found = p->next;
|
||||
|
||||
p->next = p->next->next;
|
||||
free(p->next);
|
||||
|
||||
free(found);
|
||||
|
||||
if (p->next == NULL) { this->tail = p; }
|
||||
|
||||
this->count --;
|
||||
return;
|
||||
}
|
||||
p = p->next;
|
||||
@@ -64,10 +82,10 @@ public:
|
||||
theNew->shape = s;
|
||||
|
||||
ChainList *p = this->tail;
|
||||
tail = theNew;
|
||||
this->tail = theNew;
|
||||
|
||||
if (p != nullptr) { p->next = theNew; }
|
||||
else { head = theNew; } /* If the tail is empty, it mean the list IS empty. */
|
||||
else { this->head = theNew; } /* If the tail is empty, it mean the list IS empty. */
|
||||
|
||||
this->count ++;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ public:
|
||||
bool isShadowed(Tuple point);
|
||||
|
||||
Colour reflectColour(Computation comps, uint32_t depthCount = 4);
|
||||
Colour refractedColour(Computation comps, uint32_t depthCount = 0);
|
||||
|
||||
Intersect intersect(Ray r);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user