Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Constraints/FixedConstraint.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/Physics/Constraints/TwoBodyConstraint.h>7#include <Jolt/Physics/Constraints/ConstraintPart/RotationEulerConstraintPart.h>8#include <Jolt/Physics/Constraints/ConstraintPart/PointConstraintPart.h>910JPH_NAMESPACE_BEGIN1112/// Fixed constraint settings, used to create a fixed constraint13class JPH_EXPORT FixedConstraintSettings final : public TwoBodyConstraintSettings14{15JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, FixedConstraintSettings)1617public:18// See: ConstraintSettings::SaveBinaryState19virtual void SaveBinaryState(StreamOut &inStream) const override;2021/// Create an instance of this constraint22virtual TwoBodyConstraint * Create(Body &inBody1, Body &inBody2) const override;2324/// This determines in which space the constraint is setup, all properties below should be in the specified space25EConstraintSpace mSpace = EConstraintSpace::WorldSpace;2627/// When mSpace is WorldSpace mPoint1 and mPoint2 can be automatically calculated based on the positions of the bodies when the constraint is created (they will be fixated in their current relative position/orientation). Set this to false if you want to supply the attachment points yourself.28bool mAutoDetectPoint = false;2930/// Body 1 constraint reference frame (space determined by mSpace)31RVec3 mPoint1 = RVec3::sZero();32Vec3 mAxisX1 = Vec3::sAxisX();33Vec3 mAxisY1 = Vec3::sAxisY();3435/// Body 2 constraint reference frame (space determined by mSpace)36RVec3 mPoint2 = RVec3::sZero();37Vec3 mAxisX2 = Vec3::sAxisX();38Vec3 mAxisY2 = Vec3::sAxisY();3940protected:41// See: ConstraintSettings::RestoreBinaryState42virtual void RestoreBinaryState(StreamIn &inStream) override;43};4445/// A fixed constraint welds two bodies together removing all degrees of freedom between them.46/// This variant uses Euler angles for the rotation constraint.47class JPH_EXPORT FixedConstraint final : public TwoBodyConstraint48{49public:50JPH_OVERRIDE_NEW_DELETE5152/// Constructor53FixedConstraint(Body &inBody1, Body &inBody2, const FixedConstraintSettings &inSettings);5455// Generic interface of a constraint56virtual EConstraintSubType GetSubType() const override { return EConstraintSubType::Fixed; }57virtual void NotifyShapeChanged(const BodyID &inBodyID, Vec3Arg inDeltaCOM) override;58virtual void SetupVelocityConstraint(float inDeltaTime) override;59virtual void ResetWarmStart() override;60virtual void WarmStartVelocityConstraint(float inWarmStartImpulseRatio) override;61virtual bool SolveVelocityConstraint(float inDeltaTime) override;62virtual bool SolvePositionConstraint(float inDeltaTime, float inBaumgarte) override;63#ifdef JPH_DEBUG_RENDERER64virtual void DrawConstraint(DebugRenderer *inRenderer) const override;65#endif // JPH_DEBUG_RENDERER66virtual void SaveState(StateRecorder &inStream) const override;67virtual void RestoreState(StateRecorder &inStream) override;68virtual Ref<ConstraintSettings> GetConstraintSettings() const override;6970// See: TwoBodyConstraint71virtual Mat44 GetConstraintToBody1Matrix() const override { return Mat44::sTranslation(mLocalSpacePosition1); }72virtual Mat44 GetConstraintToBody2Matrix() const override { return Mat44::sRotationTranslation(mInvInitialOrientation, mLocalSpacePosition2); }7374///@name Get Lagrange multiplier from last physics update (the linear/angular impulse applied to satisfy the constraint)75inline Vec3 GetTotalLambdaPosition() const { return mPointConstraintPart.GetTotalLambda(); }76inline Vec3 GetTotalLambdaRotation() const { return mRotationConstraintPart.GetTotalLambda(); }7778private:79// CONFIGURATION PROPERTIES FOLLOW8081// Local space constraint positions82Vec3 mLocalSpacePosition1;83Vec3 mLocalSpacePosition2;8485// Inverse of initial rotation from body 1 to body 2 in body 1 space86Quat mInvInitialOrientation;8788// RUN TIME PROPERTIES FOLLOW8990// The constraint parts91RotationEulerConstraintPart mRotationConstraintPart;92PointConstraintPart mPointConstraintPart;93};9495JPH_NAMESPACE_END969798