OPC_RayTriOverlap.h
Go to the documentation of this file.
1 #define LOCAL_EPSILON 0.000001f
2 
4 
15 inline_ BOOL RayCollider::RayTriOverlap(const Point& vert0, const Point& vert1, const Point& vert2)
17 {
18  // Stats
20 
21  // Find vectors for two edges sharing vert0
22  Point edge1 = vert1 - vert0;
23  Point edge2 = vert2 - vert0;
24 
25  // Begin calculating determinant - also used to calculate U parameter
26  Point pvec = mDir^edge2;
27 
28  // If determinant is near zero, ray lies in plane of triangle
29  float det = edge1|pvec;
30 
31  if(mCulling)
32  {
33  if(det<LOCAL_EPSILON) return FALSE;
34  // From here, det is > 0. So we can use integer cmp.
35 
36  // Calculate distance from vert0 to ray origin
37  Point tvec = mOrigin - vert0;
38 
39  // Calculate U parameter and test bounds
40  mStabbedFace.mU = tvec|pvec;
41 // if(IR(u)&0x80000000 || u>det) return FALSE;
43 
44  // Prepare to test V parameter
45  Point qvec = tvec^edge1;
46 
47  // Calculate V parameter and test bounds
48  mStabbedFace.mV = mDir|qvec;
50 
51  // Calculate t, scale parameters, ray intersects triangle
52  mStabbedFace.mDistance = edge2|qvec;
53  // Det > 0 so we can early exit here
54  // Intersection point is valid if distance is positive (else it can just be a face behind the orig point)
56  // Else go on
57  float OneOverDet = 1.0f / det;
58  mStabbedFace.mDistance *= OneOverDet;
59  mStabbedFace.mU *= OneOverDet;
60  mStabbedFace.mV *= OneOverDet;
61  }
62  else
63  {
64  // the non-culling branch
65  if(det>-LOCAL_EPSILON && det<LOCAL_EPSILON) return FALSE;
66  float OneOverDet = 1.0f / det;
67 
68  // Calculate distance from vert0 to ray origin
69  Point tvec = mOrigin - vert0;
70 
71  // Calculate U parameter and test bounds
72  mStabbedFace.mU = (tvec|pvec) * OneOverDet;
73 // if(IR(u)&0x80000000 || u>1.0f) return FALSE;
75 
76  // prepare to test V parameter
77  Point qvec = tvec^edge1;
78 
79  // Calculate V parameter and test bounds
80  mStabbedFace.mV = (mDir|qvec) * OneOverDet;
82 
83  // Calculate t, ray intersects triangle
84  mStabbedFace.mDistance = (edge2|qvec) * OneOverDet;
85  // Intersection point is valid if distance is positive (else it can just be a face behind the orig point)
87  }
88  return TRUE;
89 }
#define IR(x)
Integer representation of a floating-point value.
Definition: IceFPU.h:18
#define FALSE
Definition: OPC_IceHook.h:9
#define IS_NEGATIVE_FLOAT(x)
Definition: IceFPU.h:32
udword mNbRayPrimTests
Number of Ray-Primitive tests.
inline_ BOOL RayTriOverlap(const Point &vert0, const Point &vert1, const Point &vert2)
#define LOCAL_EPSILON
#define TRUE
Definition: OPC_IceHook.h:13
#define inline_
Point mDir
Ray direction (normalized)
Definition: IcePoint.h:25
double det(const dmatrix &_a)
int BOOL
Another boolean type.
Definition: IceTypes.h:102
float mV
Impact barycentric coordinates.
bool mCulling
Stab culled faces or not.
Point mOrigin
Ray origin.
float mDistance
Distance from collider to hitpoint.
#define IEEE_1_0
integer representation of 1.0
Definition: IceTypes.h:132
CollisionFace mStabbedFace
Current stabbed face.


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat May 8 2021 02:42:39