Skip to content
Snippets Groups Projects
Ray.cpp 631 B
Newer Older
Postea's avatar
Postea committed
#include "Ray.h"

namespace cam {
Yoel's avatar
Yoel committed
Ray::Ray(const util::Vec3& x0, const util::Vec3& arg_d, float tmin, float tmax,
         bool normalize)
    : x0(x0), tmin(tmin), tmax(tmax), normalize(normalize) {
	if (normalize)
		d = arg_d.normalize();
	else
		d = arg_d;
Yoel's avatar
Yoel committed
// Returns the value of the ray function at t
Yoel's avatar
Yoel committed
util::Vec3 Ray::operator()(float t) const {
	return x0 + (d * t);
Yoel's avatar
Yoel committed
// Check if t is within the rays bounds
Yoel's avatar
Yoel committed
bool Ray::in_range(float t) const {
	return t <= tmax && t >= tmin;
Yoel's avatar
Yoel committed
std::ostream& operator<<(std::ostream& os, const cam::Ray& rhs) {
	os << "(" << rhs.x0 << " " << rhs.d << ")";
	return os;
Postea's avatar
Postea committed
}
Yoel's avatar
Yoel committed
}  // namespace cam