From 17aebe653807488fe3e7a1cb68997137fdbd8466 Mon Sep 17 00:00:00 2001 From: Godzil Date: Mon, 17 Feb 2020 13:53:30 +0000 Subject: [PATCH] Move the cross product to Tuple instead of just vector (to ease some stuff later, but this is invalid on Points) --- source/include/tuple.h | 3 ++- source/tuple.cpp | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/source/include/tuple.h b/source/include/tuple.h index 58d2624..67d87ac 100644 --- a/source/include/tuple.h +++ b/source/include/tuple.h @@ -41,6 +41,8 @@ public: double magnitude(); Tuple normalise(); double dot(const Tuple &b); + + Tuple cross(const Tuple &b) const; }; class Point: public Tuple @@ -53,7 +55,6 @@ class Vector: public Tuple { public: Vector(double x, double y, double z) : Tuple(x, y, z, 0.0) {}; - Vector cross(const Vector &b) const; }; #endif /*DORAYME_TUPLE_H*/ diff --git a/source/tuple.cpp b/source/tuple.cpp index 0cdcdcc..19fa169 100644 --- a/source/tuple.cpp +++ b/source/tuple.cpp @@ -27,9 +27,10 @@ double Tuple::dot(const Tuple &b) return this->x * b.x + this->y * b.y + this->z * b.z + this->w * b.w; } -Vector Vector::cross(const Vector &b) const +Tuple Tuple::cross(const Tuple &b) const { - return Vector(this->y * b.z - this->z * b.y, - this->z * b.x - this->x * b.z, - this->x * b.y - this->y * b.x); + return Tuple(this->y * b.z - this->z * b.y, + this->z * b.x - this->x * b.z, + this->x * b.y - this->y * b.x, + 0); } \ No newline at end of file