World is on the verge of working!
This commit is contained in:
@@ -10,9 +10,23 @@
|
||||
#define DORAYME_INTERSECTION_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <ray.h>
|
||||
|
||||
class Shape;
|
||||
|
||||
struct Computation
|
||||
{
|
||||
Computation(Shape *object, double t, Tuple point, Tuple eyev, Tuple normalv, bool inside) :
|
||||
object(object), t(t), hitPoint(point), eyeVector(eyev), normalVector(normalv), inside(inside) { };
|
||||
Shape *object;
|
||||
double t;
|
||||
Tuple hitPoint;
|
||||
Tuple eyeVector;
|
||||
Tuple normalVector;
|
||||
|
||||
bool inside;
|
||||
};
|
||||
|
||||
class Intersection
|
||||
{
|
||||
public:
|
||||
@@ -23,6 +37,8 @@ public:
|
||||
Intersection(double t, Shape *object) : t(t), object(object) { };
|
||||
bool nothing() { return (this->object == nullptr); };
|
||||
|
||||
Computation prepareComputation(Ray r);
|
||||
|
||||
bool operator==(const Intersection &b) const { return ((this->t == b.t) && (this->object == b.object)); };
|
||||
};
|
||||
|
||||
|
||||
@@ -39,6 +39,11 @@ public:
|
||||
bool lightIsIn(Light &l);
|
||||
bool objectIsIn(Shape &s);
|
||||
|
||||
Shape *getObject(int i) { return this->objectList[i]; };
|
||||
|
||||
Tuple shadeHit(Computation comps);;
|
||||
Tuple colourAt(Ray r);
|
||||
|
||||
Intersect intersect(Ray r);
|
||||
|
||||
};
|
||||
|
||||
32
source/intersection.cpp
Normal file
32
source/intersection.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* DoRayMe - a quick and dirty Raytracer
|
||||
* Intersection implementation
|
||||
*
|
||||
* Created by Manoël Trapier
|
||||
* Copyright (c) 2020 986-Studio.
|
||||
*
|
||||
*/
|
||||
#include <intersection.h>
|
||||
#include <shape.h>
|
||||
|
||||
Computation Intersection::prepareComputation(Ray r)
|
||||
{
|
||||
Tuple hitP = r.position(this->t);
|
||||
Tuple normalV = this->object->normalAt(hitP);
|
||||
Tuple eyeV = -r.direction;
|
||||
bool inside;
|
||||
|
||||
if (normalV.dot(eyeV) < 0)
|
||||
{
|
||||
inside = true;
|
||||
normalV = -normalV;
|
||||
}
|
||||
|
||||
|
||||
return Computation(this->object,
|
||||
this->t,
|
||||
hitP,
|
||||
eyeV,
|
||||
normalV,
|
||||
inside);
|
||||
}
|
||||
@@ -90,4 +90,23 @@ Intersect World::intersect(Ray r)
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Tuple World::shadeHit(Computation comps)
|
||||
{
|
||||
return comps.object->material.lighting(*this->lightList[0], comps.hitPoint, comps.eyeVector, comps.normalVector);
|
||||
}
|
||||
|
||||
Tuple World::colourAt(Ray r)
|
||||
{
|
||||
Intersection hit = this->intersect(r).hit();
|
||||
|
||||
if (hit.nothing())
|
||||
{
|
||||
return Colour(0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this->shadeHit(hit.prepareComputation(r));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user