Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
MotorSettings.h
Go to the documentation of this file.
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
10
12
13class StreamIn;
14class StreamOut;
15
16enum class EMotorState
17{
18 Off,
19 Velocity,
21};
22
26{
27public:
29
30
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
38 void SetForceLimits(float inMin, float inMax) { JPH_ASSERT(inMin <= inMax); mMinForceLimit = inMin; mMaxForceLimit = inMax; }
39
41 void SetTorqueLimits(float inMin, float inMax) { JPH_ASSERT(inMin <= inMax); mMinTorqueLimit = inMin; mMaxTorqueLimit = inMax; }
42
44 void SetForceLimit(float inLimit) { mMinForceLimit = -inLimit; mMaxForceLimit = inLimit; }
45
47 void SetTorqueLimit(float inLimit) { mMinTorqueLimit = -inLimit; mMaxTorqueLimit = inLimit; }
48
50 bool IsValid() const { return mSpringSettings.mFrequency >= 0.0f && mSpringSettings.mDamping >= 0.0f && mMinForceLimit <= mMaxForceLimit && mMinTorqueLimit <= mMaxTorqueLimit; }
51
53 void SaveBinaryState(StreamOut &inStream) const;
54
56 void RestoreBinaryState(StreamIn &inStream);
57
58 // Settings
59 SpringSettings mSpringSettings { ESpringMode::FrequencyAndDamping, 2.0f, 1.0f };
60 float mMinForceLimit = -FLT_MAX;
61 float mMaxForceLimit = FLT_MAX;
62 float mMinTorqueLimit = -FLT_MAX;
63 float mMaxTorqueLimit = FLT_MAX;
64};
65
#define JPH_EXPORT
Definition: Core.h:227
#define JPH_NAMESPACE_END
Definition: Core.h:367
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:361
#define JPH_ASSERT(...)
Definition: IssueReporting.h:33
EMotorState
Definition: MotorSettings.h:17
@ Position
Motor will drive to target position.
@ Velocity
Motor will drive to target velocity.
@ Off
Motor is off.
#define JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(linkage, class_name)
Definition: SerializableObject.h:71
ESpringMode
Enum used by constraints to specify how the spring is defined.
Definition: SpringSettings.h:16
@ FrequencyAndDamping
Frequency and damping are specified.
Definition: MotorSettings.h:26
MotorSettings(float inFrequency, float inDamping, float inForceLimit, float inTorqueLimit)
Definition: MotorSettings.h:35
void SetForceLimits(float inMin, float inMax)
Set asymmetric force limits.
Definition: MotorSettings.h:38
void SetTorqueLimits(float inMin, float inMax)
Set asymmetric torque limits.
Definition: MotorSettings.h:41
void SetForceLimit(float inLimit)
Set symmetric force limits.
Definition: MotorSettings.h:44
bool IsValid() const
Check if settings are valid.
Definition: MotorSettings.h:50
void SetTorqueLimit(float inLimit)
Set symmetric torque limits.
Definition: MotorSettings.h:47
Settings for a linear or angular spring.
Definition: SpringSettings.h:23
Simple binary input stream.
Definition: StreamIn.h:13
Simple binary output stream.
Definition: StreamOut.h:13