|
Ray Tracer
2020
|
Class for Sphere objects. More...
#include <Sphere.h>
Public Member Functions | |
| Sphere () | |
| Sphere default constructor. More... | |
| Sphere (const Sphere &sphere) | |
| Sphere copy constructor. More... | |
| ~Sphere () | |
| Sphere destructor. More... | |
| Sphere & | operator= (const Sphere &sphere) |
| Sphere assignment operator. More... | |
| std::vector< RayIntersection > | intersect (const Ray &ray) const |
| Sphere-Ray intersection computation. More... | |
Additional Inherited Members | |
Public Attributes inherited from Object | |
| Transform | transform |
| A 3D transformation to apply to this Object. More... | |
| Material | material |
| The colour and reflectance properties of the Object. More... | |
Protected Member Functions inherited from Object | |
| Object () | |
| Object default constructor. More... | |
| Object (const Object &object) | |
| Object copy constructor. More... | |
| virtual | ~Object () |
| Object destructor. More... | |
| Object & | operator= (const Object &object) |
| Object assignment operator. More... | |
Class for Sphere objects.
This class provides an Object which is a sphere centred at the origin with radius 1., as illustrated below:
| Sphere::Sphere | ( | ) |
| Sphere::Sphere | ( | const Sphere & | sphere | ) |
| Sphere::~Sphere | ( | ) |
Sphere destructor.
|
virtual |
Sphere-Ray intersection computation.
The intersection of a Ray with a Sphere comes down to a quadratic formula of the form \(at^2 + bt + c\), where \(t\) is the distance along the Ray, and \(a\), \(b\), and \(c\) are some constants. The solutions for \(t\) are given by \($ \frac{-b \pm \sqrt{b^2-4ac}}{2a} \)$ The number of intersections depends on the value of \(b^2-4ac\). If it is negative then the Ray misses the Sphere and there are no intersections. A positive value indicates two intersection (entering and then leaving the Sphere). Finally, if \(b^2-4ac = 0\) then there is a single grazing hit with the Sphere.
Implements Object.