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

A QWorld object is required to create a physics simulation. The QWorld class manages the entire physics simulation. You can add or remove objects to the physics world and make specific settings for the simulation. Additionally, the QWorld class is responsible for updating the simulation. More...

#include <qworld.h>

Collaboration diagram for QWorld:

Public Member Functions

QVector GetGravity ()
 
bool GetSleepingEnabled ()
 
float GetSleepingPositionTolerance ()
 
float GetSleepingRotationTolerance ()
 
bool GetBroadphaseEnabled ()
 
QBroadPhaseGetBroadphase ()
 
int GetIterationCount ()
 
float GetTimeScale ()
 
bool GetEnabled ()
 
QWorldSetGravity (QVector value)
 
QWorldSetSleepingEnabled (bool value)
 
QWorldSetSleepingPositionTolerance (float value)
 
QWorldSetSleepingRotationTolerance (float value)
 
QWorldSetBroadphaseEnabled (bool value)
 
QWorldSetBroadphase (QBroadPhase *externalBroadphase)
 
QWorldSetIterationCount (int value)
 
QWorldSetTimeScale (float value=1.0f)
 
QWorldSetEnabled (bool value)
 
void Update ()
 
QWorldAddBody (QBody *body)
 
QWorldAddBodyGroup (const vector< QBody * > &bodyGroup)
 
QWorldRemoveBody (QBody *body)
 
QWorldRemoveBodyAt (int index)
 
int GetBodyCount ()
 
QBodyGetBodyAt (int index)
 
int GetBodyIndex (QBody *body)
 
vector< QBody * > GetBodiesHitByPoint (QVector point, int maxBodyCount=1, bool onlyRigidBodies=true, int layersBit=-1)
 
vector< QParticle * > GetParticlesCloseToPoint (QVector point, float distance, int maxParticleCount=1, bool exceptRigidBodies=true, int layersBit=-1)
 
bool CollideWithWorld (QBody *body)
 
vector< QManifoldTestCollisionWithWorld (QBody *body)
 
QWorldAddJoint (QJoint *joint)
 
QWorldRemoveJoint (QJoint *joint)
 
QWorldRemoveJointAt (int index)
 
QWorldRemoveMatchingJoints (QBody *body)
 
int GetJointCount ()
 
QJointGetJointAt (int index)
 
int GetJointIndex (QJoint *joint)
 
QWorldAddSpring (QSpring *spring)
 
QWorldRemoveSpring (QSpring *spring)
 
QWorldRemoveSpringAt (int index)
 
QWorldRemoveMatchingSprings (QBody *body)
 
QWorldRemoveMatchingSprings (QParticle *particle)
 
int GetSpringCount ()
 
QSpringGetSpringAt (int index)
 
int GetSpringIndex (QSpring *spring)
 
QWorldAddRaycast (QRaycast *raycast)
 
QWorldRemoveRaycast (QRaycast *raycast)
 
QWorldRemoveRaycastAt (int index)
 
int GetRaycastCount ()
 
QRaycastGetRaycastAt (int index)
 
int GetRaycastIndex (QRaycast *raycast)
 
vector< QGizmo * > * GetGizmos ()
 
QWorldAddCollisionException (QBody *bodyA, QBody *bodyB)
 
QWorldRemoveCollisionException (QBody *bodyA, QBody *bodyB)
 
QWorldRemoveMatchingCollisionException (QBody *body)
 
bool CheckCollisionException (QBody *bodyA, QBody *bodyB)
 
 QWorld ()
 
QWorldClearJoints ()
 
QWorldClearSprings ()
 
QWorldClearRaycasts ()
 
QWorldClearWorld ()
 

Static Public Member Functions

static vector< QCollision::Contact * > GetCollisions (QBody *bodyA, QBody *bodyB)
 

Public Attributes

vector< QBody * > bodies =vector<QBody*>()
 

Static Public Attributes

static float MAX_WORLD_SIZE =99999.0f
 

Protected Member Functions

void ClearGizmos ()
 
void ClearBodies ()
 
void CreateIslands (int bodyIndex, vector< QBody * > &bodyList, vector< QBody * > &island, vector< bool > &visitedList)
 
void GenerateIslands (vector< QBody * > &bodyList, vector< vector< QBody * >> &islandList)
 
void GetCollisionPairs (vector< QBody * > &bodyList, vector< pair< QBody *, QBody * > > *resList)
 
void CreateIslands (QBody &body, vector< QBody * > island)
 
vector< vector< QBody > > GenerateIslands (vector< QBody > bodyList)
 
void UpdateConstraints ()
 

Static Protected Member Functions

static bool SortBodiesHorizontal (const QBody *bodyA, const QBody *bodyB)
 
static bool SortBodiesVertical (const QBody *bodyA, const QBody *bodyB)
 

Protected Attributes

vector< QJoint * > joints =vector<QJoint*>()
 
vector< QSpring * > springs =vector<QSpring*>()
 
vector< QRaycast * > raycasts =vector<QRaycast*>()
 
vector< QGizmo * > gizmos =vector<QGizmo*>()
 
vector< vector< QBody * > > sleepingIslands =vector<vector<QBody*> >()
 
unordered_set< pair< QBody *, QBody * >, QBody::BodyPairHash, QBody::BodyPairEqualcollisionExceptions
 
vector< QManifoldmanifolds
 
QBroadPhasebroadPhase =nullptr
 
bool enabled =true
 
QVector gravity =QVector(0.0f,0.2f)
 
bool enableSleeping =true
 
bool enableBroadphase =true
 
int iteration =4
 
float timeScale =1.0f
 
float sleepingPositionTolerance =0.1f
 
float sleepingRotationTolerance =M_PI/180.0f
 
int debugAABBTestCount =0
 
int debugCollisionTestCount =0
 

Friends

class QCollision
 
class QManifold
 
class QSoftBody
 
class QBroadPhase
 

Detailed Description

A QWorld object is required to create a physics simulation. The QWorld class manages the entire physics simulation. You can add or remove objects to the physics world and make specific settings for the simulation. Additionally, the QWorld class is responsible for updating the simulation.

Constructor & Destructor Documentation

◆ QWorld()

QWorld::QWorld ( )

Creates a world.

Member Function Documentation

◆ AddBody()

QWorld * QWorld::AddBody ( QBody body)

Adds a body to the world

Parameters
bodyA body to be added

◆ AddBodyGroup()

QWorld * QWorld::AddBodyGroup ( const vector< QBody * > &  bodyGroup)

Adds a body group to the world

Parameters
bodyGroupA collection of bodies to be added

◆ AddCollisionException()

QWorld * QWorld::AddCollisionException ( QBody bodyA,
QBody bodyB 
)

Adds a collision exception between two bodies. These bodies will never collide.

Parameters
bodyAA body in the world.
bodyBAnother body in the world.

◆ AddJoint()

QWorld * QWorld::AddJoint ( QJoint joint)

Adds a joint to the world.

Parameters
jointA joint to be added

◆ AddRaycast()

QWorld * QWorld::AddRaycast ( QRaycast raycast)

Adds a raycast to the world.

Parameters
raycastA raycast to be added.

◆ AddSpring()

QWorld * QWorld::AddSpring ( QSpring spring)

Adds a spring to the world.

Parameters
springA spring to be added.

◆ CheckCollisionException()

bool QWorld::CheckCollisionException ( QBody bodyA,
QBody bodyB 
)

Checks whether there is a collision exception between two bodies.

Parameters
bodyAA body in the world.
bodyBAnother body in the world.

◆ ClearJoints()

QWorld * QWorld::ClearJoints ( )

Removes all joints from the world.

◆ ClearRaycasts()

QWorld * QWorld::ClearRaycasts ( )

It removes all raycasts from the world.

◆ ClearSprings()

QWorld * QWorld::ClearSprings ( )

Removes all springs from the world.

◆ ClearWorld()

QWorld * QWorld::ClearWorld ( )

It removes all objects from the world.

◆ CollideWithWorld()

bool QWorld::CollideWithWorld ( QBody body)

Collides a body given to other bodies in the world. If is there a collision, it returns true.

Parameters
bodyA body from the world.

◆ GetBodiesHitByPoint()

vector< QBody * > QWorld::GetBodiesHitByPoint ( QVector  point,
int  maxBodyCount = 1,
bool  onlyRigidBodies = true,
int  layersBit = -1 
)

Returns a list of bodies that collide with the point given.

Parameters
pointA point to be collided.
maxBodyCountThe maximum number of bodies to be returned.
onlyRigidBodiesIf set to true, it only tests rigid bodies.(It's true as a default)
layersBitCollision layer bits(It setted -1 as a default, it's mean it doesn't filter bodies via layer bits )

◆ GetBodyAt()

QBody* QWorld::GetBodyAt ( int  index)
inline

Returns body at the specified index

Parameters
indexThe Index of the body to get.

◆ GetBodyCount()

int QWorld::GetBodyCount ( )
inline

Returns the total body count in the world.

◆ GetBodyIndex()

int QWorld::GetBodyIndex ( QBody body)
inline

Returns index of the specified body

Parameters
bodyA body pointer

◆ GetBroadphase()

QBroadPhase* QWorld::GetBroadphase ( )
inline

Returns the external broad phase object if defined. If not defined, returns nullptr.

◆ GetBroadphaseEnabled()

bool QWorld::GetBroadphaseEnabled ( )
inline

Returns whether broad phase optimization will be applied to the collisions.

◆ GetCollisions()

vector< QCollision::Contact * > QWorld::GetCollisions ( QBody bodyA,
QBody bodyB 
)
static

Performs the collision of the body and returns a contact list as a collision result.

Parameters
bodyAA body in the world.
bodyBAnother body in the world.

◆ GetEnabled()

bool QWorld::GetEnabled ( )
inline

Returns whether world is enabled.

◆ GetGizmos()

vector<QGizmo*>* QWorld::GetGizmos ( )
inline

Returns the collection of gizmos in the world.

◆ GetIterationCount()

int QWorld::GetIterationCount ( )
inline

Returns the iteration count per step of physics in the world. The Iteration count determines the stability level of the simulation.

◆ GetJointAt()

QJoint* QWorld::GetJointAt ( int  index)
inline

Returns the joint at the specified index.

Parameters
indexThe index of the joint.

◆ GetJointCount()

int QWorld::GetJointCount ( )
inline

Returns the total joint count of the world.

◆ GetJointIndex()

int QWorld::GetJointIndex ( QJoint joint)
inline

Returns the index of the specified joint.

Parameters
jointA joint in the world.

◆ GetParticlesCloseToPoint()

vector< QParticle * > QWorld::GetParticlesCloseToPoint ( QVector  point,
float  distance,
int  maxParticleCount = 1,
bool  exceptRigidBodies = true,
int  layersBit = -1 
)

Returns nearest particles to the specified point.

Parameters
pointA point to test
distanceThe distance of proximity to the point
maxParticleCountThe maximum number of particles to be returned.
exceptRigidBodiesIf set to true, it tests only non-rigid bodies.
layersBitCollision layer bits(It setted -1 as a default, it's mean doesn't filter bodies via layer bits )

◆ GetRaycastAt()

QRaycast* QWorld::GetRaycastAt ( int  index)
inline

Returns the raycast at the specified index.

Parameters
indexThe index of the raycast

◆ GetRaycastCount()

int QWorld::GetRaycastCount ( )
inline

Returns the total raycast count of the world.

◆ GetRaycastIndex()

int QWorld::GetRaycastIndex ( QRaycast raycast)
inline

Returns the index of the specified raycast.

Parameters
raycastA raycast in the world.

◆ GetSleepingEnabled()

bool QWorld::GetSleepingEnabled ( )
inline

Returns whether sleep mode will be applied to dynamic objects.

◆ GetSleepingPositionTolerance()

float QWorld::GetSleepingPositionTolerance ( )
inline

Returns the sleeping position tolerance. If the sleeping option is active, objects will go to sleep as long as they do not exceed this position change limit within a certain step amount.

◆ GetSleepingRotationTolerance()

float QWorld::GetSleepingRotationTolerance ( )
inline

Returns the sleeping rotation tolerance. If the sleeping option is active, objects will go to sleep as long as they do not exceed this rotation change limit within a certain step amount.

◆ GetSpringAt()

QSpring* QWorld::GetSpringAt ( int  index)
inline

Returns the spring at the specified index.

Parameters
indexThe index of the spring.

◆ GetSpringCount()

int QWorld::GetSpringCount ( )
inline

Returns the total spring count of the world.

◆ GetSpringIndex()

int QWorld::GetSpringIndex ( QSpring spring)
inline

Returns the index of the specified spring.

Parameters
springA spring in the world.

◆ GetTimeScale()

float QWorld::GetTimeScale ( )
inline

Returns the time scale for the physics simulation.

◆ RemoveBody()

QWorld * QWorld::RemoveBody ( QBody body)

Removes body from the world.

Parameters
bodyA body to be removed.

◆ RemoveBodyAt()

QWorld * QWorld::RemoveBodyAt ( int  index)

Removes the body from the world at the specified index. The index of a body can be obtained using the GetBodyIndex() method.

Parameters
indexThe index of the body to remove.

◆ RemoveCollisionException()

QWorld * QWorld::RemoveCollisionException ( QBody bodyA,
QBody bodyB 
)

Removes a collision exception.

Parameters
bodyAA body in the world.
bodyBAnother body in the world.

◆ RemoveJoint()

QWorld * QWorld::RemoveJoint ( QJoint joint)

Removes a joint from the world.

Parameters
jointA joint to be removed.

◆ RemoveJointAt()

QWorld * QWorld::RemoveJointAt ( int  index)

Removes a joint from the world at the specified index. The index of a joint can be obtained using the GetJointIndex() method.

Parameters
indexThe index of the joint to be removed.

◆ RemoveMatchingCollisionException()

QWorld * QWorld::RemoveMatchingCollisionException ( QBody body)

Removes a collision exception that contains the given body.

Parameters
bodyA body to be matched.

◆ RemoveMatchingJoints()

QWorld * QWorld::RemoveMatchingJoints ( QBody body)

Removes the joints that contain the specified body.

Parameters
bodyA body to be matched.

◆ RemoveMatchingSprings() [1/2]

QWorld * QWorld::RemoveMatchingSprings ( QBody body)

Removes the springs that contain the specified body.

Parameters
bodyA body to be matched.

◆ RemoveMatchingSprings() [2/2]

QWorld * QWorld::RemoveMatchingSprings ( QParticle particle)

Removes the springs that contain the specified particle.

Parameters
particleA particle to be matched.

◆ RemoveRaycast()

QWorld * QWorld::RemoveRaycast ( QRaycast raycast)

Removes a raycast from the world.

Parameters
raycastA raycast to be removed.

◆ RemoveRaycastAt()

QWorld * QWorld::RemoveRaycastAt ( int  index)

Removes a raycast from the world at the specified index. The index of a raycast can be obtained using the GetRaycastIndex() method.

Parameters
indexAn index number.

◆ RemoveSpring()

QWorld * QWorld::RemoveSpring ( QSpring spring)

Removes a spring from the world.

Parameters
springA spring to be removed.

◆ RemoveSpringAt()

QWorld * QWorld::RemoveSpringAt ( int  index)

Removes a spring from the world at the specified index. The index of a spring can be obtained using the GetSpringIndex() method.

Parameters
indexThe index of the spring to be removed.

◆ SetBroadphase()

QWorld* QWorld::SetBroadphase ( QBroadPhase externalBroadphase)
inline

Custom solutions inheriting from the QBroadphase class can be defined for the broad phase. This allows external broad phase solutions to be plugged in or removed.

Parameters
externalBroadphaseA QBroadphase-typed class representing the external broad phase solution.

◆ SetBroadphaseEnabled()

QWorld* QWorld::SetBroadphaseEnabled ( bool  value)
inline

Sets whether broad phase optimization will be applied to the collisions.

◆ SetEnabled()

QWorld* QWorld::SetEnabled ( bool  value)
inline

Sets whether world is enabled.

Parameters
valueA value to set

◆ SetGravity()

QWorld* QWorld::SetGravity ( QVector  value)
inline

Sets the gravity force of the world. The gravity force applies to dynamic bodies in every step of physics.

Parameters
valueThe force vector value of the gravity.

◆ SetIterationCount()

QWorld* QWorld::SetIterationCount ( int  value)
inline

Sets the iteration count per step of physics in the world. Iteration count determines stability level of the simulation.

Parameters
valueThe number of iterations per step.

◆ SetSleepingEnabled()

QWorld* QWorld::SetSleepingEnabled ( bool  value)
inline

Sets whether sleep mode will be applied to dynamic objects.

Parameters
valueA value to set

◆ SetSleepingPositionTolerance()

QWorld* QWorld::SetSleepingPositionTolerance ( float  value)
inline

Sets the sleeping position tolerance. If the sleeping option is active, objects will go to sleep as long as they do not exceed this position change limit within a certain step amount.

Parameters
valueA value to set

◆ SetSleepingRotationTolerance()

QWorld* QWorld::SetSleepingRotationTolerance ( float  value)
inline

Sets the sleeping rotation tolerance. If the sleeping option is active, objects will go to sleep as long as they do not exceed this rotation change limit within a certain step amount.

Parameters
valueA value to set

◆ SetTimeScale()

QWorld* QWorld::SetTimeScale ( float  value = 1.0f)
inline

Sets the time scale for the physics simulation. The default value is 1.0. If you give a value lower than 1.0, the simulation will slow down, and if you give a value higher than 1.0, the simulation will speed up.

Parameters
valueA value to set.

◆ TestCollisionWithWorld()

vector< QManifold > QWorld::TestCollisionWithWorld ( QBody body)

Applies a collision test between a body and other bodies in the world, returning a list of manifolds if collisions are detected.

Parameters
bodyA body from the world.

◆ Update()

void QWorld::Update ( )

Updates the physics simulation of the world as a step.


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