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

QParticle objects form the network structures of QMesh objects defined for all body object types. They are the smallest building blocks of physics simulation and are manipulated differently in different body object types. For example, in QRigidBody objects, particles are collectively forced into positions obtained through various calculations based on the current body properties. However, in soft body objects, simulation particles are individually manipulated and can move freely, determining the next steps of the simulation through their individual movements. QMesh objects offer a number of methods to manage particles. For more information on restrictions between particles in soft body objects, see the QSpring object. More...

#include <qparticle.h>

Public Member Functions

 QParticle (float posX, float posY, float radius=0.5f)
 
 QParticle (QVector pos, float radius=0.5f)
 
QVector GetGlobalPosition ()
 
QVector GetPreviousGlobalPosition ()
 
QVector GetPosition ()
 
float GetMass ()
 
QMeshGetOwnerMesh ()
 
float GetRadius ()
 
bool GetIsInternal ()
 
QVector GetForce ()
 
bool GetEnabled ()
 
bool GetIsLazy ()
 
QAABB GetAABB ()
 
QParticleSetGlobalPosition (QVector value)
 
QParticleAddGlobalPosition (QVector value)
 
QParticleSetPreviousGlobalPosition (QVector value)
 
QParticleAddPreviousGlobalPosition (QVector value)
 
QParticleSetPosition (QVector value)
 
QParticleAddPosition (QVector value)
 
QParticleSetMass (float value)
 
QParticleSetOwnerMesh (QMesh *mesh)
 
QParticleSetRadius (float radius)
 
QParticleSetIsInternal (bool value)
 
QParticleSetEnabled (bool value)
 
QParticleSetIsLazy (bool value)
 
QParticleApplyForce (QVector value)
 
QParticleSetForce (QVector value)
 
QParticleAddForce (QVector value)
 
QParticleAddAccumulatedForce (QVector value)
 
QParticleClearAccumulatedForces ()
 
QParticleApplyAccumulatedForces ()
 
bool IsConnectedWithSpring (QParticle *particle)
 

Static Public Member Functions

static void ApplyForceToParticleSegment (QParticle *pA, QParticle *pB, QVector force, QVector fromPosition)
 
static bool SortParticlesHorizontal (QParticle *pA, QParticle *pB)
 

Public Attributes

bool manualDeletion =false
 

Protected Member Functions

void ResetOneTimeCollisions ()
 
void UpdateAABB ()
 

Protected Attributes

std::unordered_set< QParticle * > springConnectedParticles
 
unordered_set< QBody * > oneTimeCollidedBodies
 
unordered_set< QBody * > previousCollidedBodies
 
bool ignoreGravity =false
 

Friends

class QMesh
 
class QBody
 
class QManifold
 
class QAreaBody
 
class QCollision
 

Detailed Description

QParticle objects form the network structures of QMesh objects defined for all body object types. They are the smallest building blocks of physics simulation and are manipulated differently in different body object types. For example, in QRigidBody objects, particles are collectively forced into positions obtained through various calculations based on the current body properties. However, in soft body objects, simulation particles are individually manipulated and can move freely, determining the next steps of the simulation through their individual movements. QMesh objects offer a number of methods to manage particles. For more information on restrictions between particles in soft body objects, see the QSpring object.

Member Function Documentation

◆ AddAccumulatedForce()

QParticle * QParticle::AddAccumulatedForce ( QVector  value)

Adds a new force to the accumulated forces. The purpose of the accumulated forces is to apply their arithmetic average using ApplyAccumulatedForce(). Before performing operations with the accumulated forces, they must be cleared using ClearAccumulatedForce().

Parameters
valueA value to add.
Returns
A pointer to the particle itself.

◆ AddForce()

QParticle * QParticle::AddForce ( QVector  value)

Adds a value to the force of the particle.Set forces determine the force to be applied to a particle object at the next physics step from the current step.

Parameters
valueA value to add.
Returns
A pointer to the particle itself.

◆ AddGlobalPosition()

QParticle * QParticle::AddGlobalPosition ( QVector  value)

Adds a value to the global position of the particle.

Parameters
valueA position value to set.
Returns
A pointer to the particle itself.

◆ AddPosition()

QParticle * QParticle::AddPosition ( QVector  value)

Adds a value to the local position of the particle.

Parameters
valueA value to add.
Returns
A pointer to the particle itself.

◆ AddPreviousGlobalPosition()

QParticle * QParticle::AddPreviousGlobalPosition ( QVector  value)

Adds a value to the previous global position of the particle.

Parameters
valueA value to add.
Returns
A pointer to the particle itself.

◆ ApplyAccumulatedForces()

QParticle * QParticle::ApplyAccumulatedForces ( )

Calculates the arithmetic average of the accumulated forces based on the number of forces, applies it to the particle, and then clears all forces.

◆ ApplyForce()

QParticle * QParticle::ApplyForce ( QVector  value)

Applies a force immediately to the particle. You can use the method safely before the physics step (e.g. at the OnPreStep event of QBody objects). If you want to use this method after physics step, it can break the simulation.(Collisions and constraints may not be applied properly.) if you want to apply force at the next physic step safely, use SetForce() and AddForce() methods.

Parameters
valueA force value to apply.

◆ ApplyForceToParticleSegment()

void QParticle::ApplyForceToParticleSegment ( QParticle pA,
QParticle pB,
QVector  force,
QVector  fromPosition 
)
static

Applies a specified force to a segment created by two particles at a specific position.

Parameters
pAA particle in the world.
pBAnother particle in the world.
forceA force value to apply.
fromPositionThe position of the force.

◆ ClearAccumulatedForces()

QParticle * QParticle::ClearAccumulatedForces ( )

Clears the accumulated forces. It should be called before working with accumulated forces. Additionally, the accumulated forces are automatically cleared after the ApplyAccumulatedForce() method is called.

◆ GetAABB()

QAABB QParticle::GetAABB ( )
inline

Returns the AABB of the particle.

◆ GetEnabled()

bool QParticle::GetEnabled ( )
inline

Returns whether the particle is enabled. Disabled particles are not exempt from the collision tests that involve the meshes they belong to, but the solutions of their manifolds are not applied. Additionally, in body types where particles can move freely individually (e.g., QSoftBody), force and velocity integrations are not applied.

Note
Disabled particles in QRigidBody objects may appear to move because they are transformed based on the position and rotation of the rigid body.

◆ GetForce()

QVector QParticle::GetForce ( )
inline

Returns the current force value of the particle.

◆ GetGlobalPosition()

QVector QParticle::GetGlobalPosition ( )
inline

Returns the global position of the particle.

◆ GetIsInternal()

bool QParticle::GetIsInternal ( )
inline

Returns whether the particle is internal. Internal particle definition is used not for the particles that define the collision boundaries of a mesh, but for the grid particles inside these boundaries. This feature is important for simulation types that require different internal particle simulation, such as volume preserved soft bodies.

◆ GetIsLazy()

bool QParticle::GetIsLazy ( )
inline

Returns whether the particle's lazy feature is enabled. This feature allows the particle to react once in a one-sided manner when colliding with an object; after that, it won't react again until it exits and re-enters the collision. This feature is used for particles that lightly interact with surrounding objects when necessary.

◆ GetMass()

float QParticle::GetMass ( )
inline

Returns the mass of the particle.

◆ GetOwnerMesh()

QMesh* QParticle::GetOwnerMesh ( )
inline

Returns owner mesh of the particle. The Owner mesh is the mesh in which the particle is appointed.

◆ GetPosition()

QVector QParticle::GetPosition ( )
inline

Returns the local position of the particle.

◆ GetPreviousGlobalPosition()

QVector QParticle::GetPreviousGlobalPosition ( )
inline

Returns the previous global position of the particle.

◆ GetRadius()

float QParticle::GetRadius ( )
inline

Returns the radius of the particle.

◆ IsConnectedWithSpring()

bool QParticle::IsConnectedWithSpring ( QParticle particle)

Checks if the given particle is connected to this particle via a spring. Returns true if a connection exists, otherwise returns false.

Parameters
particleA particle to check
Returns
Returns true if a connection exists, otherwise returns false.

◆ SetEnabled()

QParticle * QParticle::SetEnabled ( bool  value)

Sets whether the particle is enabled. Disabled particles are not exempt from the collision tests that involve the meshes they belong to, but the solutions of their manifolds are not applied. Additionally, in body types where particles can move freely individually (e.g., QSoftBody), force and velocity integrations are not applied.

Note
Disabled particles in QRigidBody objects may appear to move because they are transformed based on the position and rotation of the rigid body.
Parameters
valueA value to set.
Returns
A pointer to the particle itself.

◆ SetForce()

QParticle * QParticle::SetForce ( QVector  value)

Sets the force value of the particle. Set forces determine the force to be applied to a particle object at the next physics step from the current step.

Parameters
valueA value to set.
Returns
A pointer to the particle itself.

◆ SetGlobalPosition()

QParticle * QParticle::SetGlobalPosition ( QVector  value)

Sets the global position of the particle.

Parameters
valueA position value to set.
Returns
A pointer to the particle itself.

◆ SetIsInternal()

QParticle * QParticle::SetIsInternal ( bool  value)

Sets whether the particle is internal.Internal particle definition is used not for the particles that define the collision boundaries of a mesh, but for the grid particles inside these boundaries. This feature is important for simulation types that require different internal particle simulation, such as volume preserved soft bodies.

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

◆ SetIsLazy()

QParticle * QParticle::SetIsLazy ( bool  value)

Sets whether the particle's lazy feature is enabled. This feature allows the particle to react once in a one-sided manner when colliding with an object; after that, it won't react again until it exits and re-enters the collision. This feature is used for particles that lightly interact with surrounding objects when necessary.

Parameters
valueA value to set.
Returns
A pointer to the particle itself.

◆ SetMass()

QParticle * QParticle::SetMass ( float  value)

Sets the mass of the particle.

Parameters
valueA value to set.
Returns
A pointer to the particle itself.

◆ SetOwnerMesh()

QParticle * QParticle::SetOwnerMesh ( QMesh mesh)

Sets the owner mesh of the particle. Usually the owner mesh is defining when a particle added to a mesh.

Parameters
meshA pointer of the mesh to set.
Returns
A pointer to the particle itself.

◆ SetPosition()

QParticle * QParticle::SetPosition ( QVector  value)

Sets local position of the particle.

Parameters
valueA value to set.
Returns
A pointer to the particle itself.

◆ SetPreviousGlobalPosition()

QParticle * QParticle::SetPreviousGlobalPosition ( QVector  value)

Sets the previous global position of the particle.

Parameters
valueA position value to set.
Returns
A pointer to the particle itself.

◆ SetRadius()

QParticle * QParticle::SetRadius ( float  radius)

Sets the radius of the particle.

Parameters
radiusA value to set.
Returns
A pointer to the particle itself.

Member Data Documentation

◆ manualDeletion

bool QParticle::manualDeletion =false

By default, objects included in the physics engine are deleted by the destructors of the objects they belong to. When this flag is enabled, it indicates that this object should never be deleted by this engine. It is disabled by default, and it is recommended to keep it disabled. However, it can be used if needed for advanced purposes and integrations.


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