Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
MotorcycleController Class Reference

Runtime controller class. More...

#include <MotorcycleController.h>

Inheritance diagram for MotorcycleController:
WheeledVehicleController VehicleController RefTarget< VehicleController > NonCopyable

Public Member Functions

JPH_OVERRIDE_NEW_DELETE MotorcycleController (const MotorcycleControllerSettings &inSettings, VehicleConstraint &inConstraint)
 Constructor. More...
 
float GetWheelBase () const
 Get the distance between the front and back wheels. More...
 
void EnableLeanController (bool inEnable)
 Enable or disable the lean spring. This allows you to temporarily disable the lean spring to allow the motorcycle to fall over. More...
 
bool IsLeanControllerEnabled () const
 Check if the lean spring is enabled. More...
 
void EnableLeanSteeringLimit (bool inEnable)
 Enable or disable the lean steering limit. When enabled (default) the steering angle is limited based on the vehicle speed to prevent steering that would cause an inertial force that causes the motorcycle to topple over. More...
 
bool IsLeanSteeringLimitEnabled () const
 
void SetLeanSpringConstant (float inConstant)
 Spring constant for the lean spring. More...
 
float GetLeanSpringConstant () const
 
void SetLeanSpringDamping (float inDamping)
 Spring damping constant for the lean spring. More...
 
float GetLeanSpringDamping () const
 
void SetLeanSpringIntegrationCoefficient (float inCoefficient)
 The lean spring applies an additional force equal to this coefficient * Integral(delta angle, 0, t), this effectively makes the lean spring a PID controller. More...
 
float GetLeanSpringIntegrationCoefficient () const
 
void SetLeanSpringIntegrationCoefficientDecay (float inDecay)
 How much to decay the angle integral when the wheels are not touching the floor: new_value = e^(-decay * t) * initial_value. More...
 
float GetLeanSpringIntegrationCoefficientDecay () const
 
void SetLeanSmoothingFactor (float inFactor)
 
float GetLeanSmoothingFactor () const
 
- Public Member Functions inherited from WheeledVehicleController
JPH_OVERRIDE_NEW_DELETE WheeledVehicleController (const WheeledVehicleControllerSettings &inSettings, VehicleConstraint &inConstraint)
 Constructor. More...
 
void SetDriverInput (float inForward, float inRight, float inBrake, float inHandBrake)
 
void SetForwardInput (float inForward)
 Value between -1 and 1 for auto transmission and value between 0 and 1 indicating desired driving direction and amount the gas pedal is pressed. More...
 
float GetForwardInput () const
 
void SetRightInput (float inRight)
 Value between -1 and 1 indicating desired steering angle (1 = right) More...
 
float GetRightInput () const
 
void SetBrakeInput (float inBrake)
 Value between 0 and 1 indicating how strong the brake pedal is pressed. More...
 
float GetBrakeInput () const
 
void SetHandBrakeInput (float inHandBrake)
 Value between 0 and 1 indicating how strong the hand brake is pulled. More...
 
float GetHandBrakeInput () const
 
const VehicleEngineGetEngine () const
 Get current engine state. More...
 
VehicleEngineGetEngine ()
 Get current engine state (writable interface, allows you to make changes to the configuration which will take effect the next time step) More...
 
const VehicleTransmissionGetTransmission () const
 Get current transmission state. More...
 
VehicleTransmissionGetTransmission ()
 Get current transmission state (writable interface, allows you to make changes to the configuration which will take effect the next time step) More...
 
const DifferentialsGetDifferentials () const
 Get the differentials this vehicle has. More...
 
DifferentialsGetDifferentials ()
 Get the differentials this vehicle has (writable interface, allows you to make changes to the configuration which will take effect the next time step) More...
 
float GetDifferentialLimitedSlipRatio () const
 Ratio max / min average wheel speed of each differential (measured at the clutch). More...
 
void SetDifferentialLimitedSlipRatio (float inV)
 
float GetWheelSpeedAtClutch () const
 Get the average wheel speed of all driven wheels (measured at the clutch) More...
 
const TireMaxImpulseCallbackGetTireMaxImpulseCallback () const
 
void SetTireMaxImpulseCallback (const TireMaxImpulseCallback &inTireMaxImpulseCallback)
 
void SetRPMMeter (Vec3Arg inPosition, float inSize)
 Debug drawing of RPM meter. More...
 
- Public Member Functions inherited from VehicleController
JPH_OVERRIDE_NEW_DELETE VehicleController (VehicleConstraint &inConstraint)
 Constructor / destructor. More...
 
virtual ~VehicleController ()=default
 
- Public Member Functions inherited from RefTarget< VehicleController >
 RefTarget ()=default
 Constructor. More...
 
 RefTarget (const RefTarget &)
 
 ~RefTarget ()
 assert no one is referencing us More...
 
void SetEmbedded () const
 
RefTargetoperator= (const RefTarget &)
 Assignment operator. More...
 
uint32 GetRefCount () const
 Get current refcount of this object. More...
 
void AddRef () const
 Add or release a reference to this object. More...
 
void Release () const
 
- Public Member Functions inherited from NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
void operator= (const NonCopyable &)=delete
 

Protected Member Functions

virtual void PreCollide (float inDeltaTime, PhysicsSystem &inPhysicsSystem) override
 
virtual bool SolveLongitudinalAndLateralConstraints (float inDeltaTime) override
 
virtual void SaveState (StateRecorder &inStream) const override
 
virtual void RestoreState (StateRecorder &inStream) override
 
virtual void Draw (DebugRenderer *inRenderer) const override
 
- Protected Member Functions inherited from WheeledVehicleController
virtual WheelConstructWheel (const WheelSettings &inWheel) const override
 
virtual bool AllowSleep () const override
 
virtual void PreCollide (float inDeltaTime, PhysicsSystem &inPhysicsSystem) override
 
virtual void PostCollide (float inDeltaTime, PhysicsSystem &inPhysicsSystem) override
 
virtual bool SolveLongitudinalAndLateralConstraints (float inDeltaTime) override
 
virtual void SaveState (StateRecorder &inStream) const override
 
virtual void RestoreState (StateRecorder &inStream) override
 
virtual void Draw (DebugRenderer *inRenderer) const override
 
virtual WheelConstructWheel (const WheelSettings &inWheel) const =0
 
virtual bool AllowSleep () const =0
 
virtual void PreCollide (float inDeltaTime, PhysicsSystem &inPhysicsSystem)=0
 
virtual void PostCollide (float inDeltaTime, PhysicsSystem &inPhysicsSystem)=0
 
virtual bool SolveLongitudinalAndLateralConstraints (float inDeltaTime)=0
 
virtual void SaveState (StateRecorder &inStream) const =0
 
virtual void RestoreState (StateRecorder &inStream)=0
 
virtual void Draw (DebugRenderer *inRenderer) const =0
 

Protected Attributes

bool mEnableLeanController = true
 
bool mEnableLeanSteeringLimit = true
 
float mMaxLeanAngle
 
float mLeanSpringConstant
 
float mLeanSpringDamping
 
float mLeanSpringIntegrationCoefficient
 
float mLeanSpringIntegrationCoefficientDecay
 
float mLeanSmoothingFactor
 
Vec3 mTargetLean = Vec3::sZero()
 
float mLeanSpringIntegratedDeltaAngle = 0.0f
 
float mAppliedImpulse = 0.0f
 
- Protected Attributes inherited from WheeledVehicleController
float mForwardInput = 0.0f
 Value between -1 and 1 for auto transmission and value between 0 and 1 indicating desired driving direction and amount the gas pedal is pressed. More...
 
float mRightInput = 0.0f
 Value between -1 and 1 indicating desired steering angle. More...
 
float mBrakeInput = 0.0f
 Value between 0 and 1 indicating how strong the brake pedal is pressed. More...
 
float mHandBrakeInput = 0.0f
 Value between 0 and 1 indicating how strong the hand brake is pulled. More...
 
VehicleEngine mEngine
 Engine state of the vehicle. More...
 
VehicleTransmission mTransmission
 Transmission state of the vehicle. More...
 
Differentials mDifferentials
 Differential states of the vehicle. More...
 
float mDifferentialLimitedSlipRatio
 Ratio max / min average wheel speed of each differential (measured at the clutch). More...
 
float mPreviousDeltaTime = 0.0f
 Delta time of the last step. More...
 
TireMaxImpulseCallback mTireMaxImpulseCallback
 
Vec3 mRPMMeterPosition { 0, 1, 0 }
 Position (in local space of the body) of the RPM meter when drawing the constraint. More...
 
float mRPMMeterSize = 0.5f
 Size of the RPM meter when drawing the constraint. More...
 
- Protected Attributes inherited from VehicleController
VehicleConstraintmConstraint
 The vehicle constraint we belong to. More...
 
- Protected Attributes inherited from RefTarget< VehicleController >
atomic< uint32mRefCount
 Current reference count. More...
 

Additional Inherited Members

- Public Types inherited from WheeledVehicleController
using Differentials = Array< VehicleDifferentialSettings >
 Typedefs. More...
 
using TireMaxImpulseCallback = function< void(uint inWheelIndex, float &outLongitudinalImpulse, float &outLateralImpulse, float inSuspensionImpulse, float inLongitudinalFriction, float inLateralFriction, float inLongitudinalSlip, float inLateralSlip, float inDeltaTime)>
 Calculate max tire impulses by combining friction, slip, and suspension impulse. Note that the actual applied impulse may be lower (e.g. when the vehicle is stationary on a horizontal surface the actual impulse applied will be 0). More...
 
- Static Public Member Functions inherited from RefTarget< VehicleController >
static int sInternalGetRefCountOffset ()
 INTERNAL HELPER FUNCTION USED BY SERIALIZATION. More...
 
- Static Protected Attributes inherited from RefTarget< VehicleController >
static constexpr uint32 cEmbedded
 A large value that gets added to the refcount to mark the object as embedded. More...
 

Detailed Description

Runtime controller class.

Constructor & Destructor Documentation

◆ MotorcycleController()

MotorcycleController::MotorcycleController ( const MotorcycleControllerSettings inSettings,
VehicleConstraint inConstraint 
)

Constructor.

Member Function Documentation

◆ Draw()

void MotorcycleController::Draw ( DebugRenderer inRenderer) const
overrideprotectedvirtual

Reimplemented from WheeledVehicleController.

◆ EnableLeanController()

void MotorcycleController::EnableLeanController ( bool  inEnable)
inline

Enable or disable the lean spring. This allows you to temporarily disable the lean spring to allow the motorcycle to fall over.

◆ EnableLeanSteeringLimit()

void MotorcycleController::EnableLeanSteeringLimit ( bool  inEnable)
inline

Enable or disable the lean steering limit. When enabled (default) the steering angle is limited based on the vehicle speed to prevent steering that would cause an inertial force that causes the motorcycle to topple over.

◆ GetLeanSmoothingFactor()

float MotorcycleController::GetLeanSmoothingFactor ( ) const
inline

◆ GetLeanSpringConstant()

float MotorcycleController::GetLeanSpringConstant ( ) const
inline

◆ GetLeanSpringDamping()

float MotorcycleController::GetLeanSpringDamping ( ) const
inline

◆ GetLeanSpringIntegrationCoefficient()

float MotorcycleController::GetLeanSpringIntegrationCoefficient ( ) const
inline

◆ GetLeanSpringIntegrationCoefficientDecay()

float MotorcycleController::GetLeanSpringIntegrationCoefficientDecay ( ) const
inline

◆ GetWheelBase()

float MotorcycleController::GetWheelBase ( ) const

Get the distance between the front and back wheels.

◆ IsLeanControllerEnabled()

bool MotorcycleController::IsLeanControllerEnabled ( ) const
inline

Check if the lean spring is enabled.

◆ IsLeanSteeringLimitEnabled()

bool MotorcycleController::IsLeanSteeringLimitEnabled ( ) const
inline

◆ PreCollide()

void MotorcycleController::PreCollide ( float  inDeltaTime,
PhysicsSystem inPhysicsSystem 
)
overrideprotectedvirtual

Reimplemented from WheeledVehicleController.

◆ RestoreState()

void MotorcycleController::RestoreState ( StateRecorder inStream)
overrideprotectedvirtual

Reimplemented from WheeledVehicleController.

◆ SaveState()

void MotorcycleController::SaveState ( StateRecorder inStream) const
overrideprotectedvirtual

Reimplemented from WheeledVehicleController.

◆ SetLeanSmoothingFactor()

void MotorcycleController::SetLeanSmoothingFactor ( float  inFactor)
inline

How much to smooth the lean angle (0 = no smoothing, 1 = lean angle never changes) Note that this is frame rate dependent because the formula is: smoothing_factor * previous + (1 - smoothing_factor) * current

◆ SetLeanSpringConstant()

void MotorcycleController::SetLeanSpringConstant ( float  inConstant)
inline

Spring constant for the lean spring.

◆ SetLeanSpringDamping()

void MotorcycleController::SetLeanSpringDamping ( float  inDamping)
inline

Spring damping constant for the lean spring.

◆ SetLeanSpringIntegrationCoefficient()

void MotorcycleController::SetLeanSpringIntegrationCoefficient ( float  inCoefficient)
inline

The lean spring applies an additional force equal to this coefficient * Integral(delta angle, 0, t), this effectively makes the lean spring a PID controller.

◆ SetLeanSpringIntegrationCoefficientDecay()

void MotorcycleController::SetLeanSpringIntegrationCoefficientDecay ( float  inDecay)
inline

How much to decay the angle integral when the wheels are not touching the floor: new_value = e^(-decay * t) * initial_value.

◆ SolveLongitudinalAndLateralConstraints()

bool MotorcycleController::SolveLongitudinalAndLateralConstraints ( float  inDeltaTime)
overrideprotectedvirtual

Reimplemented from WheeledVehicleController.

Member Data Documentation

◆ mAppliedImpulse

float MotorcycleController::mAppliedImpulse = 0.0f
protected

◆ mEnableLeanController

bool MotorcycleController::mEnableLeanController = true
protected

◆ mEnableLeanSteeringLimit

bool MotorcycleController::mEnableLeanSteeringLimit = true
protected

◆ mLeanSmoothingFactor

float MotorcycleController::mLeanSmoothingFactor
protected

◆ mLeanSpringConstant

float MotorcycleController::mLeanSpringConstant
protected

◆ mLeanSpringDamping

float MotorcycleController::mLeanSpringDamping
protected

◆ mLeanSpringIntegratedDeltaAngle

float MotorcycleController::mLeanSpringIntegratedDeltaAngle = 0.0f
protected

◆ mLeanSpringIntegrationCoefficient

float MotorcycleController::mLeanSpringIntegrationCoefficient
protected

◆ mLeanSpringIntegrationCoefficientDecay

float MotorcycleController::mLeanSpringIntegrationCoefficientDecay
protected

◆ mMaxLeanAngle

float MotorcycleController::mMaxLeanAngle
protected

◆ mTargetLean

Vec3 MotorcycleController::mTargetLean = Vec3::sZero()
protected

The documentation for this class was generated from the following files: