Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Constraints/TwoBodyConstraint.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/Constraint.h>7#include <Jolt/Physics/Body/Body.h>89JPH_NAMESPACE_BEGIN1011class TwoBodyConstraint;1213/// Base class for settings for all constraints that involve 2 bodies14class JPH_EXPORT TwoBodyConstraintSettings : public ConstraintSettings15{16JPH_DECLARE_SERIALIZABLE_ABSTRACT(JPH_EXPORT, TwoBodyConstraintSettings)1718public:19/// Create an instance of this constraint20/// You can use Body::sFixedToWorld for inBody1 if you want to attach inBody2 to the world21virtual TwoBodyConstraint * Create(Body &inBody1, Body &inBody2) const = 0;22};2324/// Base class for all constraints that involve 2 bodies. Body1 is usually considered the parent, Body2 the child.25class JPH_EXPORT TwoBodyConstraint : public Constraint26{27public:28JPH_OVERRIDE_NEW_DELETE2930/// Constructor31TwoBodyConstraint(Body &inBody1, Body &inBody2, const TwoBodyConstraintSettings &inSettings) : Constraint(inSettings), mBody1(&inBody1), mBody2(&inBody2) { }3233/// Get the type of a constraint34virtual EConstraintType GetType() const override { return EConstraintType::TwoBodyConstraint; }3536/// Solver interface37virtual bool IsActive() const override { return Constraint::IsActive() && (mBody1->IsActive() || mBody2->IsActive()) && (mBody2->IsDynamic() || mBody1->IsDynamic()); }38#ifdef JPH_DEBUG_RENDERER39virtual void DrawConstraintReferenceFrame(DebugRenderer *inRenderer) const override;40#endif // JPH_DEBUG_RENDERER4142/// Access to the connected bodies43Body * GetBody1() const { return mBody1; }44Body * GetBody2() const { return mBody2; }4546/// Calculates the transform that transforms from constraint space to body 1 space. The first column of the matrix is the primary constraint axis (e.g. the hinge axis / slider direction), second column the secondary etc.47virtual Mat44 GetConstraintToBody1Matrix() const = 0;4849/// Calculates the transform that transforms from constraint space to body 2 space. The first column of the matrix is the primary constraint axis (e.g. the hinge axis / slider direction), second column the secondary etc.50virtual Mat44 GetConstraintToBody2Matrix() const = 0;5152/// Link bodies that are connected by this constraint in the island builder53virtual void BuildIslands(uint32 inConstraintIndex, IslandBuilder &ioBuilder, BodyManager &inBodyManager) override;5455/// Link bodies that are connected by this constraint in the same split. Returns the split index.56virtual uint BuildIslandSplits(LargeIslandSplitter &ioSplitter) const override;5758protected:59/// The two bodies involved60Body * mBody1;61Body * mBody2;62};6364JPH_NAMESPACE_END656667