00001
00005 #ifndef HitRecord_h
00006 #define HitRecord_h
00007
00008 class Material;
00009 class Primitive;
00010 #define EPSILON (1.e-6)
00011
00014 class HitRecord {
00015 public:
00017 HitRecord(double max) {
00018 prim = 0;
00019 matl = 0;
00020 min = max;
00021 epsilon = EPSILON;
00022 }
00024 HitRecord(double max, double ep) {
00025 prim = 0;
00026 matl = 0;
00027 min = max;
00028 epsilon = ep;
00029 }
00030 ~HitRecord() {
00031 }
00032
00034 bool hit(double t, const Primitive* hit_prim, const Material* hit_matl) {
00035 if(t > epsilon && t < min){
00036 min = t;
00037 prim = hit_prim;
00038 matl = hit_matl;
00039 return true;
00040 } else {
00041 return false;
00042 }
00043 }
00044 double minT() const {
00045 return min;
00046 }
00047 const Primitive* getPrimitive() const {
00048 return prim;
00049 }
00050 const Material* getMaterial() const {
00051 return matl;
00052 }
00053
00054 template< typename T >
00055 T* getScratchpad()
00056 {
00057 char unnamed[ ( sizeof( T ) <= sizeof( scratchdata ) ) ? 1 : 0 ];
00058 return reinterpret_cast< T * >( scratchdata );
00059 }
00060 template< typename T >
00061 const T* getScratchpad() const
00062 {
00063 char unnamed[ ( sizeof( T ) <= sizeof( scratchdata ) ) ? 1 : 0 ];
00064 return reinterpret_cast< const T * >( scratchdata );
00065 }
00066 char scratchdata[128];
00067 private:
00068 const Primitive* prim;
00069 const Material* matl;
00070 double min;
00071 double epsilon;
00072
00073 };
00074
00075 #endif