aboutsummaryrefslogtreecommitdiffstats
path: root/src/vec3.cpp
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2020-12-20 21:59:33 +0100
committerladevieq <ladevie.quentin@gmail.com>2020-12-20 21:59:33 +0100
commitc7c4f8f82c66cfe89b72d176ee51dab8bd30dc95 (patch)
treed0c2caeccda953d86806cb7c7b27c8941e0ef845 /src/vec3.cpp
parentfc601fd503ec1ebd08e4daffeb9aa0812aff2b71 (diff)
Add hittable interface and hit infos on hit
Diffstat (limited to 'src/vec3.cpp')
-rw-r--r--src/vec3.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/vec3.cpp b/src/vec3.cpp
index fdd8969..b850bfc 100644
--- a/src/vec3.cpp
+++ b/src/vec3.cpp
@@ -4,10 +4,12 @@ vec3::vec3(): x(0.0), y(0.0), z(0.0) {}
vec3::vec3(double x, double y, double z): x(x), y(y), z(z) {}
-void vec3::operator-() {
- x = -x;
- y = -y;
- z = -z;
+vec3 vec3::operator-() const {
+ return vec3 {
+ -x,
+ -y,
+ -z
+ };
}
vec3& vec3::operator+=(vec3& vec) {
@@ -34,11 +36,11 @@ vec3& vec3::operator/=(double numerator) {
return *this;
}
-double vec3::length() {
+double vec3::length() const {
return sqrt(length_sq());
}
-double vec3::length_sq() {
+double vec3::length_sq() const {
return x * x + y * y + z * z;
}
@@ -54,7 +56,7 @@ vec3 vec3::cross(const vec3& vec) const {
);
}
-vec3 vec3::unit() {
+vec3 vec3::unit() const {
return *this / length();
}