36    template <
bool LastPo
intPartOfClosestFeature>
 
   37    bool        GetClosest(
float inPrevVLenSq, 
Vec3 &outV, 
float &outVLenSq, 
uint32 &outSet)
 const 
   40        for (
int i = 0; i < mNumPoints; ++i)
 
   41            Trace(
"y[%d] = [%s], |y[%d]| = %g", i, 
ConvertToString(mY[i]).c_str(), i, (
double)mY[i].Length());
 
   62            v = ClosestPoint::GetClosestPointOnTriangle<LastPointPartOfClosestFeature>(mY[0], mY[1], mY[2], set);
 
   67            v = ClosestPoint::GetClosestPointOnTetrahedron<LastPointPartOfClosestFeature>(mY[0], mY[1], mY[2], mY[3], set);
 
   80        if (v_len_sq < inPrevVLenSq) 
 
   91        Trace(
"New closer point is further away, failed to converge");
 
   97    float       GetMaxYLengthSq()
 const 
  100        for (
int i = 1; i < mNumPoints; ++i)
 
  101            y_len_sq = max(y_len_sq, mY[i].LengthSq());
 
  106    void        UpdatePointSetY(
uint32 inSet)
 
  109        for (
int i = 0; i < mNumPoints; ++i)
 
  110            if ((inSet & (1 << i)) != 0)
 
  112                mY[num_points] = mY[i];
 
  115        mNumPoints = num_points;
 
  119    JPH_SUPPRESS_WARNING_PUSH
 
  123    void        UpdatePointSetP(
uint32 inSet)
 
  126        for (
int i = 0; i < mNumPoints; ++i)
 
  127            if ((inSet & (1 << i)) != 0)
 
  129                mP[num_points] = mP[i];
 
  132        mNumPoints = num_points;
 
  136    void        UpdatePointSetPQ(
uint32 inSet)
 
  139        for (
int i = 0; i < mNumPoints; ++i)
 
  140            if ((inSet & (1 << i)) != 0)
 
  142                mP[num_points] = mP[i];
 
  143                mQ[num_points] = mQ[i];
 
  146        mNumPoints = num_points;
 
  150    void        UpdatePointSetYPQ(
uint32 inSet)
 
  153        for (
int i = 0; i < mNumPoints; ++i)
 
  154            if ((inSet & (1 << i)) != 0)
 
  156                mY[num_points] = mY[i];
 
  157                mP[num_points] = mP[i];
 
  158                mQ[num_points] = mQ[i];
 
  161        mNumPoints = num_points;
 
  164    JPH_SUPPRESS_WARNING_POP
 
  167    void        CalculatePointAAndB(
Vec3 &outPointA, 
Vec3 &outPointB)
 const 
  180                outPointA = u * mP[0] + v * mP[1];
 
  181                outPointB = u * mQ[0] + v * mQ[1];
 
  189                outPointA = u * mP[0] + v * mP[1] + w * mP[2];
 
  190                outPointB = u * mQ[0] + v * mQ[1] + w * mQ[2];
 
  196            memset(&outPointA, 0xcd, 
sizeof(outPointA));
 
  197            memset(&outPointB, 0xcd, 
sizeof(outPointB));
 
  213    template <
typename A, 
typename B>
 
  216        float tolerance_sq = 
Square(inTolerance);
 
  222        for (
int i = 0; i < 4; ++i)
 
  227        float prev_v_len_sq = FLT_MAX;
 
  236            Vec3 p = inA.GetSupport(ioV);
 
  237            Vec3 q = inB.GetSupport(-ioV);
 
  243            if (ioV.
Dot(w) < 0.0f)
 
  247                Trace(
"Seperating axis");
 
  263            if (!GetClosest<true>(prev_v_len_sq, ioV, v_len_sq, set))
 
  270                Trace(
"Full simplex");
 
  277            if (v_len_sq <= tolerance_sq)
 
  280                Trace(
"Distance zero");
 
  287            if (v_len_sq <= FLT_EPSILON * GetMaxYLengthSq())
 
  290                Trace(
"Machine precision reached");
 
  302            if (prev_v_len_sq - v_len_sq <= FLT_EPSILON * prev_v_len_sq)
 
  310            prev_v_len_sq = v_len_sq;
 
  313            UpdatePointSetY(set);
 
  333    template <
typename A, 
typename B>
 
  336        float tolerance_sq = 
Square(inTolerance);
 
  346        for (
int i = 0; i < 4; ++i)
 
  358        float prev_v_len_sq = FLT_MAX;
 
  367            Vec3 p = inA.GetSupport(ioV);
 
  368            Vec3 q = inB.GetSupport(-ioV);
 
  373            float dot = ioV.
Dot(w);
 
  391            if (dot < 0.0f && dot * dot > v_len_sq * inMaxDistSq)
 
  394                Trace(
"Distance bigger than max");
 
  397                memset(&outPointA, 0xcd, 
sizeof(outPointA));
 
  398                memset(&outPointB, 0xcd, 
sizeof(outPointB));
 
  414            if (!GetClosest<true>(prev_v_len_sq, ioV, v_len_sq, set))
 
  424                Trace(
"Full simplex");
 
  432            UpdatePointSetYPQ(set);
 
  435            if (v_len_sq <= tolerance_sq)
 
  438                Trace(
"Distance zero");
 
  447            Trace(
"Check v small compared to y: %g <= %g", (
double)v_len_sq, (
double)(FLT_EPSILON * GetMaxYLengthSq()));
 
  449            if (v_len_sq <= FLT_EPSILON * GetMaxYLengthSq())
 
  452                Trace(
"Machine precision reached");
 
  465            Trace(
"Check v not changing enough: %g <= %g", (
double)(prev_v_len_sq - v_len_sq), (
double)(FLT_EPSILON * prev_v_len_sq));
 
  468            if (prev_v_len_sq - v_len_sq <= FLT_EPSILON * prev_v_len_sq)
 
  476            prev_v_len_sq = v_len_sq;
 
  480        CalculatePointAAndB(outPointA, outPointB);
 
  504        uint size = 
sizeof(
Vec3) * mNumPoints;
 
  505        memcpy(outY, mY, size);
 
  506        memcpy(outP, mP, size);
 
  507        memcpy(outQ, mQ, size);
 
  508        outNumPoints = mNumPoints;
 
  522    template <
typename A>
 
  525        float tolerance_sq = 
Square(inTolerance);
 
  531        Vec3 x = inRayOrigin;
 
  533        float v_len_sq = FLT_MAX;
 
  534        bool allow_restart = 
false;
 
  543            Vec3 p = inA.GetSupport(v);
 
  550            float v_dot_w = v.
Dot(w);
 
  552            Trace(
"v . w = %g", (
double)v_dot_w);
 
  557                float v_dot_r = v.
Dot(inRayDirection);
 
  559                Trace(
"v . r = %g", (
double)v_dot_r);
 
  565                float delta = v_dot_w / v_dot_r;
 
  566                float old_lambda = lambda;
 
  569                Trace(
"lambda = %g, delta = %g", (
double)lambda, (
double)delta);
 
  573                if (old_lambda == lambda)
 
  577                if (lambda >= ioLambda)
 
  581                x = inRayOrigin + lambda * inRayDirection;
 
  589                allow_restart = 
true;
 
  597            for (
int i = 0; i < mNumPoints; ++i)
 
  601            bool needs_restart = 
false;
 
  603            if (!GetClosest<false>(v_len_sq, v, v_len_sq, set))
 
  606                Trace(
"Failed to converge");
 
  610                needs_restart = 
true;
 
  615                Trace(
"Full simplex");
 
  620                if (v_len_sq <= tolerance_sq)
 
  624                needs_restart = 
true;
 
  638                allow_restart = 
false;
 
  648            UpdatePointSetP(set);
 
  651            if (v_len_sq <= tolerance_sq)
 
  675    template <
typename A, 
typename B>
 
  706    template <
typename A, 
typename B>
 
  707    bool        CastShape(
Mat44Arg inStart, 
Vec3Arg inDirection, 
float inTolerance, 
const A &inA, 
const B &inB, 
float inConvexRadiusA, 
float inConvexRadiusB, 
float &ioLambda, 
Vec3 &outPointA, 
Vec3 &outPointB, 
Vec3 &outSeparatingAxis)
 
  709        float tolerance_sq = 
Square(inTolerance);
 
  712        float sum_convex_radius = inConvexRadiusA + inConvexRadiusB;
 
  723        float v_len_sq = FLT_MAX;
 
  724        bool allow_restart = 
false;
 
  740            Vec3 q = inB.GetSupport(v);
 
  741            Vec3 w = x - (q - p);
 
  754            float v_dot_w = v.
Dot(w) - sum_convex_radius * v.
Length();
 
  756            Trace(
"v . w = %g", (
double)v_dot_w);
 
  761                float v_dot_r = v.
Dot(inDirection);
 
  763                Trace(
"v . r = %g", (
double)v_dot_r);
 
  769                float delta = v_dot_w / v_dot_r;
 
  770                float old_lambda = lambda;
 
  773                Trace(
"lambda = %g, delta = %g", (
double)lambda, (
double)delta);
 
  777                if (old_lambda == lambda)
 
  781                if (lambda >= ioLambda)
 
  785                x = lambda * inDirection;
 
  792                tolerance_sq = 
Square(inTolerance + sum_convex_radius);
 
  797                allow_restart = 
true;
 
  806            for (
int i = 0; i < mNumPoints; ++i)
 
  807                mY[i] = x - (mQ[i] - mP[i]);
 
  810            bool needs_restart = 
false;
 
  812            if (!GetClosest<false>(v_len_sq, v, v_len_sq, set))
 
  815                Trace(
"Failed to converge");
 
  819                needs_restart = 
true;
 
  824                Trace(
"Full simplex");
 
  829                if (v_len_sq <= tolerance_sq)
 
  833                needs_restart = 
true;
 
  847                allow_restart = 
false;
 
  858            UpdatePointSetPQ(set);
 
  861            if (v_len_sq <= tolerance_sq)
 
  874        for (
int i = 0; i < mNumPoints; ++i)
 
  875            mY[i] = x - (mQ[i] - mP[i]);
 
  879        Vec3 convex_radius_a = inConvexRadiusA * normalized_v;
 
  880        Vec3 convex_radius_b = inConvexRadiusB * normalized_v;
 
  887            outPointB = mQ[0] + convex_radius_b; 
 
  888            outPointA = lambda > 0.0f? outPointB : mP[0] - convex_radius_a;
 
  895                outPointB = bu * mQ[0] + bv * mQ[1] + convex_radius_b;
 
  896                outPointA = lambda > 0.0f? outPointB : bu * mP[0] + bv * mP[1] - convex_radius_a;
 
  905                outPointB = bu * mQ[0] + bv * mQ[1] + bw * mQ[2] + convex_radius_b;
 
  906                outPointA = lambda > 0.0f? outPointB : bu * mP[0] + bv * mP[1] + bw * mP[2] - convex_radius_a;
 
  913        outSeparatingAxis = sum_convex_radius > 0.0f? -v : -prev_v;
 
  934        for (
int i = 0; i < mNumPoints; ++i)
 
  937            RVec3 y_i = origin * mY[i];
 
  939            for (
int j = i + 1; j < mNumPoints; ++j)
 
  942                RVec3 y_j = origin * mY[j];
 
  944                for (
int k = j + 1; k < mNumPoints; ++k)
 
  947                    RVec3 y_k = origin * mY[k];
 
  948                    RVec3 center = (y_i + y_j + y_k) / 
Real(3);
 
  949                    RVec3 normal = (y_j - y_i).Cross(y_k - y_i);
 
  950                    if (normal.
Dot(center) < 
Real(0))
 
  959        mOffset += 
Vec3(mGeometry->mBounds.GetSize().GetX() + 2.0f, 0, 0);
 
#define JPH_GCC_SUPPRESS_WARNING(w)
Definition: Core.h:141
 
uint32_t uint32
Definition: Core.h:312
 
unsigned int uint
Definition: Core.h:309
 
#define JPH_NAMESPACE_END
Definition: Core.h:240
 
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:234
 
TraceFunction Trace
Definition: IssueReporting.cpp:18
 
#define JPH_ASSERT(...)
Definition: IssueReporting.h:33
 
constexpr T Square(T inV)
Square a value.
Definition: Math.h:52
 
float Real
Definition: Real.h:27
 
static const Color sPurple
Definition: Color.h:54
 
static const Color sGreen
Definition: Color.h:50
 
static const Color sLightGrey
Definition: Color.h:59
 
static const Color sOrange
Definition: Color.h:56
 
static const Color sCyan
Definition: Color.h:55
 
static const Color sRed
Definition: Color.h:48
 
static const Color sYellow
Definition: Color.h:53
 
GeometryRef CreateTriangleGeometryForConvex(SupportFunction inGetSupport)
Definition: DebugRenderer.cpp:688
 
void DrawMarker(RVec3Arg inPosition, ColorArg inColor, float inSize)
Draw a marker on a position.
Definition: DebugRenderer.cpp:172
 
void DrawCoordinateSystem(RMat44Arg inTransform, float inSize=1.0f)
Draw coordinate system (3 arrows, x = red, y = green, z = blue)
Definition: DebugRenderer.cpp:206
 
virtual void DrawGeometry(RMat44Arg inModelMatrix, const AABox &inWorldSpaceBounds, float inLODScaleSq, ColorArg inModelColor, const GeometryRef &inGeometry, ECullMode inCullMode=ECullMode::CullBackFace, ECastShadow inCastShadow=ECastShadow::On, EDrawMode inDrawMode=EDrawMode::Solid)=0
 
static DebugRenderer * sInstance
Singleton instance.
Definition: DebugRenderer.h:131
 
virtual void DrawTriangle(RVec3Arg inV1, RVec3Arg inV2, RVec3Arg inV3, ColorArg inColor)=0
Draw a single back face culled triangle without any shadows.
 
virtual void DrawLine(RVec3Arg inFrom, RVec3Arg inTo, ColorArg inColor)=0
Draw line.
 
void DrawArrow(RVec3Arg inFrom, RVec3Arg inTo, ColorArg inColor, float inSize)
Draw an arrow.
Definition: DebugRenderer.cpp:184
 
Definition: GJKClosestPoint.h:23
 
bool Intersects(const A &inA, const B &inB, float inTolerance, Vec3 &ioV)
Definition: GJKClosestPoint.h:214
 
bool CastShape(Mat44Arg inStart, Vec3Arg inDirection, float inTolerance, const A &inA, const B &inB, float &ioLambda)
Definition: GJKClosestPoint.h:676
 
void GetClosestPointsSimplex(Vec3 *outY, Vec3 *outP, Vec3 *outQ, uint &outNumPoints) const
Definition: GJKClosestPoint.h:502
 
bool CastShape(Mat44Arg inStart, Vec3Arg inDirection, float inTolerance, const A &inA, const B &inB, float inConvexRadiusA, float inConvexRadiusB, float &ioLambda, Vec3 &outPointA, Vec3 &outPointB, Vec3 &outSeparatingAxis)
Definition: GJKClosestPoint.h:707
 
float GetClosestPoints(const A &inA, const B &inB, float inTolerance, float inMaxDistSq, Vec3 &ioV, Vec3 &outPointA, Vec3 &outPointB)
Definition: GJKClosestPoint.h:334
 
bool CastRay(Vec3Arg inRayOrigin, Vec3Arg inRayDirection, float inTolerance, const A &inA, float &ioLambda)
Definition: GJKClosestPoint.h:523
 
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition: Mat44.h:13
 
static JPH_INLINE Mat44 sTranslation(Vec3Arg inV)
Get matrix that translates.
Definition: Mat44.inl:144
 
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition: NonCopyable.h:11
 
JPH_INLINE float Dot(Vec3Arg inV2) const
Dot product.
Definition: Vec3.inl:637
 
JPH_INLINE float Length() const
Length of vector.
Definition: Vec3.inl:669
 
JPH_INLINE Vec3 NormalizedOr(Vec3Arg inZeroValue) const
Normalize vector or return inZeroValue if the length of the vector is zero.
Definition: Vec3.inl:708
 
JPH_INLINE float LengthSq() const
Squared length of vector.
Definition: Vec3.inl:653
 
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition: Vec3.inl:107
 
void GetBaryCentricCoordinates(Vec3Arg inA, Vec3Arg inB, float &outU, float &outV)
Definition: ClosestPoint.h:17
 
Vec3 GetClosestPointOnLine(Vec3Arg inA, Vec3Arg inB, uint32 &outSet)
Definition: ClosestPoint.h:123
 
Structure that performs a Minkowski difference A - B.
Definition: ConvexSupport.h:67
 
Vec3 GetSupport(Vec3Arg inDirection) const
Calculate the support vector for this convex shape.
Definition: ConvexSupport.h:75