Ray Struct Reference

Structure with ray data. More...

#include <3dmath.h>

List of all members.

Public Member Functions

 Ray (vector3 &orig, vector3 &dir)
 Constructor.
 Ray (const Ray &ray)
 Copy constructor.
float GetIntersectionDist (const plane &pln) const
 Get intersection distance from origin to plane.
vector3 GetIntersection (const plane &pln) const
 Get intersection point between plane and ray.
bool IntersectsTri (const vector3 &v0, const vector3 &v1, const vector3 &v2, float *dist=(float *) NULL) const
 Check if ray intersects given triangle.
RayClone () const
 Get copy of instance.

Public Attributes

vector3 origin
 Ray origin.
vector3 direction
 Ray direction.


Detailed Description

Structure with ray data.

Definition at line 1024 of file 3dmath.h.


Constructor & Destructor Documentation

Ray::Ray ( vector3 orig,
vector3 dir 
) [inline]

Constructor.

Definition at line 1033 of file 3dmath.h.

01034        {
01035               origin = orig;
01036               direction = dir;
01037        }

Ray::Ray ( const Ray ray  )  [inline]

Copy constructor.

Definition at line 1039 of file 3dmath.h.

01039                             : origin(ray.origin), direction(ray.direction)
01040        {
01041        }


Member Function Documentation

float Ray::GetIntersectionDist ( const plane pln  )  const [inline]

Get intersection distance from origin to plane.

Definition at line 1044 of file 3dmath.h.

01045        {
01046               return -pln.DotCoord(origin) / direction.Dot(vector3(pln._p));
01047        }

vector3 Ray::GetIntersection ( const plane pln  )  const [inline]

Get intersection point between plane and ray.

Definition at line 1050 of file 3dmath.h.

01051        {
01052               return origin + direction * GetIntersectionDist(pln);
01053        }

bool Ray::IntersectsTri ( const vector3 v0,
const vector3 v1,
const vector3 v2,
float *  dist = (float *)NULL 
) const [inline]

Check if ray intersects given triangle.

Definition at line 1057 of file 3dmath.h.

01058        {
01059 #define MOLLER_RAY_TRI_INTERSECTION 1
01060 #if !MOLLER_RAY_TRI_INTERSECTION
01061 
01062          const vector3 edge1 = v1 - v0;
01063               const vector3 edge2 = v2 - v0;
01064 
01065               /* begin calculating determinant - also used to calculate U parameter */
01066               vector3 pvec = direction.Cross(edge2);
01067 
01068               /* if determinant is near zero, ray lies in plane of triangle */
01069               const float det = fabsf( edge1.Dot(pvec) ); // = vector3U::TripleProduct(dir,edge1,edge2);
01070 
01071               /* calculate distance from vert0 to ray origin */
01072               const vector3 tvec = origin - v0;
01073 
01074               /* calculate U parameter and test bounds */
01075               const float u = tvec.Dot(pvec); // = vector3U::TripleProduct(dir,edge2,tvec);
01076               if ( u < 0 || u > det )
01077                      return false;
01078 
01079               /* prepare to test V parameter */
01080               /* calculate V parameter and test bounds */
01081               const float v = direction.Dot( tvec.Cross(edge1) ); // = dir * (tvec ^ edge1)
01082               if ( v < 0 || u + v > det )
01083                      return false;
01084 
01085               float intDist = GetIntersectionDist(plane::FromPoints(v0, v1, v2));
01086               if (intDist < 0)
01087                      return false;
01088               else if (dist)
01089                      *dist = intDist;
01090 
01091               return true;
01092 #else
01093               const float threshold = 1e-6f;
01094               const vector3 e1 = v0 - v1;
01095               const vector3 e2 = v2 - v1;
01096               const vector3 dir = direction;
01097               const vector3 p = dir.Cross(e2);
01098               float det = e1.Dot(p);
01099               const vector3 w0 = origin - v1;
01100               const float u = w0.Dot(p);
01101               const vector3 q = w0.Cross(e1);
01102               const float v = dir.Dot(q);
01103 
01104 
01105               if (det > threshold) {
01106                 if (u < 0.0f || u > det)
01107                      return false;
01108                 if (v < 0.0f || u + v > det)
01109                      return false;
01110               }
01111               else
01112                 if (det < -threshold)
01113                      {
01114                        if (u > 0.0 || u < det)
01115                             return false;
01116                        if (v > 0.0 || u + v < det)
01117                             return false;
01118                      } else
01119                        return false;
01120 
01121               float t = e2.Dot(q) / det;
01122 
01123               if (t < 0.0f)
01124                 return false;
01125 
01126               if (dist)
01127                 *dist = t;
01128               return true;
01129 #endif
01130 
01131        }

Ray* Ray::Clone (  )  const [inline]

Get copy of instance.

Definition at line 1134 of file 3dmath.h.

01135        {
01136               return new Ray(*this);
01137        }


Member Data Documentation

Ray origin.

Definition at line 1028 of file 3dmath.h.

Ray direction.

Definition at line 1030 of file 3dmath.h.


The documentation for this struct was generated from the following file:

Generated on Tue Mar 10 14:41:38 2009 for VRUT by  doxygen 1.5.5