Ray.h
Go to the documentation of this file.00001 /**<!--------------------------------------------------------------------> 00002 @class Ray 00003 @author Travis Fischer (fisch0920@gmail.com) 00004 @author Matthew Jacobs (jacobs.mh@gmail.com) 00005 @date Fall 2008 00006 00007 @brief 00008 3-Dimensional Ray (origin + direction), including several 00009 optimization fields (inverse direction and "mailbox ID") 00010 <!-------------------------------------------------------------------->**/ 00011 00012 #ifndef RAY_H_ 00013 #define RAY_H_ 00014 00015 #include <common/math/algebra.h> 00016 00017 struct Ray : public SSEAligned { 00018 00019 ///@name Public Data 00020 //@{----------------------------------------------------------------- 00021 00022 Vector3 direction; 00023 Vector3 invDir; 00024 Point3 origin; 00025 00026 00027 //@}----------------------------------------------------------------- 00028 ///@name Constructors 00029 //@{----------------------------------------------------------------- 00030 00031 inline Ray() 00032 { } 00033 00034 /** 00035 * @param origin_ is the origin of the ray 00036 * @param direction_ is the direction of the ray 00037 */ 00038 inline Ray(const Point3 &origin_, const Vector3 &direction_) 00039 : direction(direction_), 00040 invDir(direction_.getReciprocal()), 00041 origin(origin_) 00042 { } 00043 00044 00045 //@}----------------------------------------------------------------- 00046 00047 /** 00048 * @returns whether or not the given t-value represents a valid 00049 * intersection point 00050 * 00051 * @note a ray defined by P + t*d, where P is the ray's origin, d 00052 * is a direction vector, and t is the distance along the ray in 00053 * meters; with this definition, a valid t-value representing a 00054 * point along the ray where an intersection could have occurred 00055 * is positive (not behind the ray's origin) and not at at infinity. 00056 * In practice, in addition to ensuring that an intersection point's 00057 * t-value is positive, it dramatically increases robustness to 00058 * define valid t-values as greater than an epsilon value to prevent 00059 * self-intersections when a ray's origin and intersection point 00060 * coincide and the calculated t-value is close to zero but not 00061 * necessarily equal to zero due to floating point inprecision; by 00062 * throwing out t-values that are smaller than epsilon, we safeguard 00063 * ourselves from this numerical instability and disregard 00064 * invalid self-intersections 00065 */ 00066 static inline bool isValid(real_t t) { 00067 return (t > EPSILON && t < INFINITY); 00068 } 00069 00070 private: 00071 static unsigned int s_rayID; 00072 }; 00073 00074 #endif // RAY_H_ 00075
Generated on 28 Feb 2009 for Milton by
1.5.6