Add support for tuples/point/vector and corresponding tests.

This commit is contained in:
Godzil
2020-02-14 14:22:13 +00:00
parent 7b07106816
commit 332e73a3d9
3 changed files with 277 additions and 0 deletions

35
source/tuples.cpp Normal file
View File

@@ -0,0 +1,35 @@
/*
* DoRayMe - a quick and dirty Raytracer
* Tuples implementation
*
* Created by Manoël Trapier
* Copyright (c) 2020 986-Studio.
*
*/
#include <tuples.h>
#include <math.h>
double Tuple::magnitude()
{
return sqrt(pow(this->x, 2) + pow(this->y, 2) + pow(this->z, 2) + pow(this->w, 2));
}
Tuple Tuple::normalise()
{
double mag = this->magnitude();
return Tuple(this->x / mag, this->y / mag, this->z / mag, this->w / mag);
}
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
{
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);
}