diff --git a/primitive/sphere.cpp b/primitive/sphere.cpp index fc4e76e..0029a7b 100644 --- a/primitive/sphere.cpp +++ b/primitive/sphere.cpp @@ -36,7 +36,9 @@ bool Sphere::intersect(Ray &ray) const { return false; // Calculate the normal - // IMPLEMENT ME + auto intersectPoint = ray.origin + ray.direction * t; + auto normalDirection = intersectPoint - this->center; // Point of intersect - origin of sphere creates a line along the normal, pointing outwards + ray.normal = normalized(normalDirection); // Calculate the surface position and tangent vector float const phi = std::acos(ray.normal.y); diff --git a/primitive/triangle.cpp b/primitive/triangle.cpp index ae98206..41c9661 100644 --- a/primitive/triangle.cpp +++ b/primitive/triangle.cpp @@ -35,7 +35,7 @@ bool Triangle::intersectArea(Ray &ray) const { float const cosine = dotProduct(ray.direction, normal); - if (abs(cosine) < EPSILON) + if (std::abs(cosine) < EPSILON) return false; float const t = dotProduct(vertex[0] - ray.origin, normal) / cosine; @@ -57,6 +57,7 @@ bool Triangle::intersectArea(Ray &ray) const { ray.surface = a * this->surface[1] + b * this->surface[2] + (1 - a - b) * this->surface[0]; // Set the new length and the current primitive + ray.normal = normal; ray.length = t; ray.primitive = this;