20 Vec3 center_origin = inRayOrigin - inSphereCenter;
22 float b = 2.0f * inRayDirection.
Dot(center_origin);
23 float c = center_origin.
LengthSq() - inSphereRadius * inSphereRadius;
24 float fraction1, fraction2;
25 if (
FindRoot(a, b, c, fraction1, fraction2) == 0)
26 return c <= 0.0f? 0.0f : FLT_MAX;
29 if (fraction1 > fraction2)
30 swap(fraction1, fraction2);
33 if (fraction1 >= 0.0f)
37 if (fraction2 >= 0.0f)
54JPH_INLINE
int RaySphere(
Vec3Arg inRayOrigin,
Vec3Arg inRayDirection,
Vec3Arg inSphereCenter,
float inSphereRadius,
float &outMinFraction,
float &outMaxFraction)
57 Vec3 center_origin = inRayOrigin - inSphereCenter;
59 float b = 2.0f * inRayDirection.
Dot(center_origin);
60 float c = center_origin.
LengthSq() - inSphereRadius * inSphereRadius;
61 float fraction1, fraction2;
62 switch (
FindRoot(a, b, c, fraction1, fraction2))
68 outMinFraction = outMaxFraction = 0.0f;
80 outMinFraction = outMaxFraction = fraction1;
87 if (fraction1 > fraction2)
88 swap(fraction1, fraction2);
90 outMinFraction = fraction1;
91 outMaxFraction = fraction2;
JPH_NAMESPACE_BEGIN int FindRoot(const T inA, const T inB, const T inC, T &outX1, T &outX2)
Definition FindRoot.h:13
JPH_NAMESPACE_BEGIN JPH_INLINE float RaySphere(Vec3Arg inRayOrigin, Vec3Arg inRayDirection, Vec3Arg inSphereCenter, float inSphereRadius)
Definition RaySphere.h:17