-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCLine.hpp
50 lines (37 loc) · 969 Bytes
/
CLine.hpp
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
//
// Created by Tizian Rettig on 09.12.2020.
//
#ifndef RAYTRACER_CLINE_HPP
#define RAYTRACER_CLINE_HPP
#include "Vec.hpp"
/**
* Simple line class representing a line with the vector equation: l = OA + t * AB where:
* - OA is the vector from the origin to point a
* - AB is the vector from a to b
* - t is any scalar
* @see https://en.wikipedia.org/wiki/Line_(geometry)
*/
class CLine {
public:
CLine() {
m_p1 = Vec();
m_direction = normalize(Vec());
}
CLine(const Vec& p, const Vec& dir) {
m_p1 = p;
m_direction = normalize(dir);
}
[[nodiscard]] Vec pointAt(double t) const {
return m_p1 + m_direction * static_cast<float>(t);
}
[[nodiscard]] Vec const &getP1() const {
return m_p1;
}
[[nodiscard]] Vec const &getDirection() const {
return m_direction;
}
private:
Vec m_p1; // OA
Vec m_direction; // AB
};
#endif //RAYTRACER_CLINE_HPP