/******************************************************************/ /* 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. */ /******************************************************************/ #include "ray.h" ////////////////// // Constructors // ////////////////// ray::ray(const vec3d& origin, const vec3d& direction) { _origin = origin; _direction = normalize(direction); } ray::ray(const ray& r) { _origin = r._origin; _direction = r._direction; } /////////////// // Operators // /////////////// ray& ray::operator=(const ray& r) { _assign(r); return *this; } vec3d ray::operator()(float t) const { return _origin + t*_direction; } float ray::operator()(const vec3d& point) const { return _direction.dot(point - _origin); } ////////////// // Mutators // ////////////// ray& ray::transform(const transformation3d& t) { _origin = t.transformPoint(_origin); _direction = t.transformDirection(_direction); return *this; } ray& ray::inverseTransform(const transformation3d& t) { _origin = t.inverseTransformPoint(_origin); _direction = t.inverseTransformDirection(_direction); return *this; } ///////////////////// // Private Methods // ///////////////////// void ray::_swap(ray& r) { swap(_origin, r._origin); swap(_direction, r._direction); } void ray::_assign(const ray& r) { _origin = r._origin; _direction = r._direction; }