Add operator<< overloads for Vector3, Ray, and Color
This commit is contained in:
parent
2ea0589b44
commit
c6b8b167ca
2 changed files with 33 additions and 0 deletions
|
@ -242,6 +242,15 @@ operator*(const float &lhs, const Vector3 &rhs)
|
|||
return rhs * lhs;
|
||||
}
|
||||
|
||||
|
||||
std::ostream &
|
||||
operator<<(std::ostream &os, const Vector3 &v)
|
||||
{
|
||||
// Stream the vector like this: <x, y, z>
|
||||
os << "<" << v.x << ", " << v.y << ", " << v.z << ">";
|
||||
return os;
|
||||
}
|
||||
|
||||
#pragma mark - Rays
|
||||
|
||||
/*
|
||||
|
@ -276,6 +285,14 @@ Ray::parameterize(const float t)
|
|||
return origin + t * direction;
|
||||
}
|
||||
|
||||
|
||||
std::ostream &
|
||||
operator<<(std::ostream &os, const Ray &r)
|
||||
{
|
||||
os << "[Ray " << r.origin << " " << r.direction << "]";
|
||||
return os;
|
||||
}
|
||||
|
||||
#pragma mark - Colors
|
||||
|
||||
const Color Color::Black = Color();
|
||||
|
@ -482,3 +499,12 @@ operator*(const float &lhs, const Color &rhs)
|
|||
{
|
||||
return rhs * lhs;
|
||||
}
|
||||
|
||||
|
||||
std::ostream &
|
||||
operator<<(std::ostream &os, const Color &c)
|
||||
{
|
||||
// Stream colors like this: <r, g, b, a>
|
||||
os << "<" << c.red << ", " << c.green << ", " << c.blue << ", " << c.alpha << ">";
|
||||
return os;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
#ifndef __BASICS_H__
|
||||
#define __BASICS_H__
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
struct Vector3
|
||||
{
|
||||
Vector3();
|
||||
|
@ -46,6 +49,7 @@ struct Vector3
|
|||
};
|
||||
|
||||
const Vector3 operator*(const float &lhs, const Vector3 &rhs);
|
||||
std::ostream &operator<<(std::ostream &os, const Vector3 &v);
|
||||
|
||||
|
||||
struct Ray
|
||||
|
@ -58,6 +62,8 @@ struct Ray
|
|||
Vector3 origin, direction;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const Ray &r);
|
||||
|
||||
|
||||
struct Color
|
||||
{
|
||||
|
@ -96,5 +102,6 @@ struct Color
|
|||
};
|
||||
|
||||
const Color operator*(const float &lhs, const Color &rhs);
|
||||
std::ostream &operator<<(std::ostream &os, const Color &c);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue