Ray.h

00001 
00006 #ifndef RAY_H
00007 #define RAY_H
00008 
00009 
00010 /*
00011 ** ---------------------------------------------------------------
00012 ** Includes:
00013 */
00014 #include "Polygon.h"
00015 #include "Vector3.h"
00016 #include "Vector4.h"
00017 
00018 /*
00019 ** ---------------------------------------------------------------
00020 ** Definitions:
00021 */
00022 
00024 
00031 class Ray {
00032 
00033 private :
00034 
00036         Vector3 o, d;
00037 public:
00039         Ray(void);
00041         Ray(const Vector3 &o,const Vector3 &d);
00042 
00044         //Vector3 & origin();
00046         Vector3 origin() const;
00047 
00049         //Vector3 & direction();
00051         Vector3 direction() const;
00052 
00054         Ray unit(void);
00055 
00057         virtual void transform(const AffineTransform &r);
00058 
00060         virtual Real intersect(const Vector4 &h);
00061 
00063         virtual Real intersect(const Triangle &p,const Vector4 &plane)
00064 
00065         
00066         virtual Inode *intersect(const Triangle &p,const Vector4 &plane);
00067 
00069         static Vector3 ray_point(const Vector3 &r, Real t);
00070 
00071 };
00072 
00073 
00074 
00075 inline
00076 Ray::Ray(void)
00077 {
00078 }
00079 
00080 inline
00081 Ray::Ray(const Vector3 &o_, const Vector3 &d_)
00082         : o(o_),
00083           d(d_)
00084 {
00085 }
00086 
00087 /*inline Vector3 &
00088 Ray::origin()
00089 {
00090         return o;
00091 }
00092 */
00093 
00094 inline Vector3
00095 Ray::origin() const
00096 {
00097         Vector3 o_(o);
00098         return o_;
00099 }
00100 
00101 /*inline Vector3 &
00102 Ray::direction()
00103 {
00104         return d;
00105 }
00106 */
00107 
00108 inline Vector3
00109 Ray::direction() const
00110 {
00111         Vector3 d_(d);
00112         return d_;
00113 }
00114 
00115 inline Ray
00116 Ray::unit(void)
00117 {
00118   d.unit();
00119   return *this;
00120 }
00121 
00122 inline Vector3
00123 Ray::ray_point(const Ray &r,Real t)
00124 {
00125   return Vector3(r.origin() + (t*r.direction()));
00126 }
00127 
00128 template <typename T>
00129 inline int max3_index(T const& d1,T const& d2,T const& d3)
00130 {
00131         if (d1 > d2)
00132                 return (d1 > d3)? 1 : 3;
00133         else
00134                 return (d2 > d3)? 2 : 3;
00135 }       
00136 
00137 #endif //RAY_H

Generated on Thu Jul 5 00:39:19 2007 for S3D by  doxygen 1.4.6