Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Constraints/MotorSettings.h
9912 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/Core/Reference.h>
8
#include <Jolt/ObjectStream/SerializableObject.h>
9
#include <Jolt/Physics/Constraints/SpringSettings.h>
10
11
JPH_NAMESPACE_BEGIN
12
13
class StreamIn;
14
class StreamOut;
15
16
enum class EMotorState
17
{
18
Off, ///< Motor is off
19
Velocity, ///< Motor will drive to target velocity
20
Position ///< Motor will drive to target position
21
};
22
23
/// Class that contains the settings for a constraint motor.
24
/// See the main page of the API documentation for more information on how to configure a motor.
25
class JPH_EXPORT MotorSettings
26
{
27
JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, MotorSettings)
28
29
public:
30
/// Constructor
31
MotorSettings() = default;
32
MotorSettings(const MotorSettings &) = default;
33
MotorSettings & operator = (const MotorSettings &) = default;
34
MotorSettings(float inFrequency, float inDamping) : mSpringSettings(ESpringMode::FrequencyAndDamping, inFrequency, inDamping) { JPH_ASSERT(IsValid()); }
35
MotorSettings(float inFrequency, float inDamping, float inForceLimit, float inTorqueLimit) : mSpringSettings(ESpringMode::FrequencyAndDamping, inFrequency, inDamping), mMinForceLimit(-inForceLimit), mMaxForceLimit(inForceLimit), mMinTorqueLimit(-inTorqueLimit), mMaxTorqueLimit(inTorqueLimit) { JPH_ASSERT(IsValid()); }
36
37
/// Set asymmetric force limits
38
void SetForceLimits(float inMin, float inMax) { JPH_ASSERT(inMin <= inMax); mMinForceLimit = inMin; mMaxForceLimit = inMax; }
39
40
/// Set asymmetric torque limits
41
void SetTorqueLimits(float inMin, float inMax) { JPH_ASSERT(inMin <= inMax); mMinTorqueLimit = inMin; mMaxTorqueLimit = inMax; }
42
43
/// Set symmetric force limits
44
void SetForceLimit(float inLimit) { mMinForceLimit = -inLimit; mMaxForceLimit = inLimit; }
45
46
/// Set symmetric torque limits
47
void SetTorqueLimit(float inLimit) { mMinTorqueLimit = -inLimit; mMaxTorqueLimit = inLimit; }
48
49
/// Check if settings are valid
50
bool IsValid() const { return mSpringSettings.mFrequency >= 0.0f && mSpringSettings.mDamping >= 0.0f && mMinForceLimit <= mMaxForceLimit && mMinTorqueLimit <= mMaxTorqueLimit; }
51
52
/// Saves the contents of the motor settings in binary form to inStream.
53
void SaveBinaryState(StreamOut &inStream) const;
54
55
/// Restores contents from the binary stream inStream.
56
void RestoreBinaryState(StreamIn &inStream);
57
58
// Settings
59
SpringSettings mSpringSettings { ESpringMode::FrequencyAndDamping, 2.0f, 1.0f }; ///< Settings for the spring that is used to drive to the position target (not used when motor is a velocity motor).
60
float mMinForceLimit = -FLT_MAX; ///< Minimum force to apply in case of a linear constraint (N). Usually this is -mMaxForceLimit unless you want a motor that can e.g. push but not pull. Not used when motor is an angular motor.
61
float mMaxForceLimit = FLT_MAX; ///< Maximum force to apply in case of a linear constraint (N). Not used when motor is an angular motor.
62
float mMinTorqueLimit = -FLT_MAX; ///< Minimum torque to apply in case of a angular constraint (N m). Usually this is -mMaxTorqueLimit unless you want a motor that can e.g. push but not pull. Not used when motor is a position motor.
63
float mMaxTorqueLimit = FLT_MAX; ///< Maximum torque to apply in case of a angular constraint (N m). Not used when motor is a position motor.
64
};
65
66
JPH_NAMESPACE_END
67
68