Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Constraints/PathConstraintPathHermite.h
9913 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2021 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/Physics/Constraints/PathConstraintPath.h>78JPH_NAMESPACE_BEGIN910/// A path that follows a Hermite spline11class JPH_EXPORT PathConstraintPathHermite final : public PathConstraintPath12{13JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, PathConstraintPathHermite)1415public:16// See PathConstraintPath::GetPathMaxFraction17virtual float GetPathMaxFraction() const override { return float(IsLooping()? mPoints.size() : mPoints.size() - 1); }1819// See PathConstraintPath::GetClosestPoint20virtual float GetClosestPoint(Vec3Arg inPosition, float inFractionHint) const override;2122// See PathConstraintPath::GetPointOnPath23virtual void GetPointOnPath(float inFraction, Vec3 &outPathPosition, Vec3 &outPathTangent, Vec3 &outPathNormal, Vec3 &outPathBinormal) const override;2425/// Adds a point to the path26void AddPoint(Vec3Arg inPosition, Vec3Arg inTangent, Vec3Arg inNormal) { mPoints.push_back({ inPosition, inTangent, inNormal}); }2728// See: PathConstraintPath::SaveBinaryState29virtual void SaveBinaryState(StreamOut &inStream) const override;3031struct Point32{33JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, Point)3435Vec3 mPosition; ///< Position on the path36Vec3 mTangent; ///< Tangent of the path, does not need to be normalized (in the direction of the path)37Vec3 mNormal; ///< Normal of the path (together with the tangent along the curve this forms a basis for the constraint)38};3940protected:41// See: PathConstraintPath::RestoreBinaryState42virtual void RestoreBinaryState(StreamIn &inStream) override;4344private:45/// Helper function that returns the index of the path segment and the fraction t on the path segment based on the full path fraction46inline void GetIndexAndT(float inFraction, int &outIndex, float &outT) const;4748using Points = Array<Point>;4950Points mPoints; ///< Points on the Hermite spline51};5253JPH_NAMESPACE_END545556