Quark Physics  1.0
2D Rigid and Soft Body Physics Engine
QSpring Class Reference

You can apply distance constraints between 2 particles using the QSpring. The physics engine uses QSpring to impose distance constraints between particles in objects already simulated using mass-spring models (e.g. QSoftBody objects). However, if the user wants, they can apply specific distance constraints between any 2 particles using QSpring. QWorld also provides methods to manage QSpring objects. More...

#include <qspring.h>

Public Member Functions

 QSpring (QParticle *particleA, QParticle *particleB, bool internal=false)
 
 QSpring (QParticle *particleA, QParticle *particleB, float length, bool internal=false)
 
virtual void Update (float rigidity, bool internalsException, bool isWorldSpring=false)
 
QParticleGetParticleA ()
 
QParticleGetParticleB ()
 
float GetLength ()
 
bool GetIsInternal ()
 
float GetRigidity ()
 
bool GetEnabled ()
 
QSpringSetParticleA (QParticle *particle)
 
QSpringSetParticleB (QParticle *particle)
 
QSpringSetLength (float length)
 
QSpringSetIsInternal (bool value)
 
QSpringSetRigidity (float rigidity)
 
QSpringSetEnabled (bool value)
 

Detailed Description

You can apply distance constraints between 2 particles using the QSpring. The physics engine uses QSpring to impose distance constraints between particles in objects already simulated using mass-spring models (e.g. QSoftBody objects). However, if the user wants, they can apply specific distance constraints between any 2 particles using QSpring. QWorld also provides methods to manage QSpring objects.

Note
You can think of QSpring objects as similar to QJoint, which provides special distance constraints for rigid body objects in particle-based simulations. You can also use QSpring to connect objects with each other, but the constraints are enforced between particles.
Warning
QSpring will not work correctly on objects that are not simulated with particle dynamics, such as rigid bodies whose positions are fixed by transformations. QSpring relies on the ability to change the positions of particles with freedom of movement to apply constraints correctly.

Constructor & Destructor Documentation

◆ QSpring() [1/2]

QSpring::QSpring ( QParticle particleA,
QParticle particleB,
bool  internal = false 
)

Creates a spring between two particles. But auto calculates length with the distance between two particles.

Parameters
particleAA particle in the world.
particleBAnother particle in the world.
internalDetermines whether the spring connection between two particles is an internal connection within an object. It can usually be set to false. This setting is important for soft body objects with the volume preserving option enabled, where internal spring connections are restricted in different ways.

◆ QSpring() [2/2]

QSpring::QSpring ( QParticle particleA,
QParticle particleB,
float  length,
bool  internal = false 
)

Creates a spring between two particles with a specified length.

Parameters
particleAA particle in the world.
particleBAnother particle in the world.
lengthThe distance between the two particles.
internalDetermines whether the spring connection between two particles is an internal connection within an object.It can usually be set to false. This setting is important for soft body objects with the volume preserving option enabled, where internal spring connections are restricted in different ways.

Member Function Documentation

◆ GetEnabled()

bool QSpring::GetEnabled ( )
inline

Returns whether the spring is enabled.

◆ GetIsInternal()

bool QSpring::GetIsInternal ( )
inline

Returns whether the spring is internal.

◆ GetLength()

float QSpring::GetLength ( )
inline

Returns the length of the spring.

◆ GetParticleA()

QParticle* QSpring::GetParticleA ( )
inline

Returns particleA of the spring.

◆ GetParticleB()

QParticle* QSpring::GetParticleB ( )
inline

Returns particleB of the spring.

◆ GetRigidity()

float QSpring::GetRigidity ( )
inline

Returns the rigidity of the spring.

◆ SetEnabled()

QSpring* QSpring::SetEnabled ( bool  value)
inline

Sets whether the spring is enabled.

Parameters
valueTrue or false.
Returns
A pointer to the spring itself.

◆ SetIsInternal()

QSpring* QSpring::SetIsInternal ( bool  value)
inline

Sets whether the spring is internal.

Parameters
valueTrue or false.
Returns
A pointer to the spring itself.

◆ SetLength()

QSpring* QSpring::SetLength ( float  length)
inline

Sets the length of the spring.

Parameters
lengthThe length to set.
Returns
A pointer to the spring itself.

◆ SetParticleA()

QSpring* QSpring::SetParticleA ( QParticle particle)
inline

Sets particleA of the spring.

Parameters
particleA pointer to the particle.
Returns
A pointer to the spring itself.

◆ SetParticleB()

QSpring* QSpring::SetParticleB ( QParticle particle)
inline

Sets particleB of the spring.

Parameters
particleA pointer to the particle.
Returns
A pointer to the spring itself.

◆ SetRigidity()

QSpring* QSpring::SetRigidity ( float  rigidity)
inline

Sets the rigidity of the spring.

Parameters
rigidityThe rigidity value to set.It must be a value between 0.0 and 1.0.
Returns
A pointer to the spring itself.

◆ Update()

void QSpring::Update ( float  rigidity,
bool  internalsException,
bool  isWorldSpring = false 
)
virtual

Applies spring constraints and updates particle positions.

Parameters
rigidityThe rigidity of the constraint. The rigidity must be a value between 0.0 and 1.0.
internalsExceptionIt is usually set to false. However, if set to true, it pays attention to internal particle connections and applies the constraints accordingly. This setting is important for soft body objects with the volume preserving option enabled. \Note This method is virtual and users can implement custom spring update methods in an interited class of QSpring.

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