Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
RayCapsule.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
9
11
19JPH_INLINE float RayCapsule(Vec3Arg inRayOrigin, Vec3Arg inRayDirection, float inCapsuleHalfHeight, float inCapsuleRadius)
20{
21 // Test infinite cylinder
22 float cylinder = RayCylinder(inRayOrigin, inRayDirection, inCapsuleRadius);
23 if (cylinder == FLT_MAX)
24 return FLT_MAX;
25
26 // If this hit is in the finite cylinder we have our fraction
27 if (abs(inRayOrigin.GetY() + cylinder * inRayDirection.GetY()) <= inCapsuleHalfHeight)
28 return cylinder;
29
30 // Test upper and lower sphere
31 Vec3 sphere_center(0, inCapsuleHalfHeight, 0);
32 float upper = RaySphere(inRayOrigin, inRayDirection, sphere_center, inCapsuleRadius);
33 float lower = RaySphere(inRayOrigin, inRayDirection, -sphere_center, inCapsuleRadius);
34 return min(upper, lower);
35}
36
#define JPH_NAMESPACE_END
Definition: Core.h:354
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:348
JPH_NAMESPACE_BEGIN JPH_INLINE float RayCapsule(Vec3Arg inRayOrigin, Vec3Arg inRayDirection, float inCapsuleHalfHeight, float inCapsuleRadius)
Definition: RayCapsule.h:19
JPH_NAMESPACE_BEGIN JPH_INLINE float RayCylinder(Vec3Arg inRayOrigin, Vec3Arg inRayDirection, float inCylinderRadius)
Definition: RayCylinder.h:17
JPH_NAMESPACE_BEGIN JPH_INLINE float RaySphere(Vec3Arg inRayOrigin, Vec3Arg inRayDirection, Vec3Arg inSphereCenter, float inSphereRadius)
Definition: RaySphere.h:17
Definition: Vec3.h:16
JPH_INLINE float GetY() const
Definition: Vec3.h:124