-
Notifications
You must be signed in to change notification settings - Fork 0
/
sphere.h
54 lines (49 loc) · 1.34 KB
/
sphere.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @file sphere.h
* @brief Defines the Sphere class that represents a sphere in a 3D scene.
* @implements Shape
*/
#ifndef SPHERE_H
#define SPHERE_H
#include "vector3f.h"
#include "ray3f.h"
#include "shape.h"
#include "material.h"
/**
* @class Sphere
* @brief Represents a sphere in 3D space.
*/
class Sphere : public Shape {
private:
/**
* @brief The origin of the sphere.
*/
Vector3f origin;
/**
* @brief The radius of the sphere.
*/
float radius;
public:
/**
* @brief Indicates whether a given ray intersects this shape.
* @param ray The ray to test for intersection.
* @return true if the ray intersects this shape, false otherwise.
*/
bool isHit(Ray3f ray) const;
/**
* @brief Computes the reflected ray when a given ray hits this shape.
* @param ray The ray that hits this shape.
* @return The reflected ray.
*/
Ray3f reflect(Ray3f ray) const;
/**
* @brief Constructs a new Sphere object with the given values.
* @param position_ The origin of the sphere.
* @param radius_ The radius of the sphere.
* @throw runtime_error if the radius is negative.
*/
Sphere(Vector3f origin_, float radius_, Material matter_);
Sphere() = default;
friend std::ostream & operator<< (std::ostream &st, const Sphere &s);
};
#endif