22 float origin_xz_len_sq = origin_xz.
LengthSq();
23 float r_sq =
Square(inCylinderRadius);
24 if (origin_xz_len_sq > r_sq)
30 float b = 2.0f * origin_xz.
Dot(direction_xz);
31 float c = origin_xz_len_sq - r_sq;
32 float fraction1, fraction2;
33 if (
FindRoot(a, b, c, fraction1, fraction2) == 0)
37 float fraction = min(fraction1, fraction2);
60 float fraction =
RayCylinder(inRayOrigin, inRayDirection, inCylinderRadius);
61 if (fraction == FLT_MAX)
65 if (abs(inRayOrigin.
GetY() + fraction * inRayDirection.
GetY()) <= inCylinderHalfHeight)
69 float direction_y = inRayDirection.
GetY();
70 if (direction_y != 0.0f)
79 float origin_y = inRayOrigin.
GetY();
81 if (direction_y < 0.0f)
82 plane_fraction = (inCylinderHalfHeight - origin_y) / direction_y;
84 plane_fraction = -(inCylinderHalfHeight + origin_y) / direction_y;
87 if (plane_fraction >= 0.0f)
90 Vec3 point = inRayOrigin + plane_fraction * inRayDirection;
92 if (dist_sq <=
Square(inCylinderRadius))
93 return plane_fraction;
#define JPH_NAMESPACE_END
Definition Core.h:379
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
JPH_NAMESPACE_BEGIN int FindRoot(const T inA, const T inB, const T inC, T &outX1, T &outX2)
Definition FindRoot.h:13
JPH_INLINE constexpr T Square(T inV)
Square a value.
Definition Math.h:52
JPH_NAMESPACE_BEGIN JPH_INLINE float RayCylinder(Vec3Arg inRayOrigin, Vec3Arg inRayDirection, float inCylinderRadius)
Definition RayCylinder.h:17
JPH_INLINE float Dot(Vec3Arg inV2) const
Dot product.
Definition Vec3.inl:649
JPH_INLINE float GetX() const
Get individual components.
Definition Vec3.h:124
JPH_INLINE float GetY() const
Definition Vec3.h:125
JPH_INLINE float LengthSq() const
Squared length of vector.
Definition Vec3.inl:665
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:107
static JPH_INLINE Vec3 sSelect(Vec3Arg inNotSet, Vec3Arg inSet, UVec4Arg inControl)
Component wise select, returns inNotSet when highest bit of inControl = 0 and inSet when highest bit ...
Definition Vec3.inl:269
JPH_INLINE float GetZ() const
Definition Vec3.h:126