diff options
Diffstat (limited to 'hw2/include/ray.h')
-rw-r--r-- | hw2/include/ray.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/hw2/include/ray.h b/hw2/include/ray.h new file mode 100644 index 0000000..743375f --- /dev/null +++ b/hw2/include/ray.h @@ -0,0 +1,69 @@ +/******************************************************************/ +/* This file is part of the homework assignments for CSCI-427/527 */ +/* at The College of William & Mary and authored by Pieter Peers. */ +/* No part of this file, whether altered or in original form, can */ +/* be distributed or used outside the context of CSCI-427/527 */ +/* without consent of either the College of William & Mary or */ +/* Pieter Peers. */ +/******************************************************************/ +#ifndef _RAY_H_ +#define _RAY_H_ + +#include <ostream> +#include "vec3d.h" +#include "transformation3d.h" + +class ray { + public: + ////////////////// + // Constructors // + ////////////////// + ray(const vec3d& origin = vec3d(), const vec3d& direction = vec3d()); + ray(const ray& src); + + //////////////// + // Inspectors // + //////////////// + const vec3d& origin(void) const { return _origin; } + const vec3d& direction(void) const { return _direction; } + + /////////////// + // Operators // + /////////////// + ray& operator=(const ray& r); + vec3d operator()(float t) const; + float operator()(const vec3d& point) const; + + ////////////// + // Mutators // + ////////////// + ray& transform(const transformation3d& t); + ray& inverseTransform(const transformation3d& t); + + ///////////// + // Friends // + ///////////// + friend void swap(ray& a, ray& b) { a._swap(b); } + friend ray transform(const ray& r, const transformation3d& t) { return ray(r).transform(t); } + friend ray inverseTransform(const ray& r, const transformation3d& t) { return ray(r).inverseTransform(t); } + friend std::ostream& operator<<(std::ostream& s, const ray& r) + { + s << r.origin() << "->" << r.direction(); + return s; + } + + private: + ///////////////////// + // Private Methods // + ///////////////////// + void _swap(ray& r); + void _assign(const ray& r); + + ////////////////// + // Data Members // + ////////////////// + vec3d _origin; + vec3d _direction; +}; + +#endif /* _RAY_H_ */ |