Add operator<< overloads for Vector3, Ray, and Color

This commit is contained in:
Eryn Wells 2013-09-22 10:15:41 -07:00
parent 2ea0589b44
commit c6b8b167ca
2 changed files with 33 additions and 0 deletions

View file

@ -242,6 +242,15 @@ operator*(const float &lhs, const Vector3 &rhs)
return rhs * lhs; 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 #pragma mark - Rays
/* /*
@ -276,6 +285,14 @@ Ray::parameterize(const float t)
return origin + t * direction; return origin + t * direction;
} }
std::ostream &
operator<<(std::ostream &os, const Ray &r)
{
os << "[Ray " << r.origin << " " << r.direction << "]";
return os;
}
#pragma mark - Colors #pragma mark - Colors
const Color Color::Black = Color(); const Color Color::Black = Color();
@ -482,3 +499,12 @@ operator*(const float &lhs, const Color &rhs)
{ {
return rhs * lhs; 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;
}

View file

@ -12,6 +12,9 @@
#ifndef __BASICS_H__ #ifndef __BASICS_H__
#define __BASICS_H__ #define __BASICS_H__
#include <iostream>
struct Vector3 struct Vector3
{ {
Vector3(); Vector3();
@ -46,6 +49,7 @@ struct Vector3
}; };
const Vector3 operator*(const float &lhs, const Vector3 &rhs); const Vector3 operator*(const float &lhs, const Vector3 &rhs);
std::ostream &operator<<(std::ostream &os, const Vector3 &v);
struct Ray struct Ray
@ -58,6 +62,8 @@ struct Ray
Vector3 origin, direction; Vector3 origin, direction;
}; };
std::ostream &operator<<(std::ostream &os, const Ray &r);
struct Color struct Color
{ {
@ -96,5 +102,6 @@ struct Color
}; };
const Color operator*(const float &lhs, const Color &rhs); const Color operator*(const float &lhs, const Color &rhs);
std::ostream &operator<<(std::ostream &os, const Color &c);
#endif #endif