Move the cross product to Tuple instead of just vector (to ease some stuff later, but this is invalid on Points)
This commit is contained in:
@@ -41,6 +41,8 @@ public:
|
|||||||
double magnitude();
|
double magnitude();
|
||||||
Tuple normalise();
|
Tuple normalise();
|
||||||
double dot(const Tuple &b);
|
double dot(const Tuple &b);
|
||||||
|
|
||||||
|
Tuple cross(const Tuple &b) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Point: public Tuple
|
class Point: public Tuple
|
||||||
@@ -53,7 +55,6 @@ class Vector: public Tuple
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Vector(double x, double y, double z) : Tuple(x, y, z, 0.0) {};
|
Vector(double x, double y, double z) : Tuple(x, y, z, 0.0) {};
|
||||||
Vector cross(const Vector &b) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*DORAYME_TUPLE_H*/
|
#endif /*DORAYME_TUPLE_H*/
|
||||||
|
|||||||
@@ -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;
|
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,
|
return Tuple(this->y * b.z - this->z * b.y,
|
||||||
this->z * b.x - this->x * b.z,
|
this->z * b.x - this->x * b.z,
|
||||||
this->x * b.y - this->y * b.x);
|
this->x * b.y - this->y * b.x,
|
||||||
|
0);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user