Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Constraints/PathConstraintPath.h
9912 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2021 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/Core/Reference.h>7#include <Jolt/Core/Result.h>8#include <Jolt/ObjectStream/SerializableObject.h>910JPH_NAMESPACE_BEGIN1112class StreamIn;13class StreamOut;14#ifdef JPH_DEBUG_RENDERER15class DebugRenderer;16#endif // JPH_DEBUG_RENDERER1718/// The path for a path constraint. It allows attaching two bodies to each other while giving the second body the freedom to move along a path relative to the first.19class JPH_EXPORT PathConstraintPath : public SerializableObject, public RefTarget<PathConstraintPath>20{21JPH_DECLARE_SERIALIZABLE_ABSTRACT(JPH_EXPORT, PathConstraintPath)2223public:24using PathResult = Result<Ref<PathConstraintPath>>;2526/// Virtual destructor to ensure that derived types get their destructors called27virtual ~PathConstraintPath() override = default;2829/// Gets the max fraction along the path. I.e. sort of the length of the path.30virtual float GetPathMaxFraction() const = 0;3132/// Get the globally closest point on the curve (Could be slow!)33/// @param inPosition Position to find closest point for34/// @param inFractionHint Last known fraction along the path (can be used to speed up the search)35/// @return Fraction of closest point along the path36virtual float GetClosestPoint(Vec3Arg inPosition, float inFractionHint) const = 0;3738/// Given the fraction along the path, get the point, tangent and normal.39/// @param inFraction Fraction along the path [0, GetPathMaxFraction()].40/// @param outPathPosition Returns the closest position to inSearchPosition on the path.41/// @param outPathTangent Returns the tangent to the path at outPathPosition (the vector that follows the direction of the path)42/// @param outPathNormal Return the normal to the path at outPathPosition (a vector that's perpendicular to outPathTangent)43/// @param outPathBinormal Returns the binormal to the path at outPathPosition (a vector so that normal cross tangent = binormal)44virtual void GetPointOnPath(float inFraction, Vec3 &outPathPosition, Vec3 &outPathTangent, Vec3 &outPathNormal, Vec3 &outPathBinormal) const = 0;4546/// If the path is looping or not. If a path is looping, the first and last point are automatically connected to each other. They should not be the same points.47void SetIsLooping(bool inIsLooping) { mIsLooping = inIsLooping; }48bool IsLooping() const { return mIsLooping; }4950#ifdef JPH_DEBUG_RENDERER51/// Draw the path relative to inBaseTransform. Used for debug purposes.52void DrawPath(DebugRenderer *inRenderer, RMat44Arg inBaseTransform) const;53#endif // JPH_DEBUG_RENDERER5455/// Saves the contents of the path in binary form to inStream.56virtual void SaveBinaryState(StreamOut &inStream) const;5758/// Creates a Shape of the correct type and restores its contents from the binary stream inStream.59static PathResult sRestoreFromBinaryState(StreamIn &inStream);6061protected:62/// This function should not be called directly, it is used by sRestoreFromBinaryState.63virtual void RestoreBinaryState(StreamIn &inStream);6465private:66/// If the path is looping or not. If a path is looping, the first and last point are automatically connected to each other. They should not be the same points.67bool mIsLooping = false;68};6970JPH_NAMESPACE_END717273