00001 #ifndef RAY_H_ 00002 #define RAY_H_ 00003 00004 #include "math/rcrtmath.h" 00005 #include <complex> 00006 00007 namespace rcrt 00008 { 00009 00010 class Object; 00011 00015 class Ray 00016 { 00017 private: 00018 Point3D origin; 00019 Vec3D direction; 00020 Vec3D invdir; 00021 int dirsign[3];//precomputation for BIH efficiency 00022 float minDistance; 00023 float maxDistance; 00024 float currDistance;//only used for beer's law 00025 int depth; 00026 bool cullBackFaces;//for debugging purposes 00027 std::complex<float> lastIOR;//ior of previously travelled material 00028 Object* lastObject;//previously intersected object 00029 float weight;//an approximate influence to the final pixel 00030 00031 public: 00032 Ray(const Point3D& o, const Vec3D& dir, int d = 0, float weight = 1.0f, bool cull = false); 00033 virtual ~Ray(); 00034 00035 const Point3D& org() const; 00036 const Vec3D& dir() const; 00037 const Vec3D& invDir() const; 00038 void setMinDist(float minD); 00039 void setMaxDist(float maxD); 00040 void setCurrDist(float currD); 00041 void setDepth(int d); 00042 float minDist() const; 00043 float maxDist() const; 00044 float currDist() const; 00045 int getDepth() const; 00046 const int* dirSign() const; 00047 Point3D atDistance(float d) const; 00048 const bool& cull() const; 00049 void setLastIOR(const std::complex<float> ior); 00050 const std::complex<float>& getLastIOR() const; 00051 void setLastObject(Object* obj); 00052 Object* getLastObject(); 00053 const float& getWeight() const; 00054 00055 //for debugging and bih visualization 00056 int tris; 00057 int bihnodes; 00058 }; 00059 00060 inline std::ostream& operator<<(std::ostream& o, const Ray& r) 00061 { 00062 o << "Ray(" << r.org() << " -> " << r.dir() << "|minD="<<r.minDist() 00063 << " maxD="<<r.maxDist() << " currD="<< r.currDist() << ")"; 00064 return o; 00065 } 00066 00067 } 00068 00069 #endif /*RAY_H_*/