Working on refraction & transparency.
Lots of work left to do!
This commit is contained in:
@@ -13,13 +13,14 @@
|
||||
#include <ray.h>
|
||||
|
||||
class Shape;
|
||||
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)) :
|
||||
bool inside, Tuple reflectV = Vector(0, 0, 0), double n1 = 1.0, double n2 = 1.0) :
|
||||
object(object), t(t), hitPoint(point), eyeVector(eyev), normalVector(normalv), inside(inside),
|
||||
overHitPoint(overHitP), reflectVector(reflectV) { };
|
||||
overHitPoint(overHitP), reflectVector(reflectV), n1(n1), n2(n2) { };
|
||||
|
||||
Shape *object;
|
||||
double t;
|
||||
@@ -29,6 +30,9 @@ struct Computation
|
||||
Tuple normalVector;
|
||||
Tuple reflectVector;
|
||||
|
||||
double n1;
|
||||
double n2;
|
||||
|
||||
bool inside;
|
||||
};
|
||||
|
||||
@@ -42,7 +46,7 @@ public:
|
||||
Intersection(double t, Shape *object) : t(t), object(object) { };
|
||||
bool nothing() { return (this->object == nullptr); };
|
||||
|
||||
Computation prepareComputation(Ray r);
|
||||
Computation prepareComputation(Ray r, Intersect *xs = nullptr);
|
||||
|
||||
bool operator==(const Intersection &b) const { return ((this->t == b.t) && (this->object == b.object)); };
|
||||
};
|
||||
|
||||
94
source/include/list.h
Normal file
94
source/include/list.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* DoRayMe - a quick and dirty Raytracer
|
||||
* List header
|
||||
*
|
||||
* Created by Manoël Trapier
|
||||
* Copyright (c) 2020 986-Studio.
|
||||
*
|
||||
*/
|
||||
#ifndef DORAYME_LIST_H
|
||||
#define DORAYME_LIST_H
|
||||
|
||||
#include <shape.h>
|
||||
|
||||
struct ChainList
|
||||
{
|
||||
Shape *shape;
|
||||
ChainList *next;
|
||||
};
|
||||
|
||||
class List
|
||||
{
|
||||
private:
|
||||
ChainList *head;
|
||||
ChainList *tail;
|
||||
uint32_t count;
|
||||
public:
|
||||
List() : head(nullptr), tail(nullptr), count(0) { };
|
||||
~List()
|
||||
{
|
||||
ChainList *p = this->head;
|
||||
if (p == nullptr) { return; }
|
||||
|
||||
/* clear up the list */
|
||||
}
|
||||
|
||||
Shape *last()
|
||||
{
|
||||
ChainList *p = this->tail;
|
||||
if (p == nullptr) { return nullptr; }
|
||||
return p->shape;
|
||||
}
|
||||
|
||||
void remove(Shape *s)
|
||||
{
|
||||
ChainList *p = this->head;
|
||||
if (p == nullptr) { return; }
|
||||
while(p->next != nullptr)
|
||||
{
|
||||
if (p->next->shape == s)
|
||||
{
|
||||
this->count --;
|
||||
p->next = p->next->next;
|
||||
free(p->next);
|
||||
return;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
|
||||
void append(Shape *s)
|
||||
{
|
||||
ChainList *theNew = (ChainList *)calloc(1, sizeof(ChainList));
|
||||
|
||||
theNew->shape = s;
|
||||
|
||||
ChainList *p = this->tail;
|
||||
tail = theNew;
|
||||
|
||||
if (p != nullptr) { p->next = theNew; }
|
||||
else { head = theNew; } /* If the tail is empty, it mean the list IS empty. */
|
||||
|
||||
this->count ++;
|
||||
}
|
||||
|
||||
bool isEmpty()
|
||||
{
|
||||
return (this->count == 0);
|
||||
}
|
||||
|
||||
bool doesInclude(Shape *s)
|
||||
{
|
||||
ChainList *p = this->head;
|
||||
|
||||
while(p != nullptr)
|
||||
{
|
||||
if (p->shape == s) { return true; }
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //DORAYME_LIST_H
|
||||
@@ -25,11 +25,14 @@ public:
|
||||
double specular;
|
||||
double shininess;
|
||||
double reflective;
|
||||
double transparency;
|
||||
double refractiveIndex;
|
||||
|
||||
Pattern *pattern;
|
||||
|
||||
public:
|
||||
Material() : colour(Colour(1, 1, 1)), ambient(0.1), diffuse(0.9), specular(0.9), shininess(200), reflective(0.0), pattern(nullptr) {};
|
||||
Material() : colour(Colour(1, 1, 1)), ambient(0.1), diffuse(0.9), specular(0.9), shininess(200),
|
||||
reflective(0.0), transparency(0.0), refractiveIndex(1.0), pattern(nullptr) {};
|
||||
|
||||
Colour lighting(Light light, Tuple point, Tuple eyeVector, Tuple normalVector, Shape *hitObject, bool inShadow = false);
|
||||
|
||||
@@ -40,4 +43,5 @@ public:
|
||||
(this->colour == b.colour); };
|
||||
};
|
||||
|
||||
|
||||
#endif /* DORAYME_MATERIAL_H */
|
||||
|
||||
@@ -24,4 +24,11 @@ public:
|
||||
/* All sphere are at (0, 0, 0) and radius 1 in the object space */
|
||||
};
|
||||
|
||||
/* Mostly for test purposes */
|
||||
class GlassSphere : public Sphere
|
||||
{
|
||||
public:
|
||||
GlassSphere() : Sphere() { this->material.transparency = 1.0; this->material.refractiveIndex = 1.5; };
|
||||
};
|
||||
|
||||
#endif /* DORAYME_SPHERE_H */
|
||||
|
||||
Reference in New Issue
Block a user