00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LUX_RAY_H
00024 #define LUX_RAY_H
00025
00026 #include <iostream>
00027 #include "vector.h"
00028 #include "point.h"
00029 #include "epsilon.h"
00030
00031 namespace lux
00032 {
00033
00034 class Ray {
00035 public:
00036
00037 Ray(): maxt(INFINITY), time(0.f) {
00038 mint = MachineEpsilon::E(1.f);
00039 }
00040
00041 Ray(const Point &origin, const Vector &direction)
00042 : o(origin), d(direction), maxt(INFINITY), time(0.f) {
00043 mint = MachineEpsilon::E(origin);
00044 }
00045
00046 Ray(const Point &origin, const Vector &direction,
00047 float start, float end = INFINITY, float t = 0.f)
00048 : o(origin), d(direction), mint(start), maxt(end), time(t) { }
00049
00050 Point operator()(float t) const { return o + d * t; }
00051 void GetDirectionSigns(int signs[3]) const {
00052 signs[0] = d.x < 0.f;
00053 signs[1] = d.y < 0.f;
00054 signs[2] = d.z < 0.f;
00055 }
00056
00057 Point o;
00058 Vector d;
00059 mutable float mint, maxt;
00060 float time;
00061 };
00062
00063 inline ostream &operator<<(ostream &os, Ray &r) {
00064 os << "org: " << r.o << "dir: " << r.d << " range [" <<
00065 r.mint << "," << r.maxt << "] time = " <<
00066 r.time;
00067 return os;
00068 }
00069
00070 }
00071
00072 #endif //LUX_RAY_H