| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Physics/Collision/BackFaceMode.h> |
| 8 |
|
| 9 |
JPH_NAMESPACE_BEGIN |
| 10 |
|
| 11 |
|
| 12 |
template <class Vec, class Mat, class RayCastType> |
| 13 |
struct RayCastT |
| 14 |
{ |
| 15 |
JPH_OVERRIDE_NEW_DELETE |
| 16 |
|
| 17 |
|
| 18 |
RayCastT() = default; |
| 19 |
RayCastT(typename Vec::ArgType inOrigin, Vec3Arg inDirection) : mOrigin(inOrigin), mDirection(inDirection) { } |
| 20 |
RayCastT(const RayCastT<Vec, Mat, RayCastType> &) = default; |
| 21 |
|
| 22 |
|
| 23 |
RayCastType Transformed(typename Mat::ArgType inTransform) const |
| 24 |
{ |
| 25 |
Vec ray_origin = inTransform * mOrigin; |
| 26 |
Vec3 ray_direction(inTransform * (mOrigin + mDirection) - ray_origin); |
| 27 |
return { ray_origin, ray_direction }; |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
RayCastType Translated(typename Vec::ArgType inTranslation) const |
| 32 |
{ |
| 33 |
return { inTranslation + mOrigin, mDirection }; |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
inline Vec GetPointOnRay(float inFraction) const |
| 38 |
{ |
| 39 |
return mOrigin + inFraction * mDirection; |
| 40 |
} |
| 41 |
|
| 42 |
Vec mOrigin; |
| 43 |
Vec3 mDirection; |
| 44 |
}; |
| 45 |
|
| 46 |
struct RayCast : public RayCastT<Vec3, Mat44, RayCast> |
| 47 |
{ |
| 48 |
using RayCastT<Vec3, Mat44, RayCast>::RayCastT; |
| 49 |
}; |
| 50 |
|
| 51 |
struct RRayCast : public RayCastT<RVec3, RMat44, RRayCast> |
| 52 |
{ |
| 53 |
using RayCastT<RVec3, RMat44, RRayCast>::RayCastT; |
| 54 |
|
| 55 |
|
| 56 |
explicit RRayCast(const RayCast &inRay) : |
| 57 |
RRayCast(RVec3(inRay.mOrigin), inRay.mDirection) |
| 58 |
{ |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
explicit operator RayCast() const |
| 63 |
{ |
| 64 |
return RayCast(Vec3(mOrigin), mDirection); |
| 65 |
} |
| 66 |
}; |
| 67 |
|
| 68 |
|
| 69 |
class RayCastSettings |
| 70 |
{ |
| 71 |
public: |
| 72 |
JPH_OVERRIDE_NEW_DELETE |
| 73 |
|
| 74 |
|
| 75 |
void SetBackFaceMode(EBackFaceMode inMode) { mBackFaceModeTriangles = mBackFaceModeConvex = inMode; } |
| 76 |
|
| 77 |
|
| 78 |
EBackFaceMode mBackFaceModeTriangles = EBackFaceMode::IgnoreBackFaces; |
| 79 |
|
| 80 |
|
| 81 |
EBackFaceMode mBackFaceModeConvex = EBackFaceMode::IgnoreBackFaces; |
| 82 |
|
| 83 |
|
| 84 |
bool mTreatConvexAsSolid = true; |
| 85 |
}; |
| 86 |
|
| 87 |
JPH_NAMESPACE_END |