29#ifndef GU_INTERSECTION_RAY_TRIANGLE_H
30#define GU_INTERSECTION_RAY_TRIANGLE_H
32#include "foundation/PxVec3.h"
33#include "common/PxPhysXCommonConfig.h"
50 #define GU_CULLING_EPSILON_RAY_TRIANGLE FLT_EPSILON*FLT_EPSILON
74 PxReal& at, PxReal& au, PxReal& av,
75 bool cull,
float enlarge=0.0f)
78 const PxVec3 edge1 = vert1 - vert0;
79 const PxVec3 edge2 = vert2 - vert0;
85 const PxReal det = edge1.
dot(pvec);
89 if(det<GU_CULLING_EPSILON_RAY_TRIANGLE)
93 const PxVec3 tvec = orig - vert0;
96 const PxReal u = tvec.
dot(pvec);
98 const PxReal enlargeCoeff = enlarge*det;
99 const PxReal uvlimit = -enlargeCoeff;
100 const PxReal uvlimit2 = det + enlargeCoeff;
102 if(u<uvlimit || u>uvlimit2)
109 const PxReal v = dir.
dot(qvec);
110 if(v<uvlimit || (u+v)>uvlimit2)
114 const PxReal t = edge2.
dot(qvec);
116 const PxReal inv_det = 1.0f / det;
124 if(
PxAbs(det)<GU_CULLING_EPSILON_RAY_TRIANGLE)
127 const PxReal inv_det = 1.0f / det;
130 const PxVec3 tvec = orig - vert0;
133 const PxReal u = tvec.
dot(pvec) * inv_det;
134 if(u<-enlarge || u>1.0f+enlarge)
141 const PxReal v = dir.
dot(qvec) * inv_det;
142 if(v<-enlarge || (u+v)>1.0f+enlarge)
146 const PxReal t = edge2.
dot(qvec) * inv_det;
158 PxReal& t, PxReal& u, PxReal& v,
165 PX_FORCE_INLINE bool intersectRayTriangleNoCulling(
const PxVec3& orig,
const PxVec3& dir,
166 const PxVec3& vert0,
const PxVec3& vert1,
const PxVec3& vert2,
167 PxReal& t, PxReal& u, PxReal& v,
3 Element vector class.
Definition PxVec3.h:50
PX_CUDA_CALLABLE PX_FORCE_INLINE float dot(const PxVec3 &v) const
returns the scalar product of this and other.
Definition PxVec3.h:276
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 cross(const PxVec3 &v) const
cross product
Definition PxVec3.h:284
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
PX_FORCE_INLINE bool intersectRayTriangle(const PxVec3 &orig, const PxVec3 &dir, const PxVec3 &vert0, const PxVec3 &vert1, const PxVec3 &vert2, PxReal &at, PxReal &au, PxReal &av, bool cull, float enlarge=0.0f)
Definition GuIntersectionRayTriangle.h:72
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_CUDA_CALLABLE PX_FORCE_INLINE float PxAbs(float a)
abs returns the absolute value of its argument.
Definition PxMath.h:109