From 4348cc9581bfea05359485c5d2d074132d0271da Mon Sep 17 00:00:00 2001 From: Julian T Date: Thu, 6 Aug 2020 19:21:49 +0200 Subject: Renders scenes with a single hardcoded light and green objects --- src/vector.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/vector.cpp') 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 +#include 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 + ); +} -- cgit v1.2.3