Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Constraints/PathConstraintPathHermite.h
9913 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/Constraints/PathConstraintPath.h>
8
9
JPH_NAMESPACE_BEGIN
10
11
/// A path that follows a Hermite spline
12
class JPH_EXPORT PathConstraintPathHermite final : public PathConstraintPath
13
{
14
JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, PathConstraintPathHermite)
15
16
public:
17
// See PathConstraintPath::GetPathMaxFraction
18
virtual float GetPathMaxFraction() const override { return float(IsLooping()? mPoints.size() : mPoints.size() - 1); }
19
20
// See PathConstraintPath::GetClosestPoint
21
virtual float GetClosestPoint(Vec3Arg inPosition, float inFractionHint) const override;
22
23
// See PathConstraintPath::GetPointOnPath
24
virtual void GetPointOnPath(float inFraction, Vec3 &outPathPosition, Vec3 &outPathTangent, Vec3 &outPathNormal, Vec3 &outPathBinormal) const override;
25
26
/// Adds a point to the path
27
void AddPoint(Vec3Arg inPosition, Vec3Arg inTangent, Vec3Arg inNormal) { mPoints.push_back({ inPosition, inTangent, inNormal}); }
28
29
// See: PathConstraintPath::SaveBinaryState
30
virtual void SaveBinaryState(StreamOut &inStream) const override;
31
32
struct Point
33
{
34
JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, Point)
35
36
Vec3 mPosition; ///< Position on the path
37
Vec3 mTangent; ///< Tangent of the path, does not need to be normalized (in the direction of the path)
38
Vec3 mNormal; ///< Normal of the path (together with the tangent along the curve this forms a basis for the constraint)
39
};
40
41
protected:
42
// See: PathConstraintPath::RestoreBinaryState
43
virtual void RestoreBinaryState(StreamIn &inStream) override;
44
45
private:
46
/// Helper function that returns the index of the path segment and the fraction t on the path segment based on the full path fraction
47
inline void GetIndexAndT(float inFraction, int &outIndex, float &outT) const;
48
49
using Points = Array<Point>;
50
51
Points mPoints; ///< Points on the Hermite spline
52
};
53
54
JPH_NAMESPACE_END
55
56