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

Settings for a linear or angular spring. More...

#include <SpringSettings.h>

Public Member Functions

 SpringSettings ()=default
 Constructor. More...
 
 SpringSettings (const SpringSettings &)=default
 
SpringSettingsoperator= (const SpringSettings &)=default
 
 SpringSettings (ESpringMode inMode, float inFrequencyOrStiffness, float inDamping)
 
void SaveBinaryState (StreamOut &inStream) const
 Saves the contents of the spring settings in binary form to inStream. More...
 
void RestoreBinaryState (StreamIn &inStream)
 Restores contents from the binary stream inStream. More...
 
bool HasStiffness () const
 Check if the spring has a valid frequency / stiffness, if not the spring will be hard. More...
 

Public Attributes

ESpringMode mMode = ESpringMode::FrequencyAndDamping
 
union {
   float   mFrequency = 0.0f
 
   float   mStiffness
 
}; 
 
float mDamping = 0.0f
 

Detailed Description

Settings for a linear or angular spring.

Constructor & Destructor Documentation

◆ SpringSettings() [1/3]

SpringSettings::SpringSettings ( )
default

Constructor.

◆ SpringSettings() [2/3]

SpringSettings::SpringSettings ( const SpringSettings )
default

◆ SpringSettings() [3/3]

SpringSettings::SpringSettings ( ESpringMode  inMode,
float  inFrequencyOrStiffness,
float  inDamping 
)
inline

Member Function Documentation

◆ HasStiffness()

bool SpringSettings::HasStiffness ( ) const
inline

Check if the spring has a valid frequency / stiffness, if not the spring will be hard.

◆ operator=()

SpringSettings & SpringSettings::operator= ( const SpringSettings )
default

◆ RestoreBinaryState()

void SpringSettings::RestoreBinaryState ( StreamIn inStream)

Restores contents from the binary stream inStream.

◆ SaveBinaryState()

void SpringSettings::SaveBinaryState ( StreamOut inStream) const

Saves the contents of the spring settings in binary form to inStream.

Member Data Documentation

◆ 

union { ... } SpringSettings::@22

◆ mDamping

float SpringSettings::mDamping = 0.0f

When mSpringMode = ESpringMode::FrequencyAndDamping mDamping is the damping ratio (0 = no damping, 1 = critical damping). When mSpringMode = ESpringMode::StiffnessAndDamping mDamping is the damping (c) in the spring equation F = -k * x - c * v for a linear or T = -k * theta - c * w for an angular spring. Note that if you set mDamping = 0, you will not get an infinite oscillation. Because we integrate physics using an explicit Euler scheme, there is always energy loss. This is done to keep the simulation from exploding, because with a damping of 0 and even the slightest rounding error, the oscillation could become bigger and bigger until the simulation explodes.

◆ mFrequency

float SpringSettings::mFrequency = 0.0f

Valid when mSpringMode = ESpringMode::FrequencyAndDamping. If mFrequency > 0 the constraint will be soft and mFrequency specifies the oscillation frequency in Hz. If mFrequency <= 0, mDamping is ignored and the constraint will have hard limits (as hard as the time step / the number of velocity / position solver steps allows).

◆ mMode

ESpringMode SpringSettings::mMode = ESpringMode::FrequencyAndDamping

Selects the way in which the spring is defined If the mode is StiffnessAndDamping then mFrequency becomes the stiffness (k) and mDamping becomes the damping ratio (c) in the spring equation F = -k * x - c * v. Otherwise the properties are as documented.

◆ mStiffness

float SpringSettings::mStiffness

Valid when mSpringMode = ESpringMode::StiffnessAndDamping. If mStiffness > 0 the constraint will be soft and mStiffness specifies the stiffness (k) in the spring equation F = -k * x - c * v for a linear or T = -k * theta - c * w for an angular spring. If mStiffness <= 0, mDamping is ignored and the constraint will have hard limits (as hard as the time step / the number of velocity / position solver steps allows).

Note that stiffness values are large numbers. To calculate a ballpark value for the needed stiffness you can use: force = stiffness * delta_spring_length = mass * gravity <=> stiffness = mass * gravity / delta_spring_length. So if your object weighs 1500 kg and the spring compresses by 2 meters, you need a stiffness in the order of 1500 * 9.81 / 2 ~ 7500 N/m.


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