Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Collision/CastResult.h
9912 views
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
7
#include <Jolt/Physics/Body/BodyID.h>
8
#include <Jolt/Physics/Collision/Shape/SubShapeID.h>
9
10
JPH_NAMESPACE_BEGIN
11
12
/// Structure that holds a ray cast or other object cast hit
13
class BroadPhaseCastResult
14
{
15
public:
16
JPH_OVERRIDE_NEW_DELETE
17
18
/// Function required by the CollisionCollector. A smaller fraction is considered to be a 'better hit'. For rays/cast shapes we can just use the collision fraction.
19
inline float GetEarlyOutFraction() const { return mFraction; }
20
21
/// Reset this result so it can be reused for a new cast.
22
inline void Reset() { mBodyID = BodyID(); mFraction = 1.0f + FLT_EPSILON; }
23
24
BodyID mBodyID; ///< Body that was hit
25
float mFraction = 1.0f + FLT_EPSILON; ///< Hit fraction of the ray/object [0, 1], HitPoint = Start + mFraction * (End - Start)
26
};
27
28
/// Specialization of cast result against a shape
29
class RayCastResult : public BroadPhaseCastResult
30
{
31
public:
32
JPH_OVERRIDE_NEW_DELETE
33
34
SubShapeID mSubShapeID2; ///< Sub shape ID of shape that we collided against
35
};
36
37
JPH_NAMESPACE_END
38
39