Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
Wheel.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#include <Jolt/Core/StreamIn.h>
11#include <Jolt/Core/StreamOut.h>
12
14
16
18class JPH_EXPORT WheelSettings : public SerializableObject, public RefTarget<WheelSettings>
19{
20public:
22
23
24 virtual void SaveBinaryState(StreamOut &inStream) const;
25
27 virtual void RestoreBinaryState(StreamIn &inStream);
28
29 Vec3 mPosition { 0, 0, 0 };
30 Vec3 mSuspensionForcePoint { 0, 0, 0 };
31 Vec3 mSuspensionDirection { 0, -1, 0 };
32 Vec3 mSteeringAxis { 0, 1, 0 };
33 Vec3 mWheelUp { 0, 1, 0 };
34 Vec3 mWheelForward { 0, 0, 1 };
35 float mSuspensionMinLength = 0.3f;
36 float mSuspensionMaxLength = 0.5f;
37 float mSuspensionPreloadLength = 0.0f;
38 SpringSettings mSuspensionSpring { ESpringMode::FrequencyAndDamping, 1.5f, 0.5f };
39 float mRadius = 0.3f;
40 float mWidth = 0.1f;
41 bool mEnableSuspensionForcePoint = false;
42};
43
46{
47public:
49
51 explicit Wheel(const WheelSettings &inSettings);
52 virtual ~Wheel() = default;
53
55 const WheelSettings * GetSettings() const { return mSettings; }
56
58 float GetAngularVelocity() const { return mAngularVelocity; }
59
61 void SetAngularVelocity(float inVel) { mAngularVelocity = inVel; }
62
64 float GetRotationAngle() const { return mAngle; }
65
67 void SetRotationAngle(float inAngle) { mAngle = inAngle; }
68
70 float GetSteerAngle() const { return mSteerAngle; }
71
73 void SetSteerAngle(float inAngle) { mSteerAngle = inAngle; }
74
76 inline bool HasContact() const { return !mContactBodyID.IsInvalid(); }
77
79 BodyID GetContactBodyID() const { return mContactBodyID; }
80
82 SubShapeID GetContactSubShapeID() const { return mContactSubShapeID; }
83
85 RVec3 GetContactPosition() const { JPH_ASSERT(HasContact()); return mContactPosition; }
86
88 Vec3 GetContactPointVelocity() const { JPH_ASSERT(HasContact()); return mContactPointVelocity; }
89
91 Vec3 GetContactNormal() const { JPH_ASSERT(HasContact()); return mContactNormal; }
92
94 Vec3 GetContactLongitudinal() const { JPH_ASSERT(HasContact()); return mContactLongitudinal; }
95
97 Vec3 GetContactLateral() const { JPH_ASSERT(HasContact()); return mContactLateral; }
98
100 float GetSuspensionLength() const { return mSuspensionLength; }
101
103 bool HasHitHardPoint() const { return mSuspensionMaxUpPart.IsActive(); }
104
106 float GetSuspensionLambda() const { return mSuspensionPart.GetTotalLambda() + mSuspensionMaxUpPart.GetTotalLambda(); }
107
109 float GetLongitudinalLambda() const { return mLongitudinalPart.GetTotalLambda(); }
110
112 float GetLateralLambda() const { return mLateralPart.GetTotalLambda(); }
113
115 bool SolveLongitudinalConstraintPart(const VehicleConstraint &inConstraint, float inMinImpulse, float inMaxImpulse);
116
118 bool SolveLateralConstraintPart(const VehicleConstraint &inConstraint, float inMinImpulse, float inMaxImpulse);
119
120protected:
121 friend class VehicleConstraint;
122
126 Body * mContactBody = nullptr;
134 float mAntiRollBarImpulse = 0.0f;
135
136 float mSteerAngle = 0.0f;
137 float mAngularVelocity = 0.0f;
138 float mAngle = 0.0f;
139
144};
145
147
#define JPH_EXPORT
Definition Core.h:236
#define JPH_NAMESPACE_END
Definition Core.h:377
#define JPH_NAMESPACE_BEGIN
Definition Core.h:371
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:31
float Real
Definition Real.h:27
#define JPH_DECLARE_SERIALIZABLE_VIRTUAL(linkage, class_name)
Definition SerializableObject.h:109
@ FrequencyAndDamping
Frequency and damping are specified.
Definition AxisConstraintPart.h:43
Definition Body.h:35
ID of a body. This is a way of reasoning about bodies in a multithreaded simulation while avoiding ra...
Definition BodyID.h:13
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition NonCopyable.h:11
Definition Reference.h:151
Definition Reference.h:35
Definition SerializableObject.h:156
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
A sub shape id contains a path to an element (usually a triangle or other primitive type) of a compou...
Definition SubShapeID.h:23
Definition Vec3.h:17
Definition VehicleConstraint.h:66
Base class for runtime data for a wheel, each VehicleController can implement a derived class of this...
Definition Wheel.h:46
RefConst< WheelSettings > mSettings
Configuration settings for this wheel.
Definition Wheel.h:123
float GetRotationAngle() const
Get the current rotation angle of the wheel in radians [0, 2 pi].
Definition Wheel.h:64
float GetSteerAngle() const
Get the current steer angle of the wheel in radians [-pi, pi], positive is to the left.
Definition Wheel.h:70
Vec3 mContactNormal
Normal of the contact point between wheel and ground.
Definition Wheel.h:130
Vec3 GetContactLateral() const
Returns lateral direction (sideways direction) in world space (note by the time you call this the veh...
Definition Wheel.h:97
void SetAngularVelocity(float inVel)
Update the angular velocity (rad/s)
Definition Wheel.h:61
float GetLateralLambda() const
Get total impulse (N s) applied along the sideways direction of the wheel.
Definition Wheel.h:112
AxisConstraintPart mLateralPart
Controls movement sideways (slip)
Definition Wheel.h:143
Vec3 mContactLongitudinal
Vector perpendicular to normal in the forward direction.
Definition Wheel.h:131
float mSuspensionLength
Current length of the suspension.
Definition Wheel.h:127
SubShapeID GetContactSubShapeID() const
Returns the sub shape ID where we're contacting the body.
Definition Wheel.h:82
Vec3 GetContactLongitudinal() const
Returns longitudinal direction (direction along the wheel relative to floor) in world space (note by ...
Definition Wheel.h:94
BodyID mContactBodyID
ID of body for ground.
Definition Wheel.h:124
AxisConstraintPart mSuspensionMaxUpPart
Adds a hard limit when reaching the minimal suspension length.
Definition Wheel.h:141
bool HasHitHardPoint() const
Check if the suspension hit its upper limit.
Definition Wheel.h:103
Vec3 mContactPointVelocity
Velocity of the contact point (m / s, not relative to the wheel but in world space)
Definition Wheel.h:129
void SetSteerAngle(float inAngle)
Set the current steer angle of the wheel in radians [-pi, pi].
Definition Wheel.h:73
Vec3 GetContactPointVelocity() const
Velocity of the contact point (m / s, not relative to the wheel but in world space)
Definition Wheel.h:88
AxisConstraintPart mSuspensionPart
Controls movement up/down along the contact normal.
Definition Wheel.h:140
virtual ~Wheel()=default
Real mAxlePlaneConstant
Constant for the contact plane of the axle, defined as ContactNormal . (WorldSpaceSuspensionPoint + S...
Definition Wheel.h:133
void SetRotationAngle(float inAngle)
Set the current rotation angle of the wheel in radians [0, 2 pi].
Definition Wheel.h:67
AxisConstraintPart mLongitudinalPart
Controls movement forward/backward.
Definition Wheel.h:142
Vec3 GetContactNormal() const
Returns the current contact normal in world space (note by the time you call this the vehicle has mov...
Definition Wheel.h:91
const WheelSettings * GetSettings() const
Get settings for the wheel.
Definition Wheel.h:55
RVec3 mContactPosition
Position of the contact point between wheel and ground.
Definition Wheel.h:128
float GetLongitudinalLambda() const
Get total impulse (N s) applied along the forward direction of the wheel.
Definition Wheel.h:109
BodyID GetContactBodyID() const
Returns the body ID of the body that this wheel is touching.
Definition Wheel.h:79
float GetSuspensionLength() const
Get the length of the suspension for a wheel (m) relative to the suspension attachment point (hard po...
Definition Wheel.h:100
float GetAngularVelocity() const
Get the angular velocity (rad/s) for this wheel, note that positive means the wheel is rotating such ...
Definition Wheel.h:58
bool HasContact() const
Returns true if the wheel is touching an object.
Definition Wheel.h:76
Vec3 mContactLateral
Vector perpendicular to normal and longitudinal direction in the right direction.
Definition Wheel.h:132
float GetSuspensionLambda() const
Get the total impulse (N s) that was applied by the suspension.
Definition Wheel.h:106
SubShapeID mContactSubShapeID
Sub shape ID for ground.
Definition Wheel.h:125
RVec3 GetContactPosition() const
Returns the current contact position in world space (note by the time you call this the vehicle has m...
Definition Wheel.h:85
Base class for wheel settings, each VehicleController can implement a derived class of this.
Definition Wheel.h:19