Add vector reflection via a normal vector.

This commit is contained in:
Godzil
2020-02-17 15:56:08 +00:00
parent a8194169c5
commit aeb4669162
3 changed files with 26 additions and 1 deletions

View File

@@ -41,8 +41,8 @@ public:
double magnitude();
Tuple normalise();
double dot(const Tuple &b);
Tuple cross(const Tuple &b) const;
Tuple reflect(const Tuple &normal);
};
class Point: public Tuple

View File

@@ -33,4 +33,9 @@ Tuple Tuple::cross(const Tuple &b) const
this->z * b.x - this->x * b.z,
this->x * b.y - this->y * b.x,
0);
}
Tuple Tuple::reflect(const Tuple &normal)
{
return *this - normal * 2 * this->dot(normal);
}