aboutsummaryrefslogtreecommitdiff
path: root/src/vector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/vector.cpp')
-rw-r--r--src/vector.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/vector.cpp b/src/vector.cpp
index 070f956..1e4f5a1 100644
--- a/src/vector.cpp
+++ b/src/vector.cpp
@@ -1,6 +1,7 @@
#include "vector.hpp"
#include <math.h>
+#include <stdexcept>
Vec3d::Vec3d() {
set(0, 0, 0);
@@ -19,7 +20,7 @@ void Vec3d::set(double x, double y, double z) {
void Vec3d::normalize() {
auto len = length();
if (len == 0) {
- throw "Normalizing zero vector";
+ throw std::runtime_error("Normalizing zero vector");
}
m_x /= len;
@@ -35,6 +36,22 @@ double Vec3d::dot(const Vec3d &vec) const {
return m_x * vec.m_x + m_y * vec.m_y + m_z * vec.m_z;
}
+Vec3d Vec3d::cross(const Vec3d &vec) const {
+ return Vec3d(
+ m_y * vec.m_z - m_z * vec.m_y,
+ m_z * vec.m_x - m_x * vec.m_z,
+ m_x * vec.m_y - m_y * vec.m_x
+ );
+}
+
+Vec3d Vec3d::operator+(const Vec3d &vec) const {
+ return Vec3d(
+ m_x + vec.m_x,
+ m_y + vec.m_y,
+ m_z + vec.m_z
+ );
+}
+
Vec3d Vec3d::operator-(const Vec3d &vec) const {
return Vec3d(
m_x - vec.m_x,
@@ -51,3 +68,11 @@ Vec3d Vec3d::operator-() const {
);
}
+
+Vec3d Vec3d::operator*(double op) const {
+ return Vec3d(
+ m_x * op,
+ m_y * op,
+ m_z * op
+ );
+}