00001 #ifndef RAY_H 00002 #define RAY_H 00003 00004 00005 #include <cassert> 00006 #include <iosfwd> 00007 00008 #include "Vec3f.h" 00009 #include "defines.h" 00010 00011 00012 class Primitive; 00013 class Object; 00014 00015 00022 class Ray 00023 { 00024 public: 00027 Ray() 00028 : mOrg(), 00029 mDir(), 00030 mT(INFINITY), 00031 mHit(NULL), 00032 mHitObj(NULL), 00033 mU(0.0f), 00034 mV(0.0f), 00035 mInfluence(1.0f), 00036 mRecursionDeep(0) 00037 { 00038 } 00039 00046 void init( const Vec3f & origin, 00047 const Vec3f & direction, 00048 float t = INFINITY ) 00049 { 00050 assert(0.0f <= t); 00051 mOrg = origin; 00052 mDir = direction.normal(); 00053 mT = t + EPSILON; 00054 mHit = NULL; 00055 mHitObj = NULL; 00056 mU = 0.0f; 00057 mV = 0.0f; 00058 mInfluence = 1.0f; 00059 mRecursionDeep = 0; 00060 } 00061 00064 const Vec3f & org() const 00065 { 00066 return mOrg; 00067 } 00068 00071 const Vec3f & dir() const 00072 { 00073 return mDir; 00074 } 00075 00078 float t() const 00079 { 00080 return mT; 00081 } 00082 00087 Vec3f hitPoint(float eps) const 00088 { 00089 return mOrg + (mT + eps) * mDir; 00090 } 00091 00094 const Primitive * hit() const 00095 { 00096 return mHit; 00097 } 00098 00101 void setHit(const Primitive * hit, float t) 00102 { 00103 mHit = hit; 00104 mT = t; 00105 } 00106 00109 const Object * obj() const 00110 { 00111 return mHitObj; 00112 } 00113 00116 void setObj(const Object * object) 00117 { 00118 assert(mHit || !object); 00119 mHitObj = object; 00120 } 00121 00124 float u() const 00125 { 00126 return mU; 00127 } 00128 00131 float v() const 00132 { 00133 return mV; 00134 } 00135 00138 void setUV(float u, float v) 00139 { 00140 mU = u; 00141 mV = v; 00142 } 00143 00146 float influence() const 00147 { 00148 return mInfluence; 00149 } 00150 00153 int recDeep() const 00154 { 00155 return mRecursionDeep; 00156 } 00157 00163 void setInfluence(float infl, int recursionDeep) 00164 { 00165 assert(0.0f <= infl && infl <= 1.0f); 00166 assert(0 <= recursionDeep); 00167 mInfluence = infl; 00168 mRecursionDeep = recursionDeep; 00169 } 00170 00177 void updateInfluence(const Ray & ray, float infl = 1.0f) 00178 { 00179 assert(0.0f <= infl && infl <= 1.0f); 00180 mInfluence = ray.influence() * infl; 00181 mRecursionDeep = ray.recDeep() + 1; 00182 } 00183 00184 private: 00186 Vec3f mOrg; 00187 00189 Vec3f mDir; 00190 00192 float mT; 00193 00195 const Primitive * mHit; 00196 00198 const Object * mHitObj; 00199 00201 float mU; 00202 00204 float mV; 00205 00207 float mInfluence; 00208 00210 int mRecursionDeep; 00211 }; 00212 00213 00216 std::ostream & operator<<(std::ostream & o, const Ray & ray); 00217 00218 00219 #endif 00220