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

QRigidBody is a type of body that is simulated with the dynamics of Rigid body. A rigid body is a type of object in physics simulations that models non-deformable, solid objects. Rigid bodies have properties such as momentum, center of mass, inertia, and mass, which affect their simulation. These properties are used to compute the motion and collisions of rigid bodies in a physics engine. More...

#include <qrigidbody.h>

Inheritance diagram for QRigidBody:
Collaboration diagram for QRigidBody:

Public Member Functions

bool GetFixedRotationEnabled ()
 
bool GetKinematicEnabled ()
 
bool GetKinematicCollisionsEnabled ()
 
QVector GetForce ()
 
float GetAngularForce ()
 
QRigidBodySetFixedRotationEnabled (bool value)
 
QRigidBodySetKinematicEnabled (bool value)
 
QRigidBodySetKinematicCollisionsEnabled (bool value)
 
QRigidBodySetPositionAndCollide (QVector value, bool withPreviousPosition=true)
 
QRigidBodyApplyForce (QVector force, QVector r, bool updateMeshTransforms=true)
 
QRigidBodyApplyImpulse (QVector impulse, QVector r)
 
QRigidBodySetForce (QVector value)
 
QRigidBodyAddForce (QVector value)
 
QRigidBodySetAngularForce (float value)
 
QRigidBodyAddAngularForce (float value)
 
virtual void Update ()
 
virtual void PostUpdate ()
 
- Public Member Functions inherited from QBody
virtual void OnPreStep ()
 
virtual void OnStep ()
 
virtual bool OnCollision (CollisionInfo)
 
BodyTypes GetBodyType ()
 
QWorldGetWorld ()
 
QVector GetPosition ()
 
QVector GetPreviousPosition ()
 
float GetRotation ()
 
float GetRotationDegree ()
 
float GetPreviousRotation ()
 
QAABB GetAABB () const
 
float GetTotalInitialArea ()
 
float GetTotalPolygonsInitialArea ()
 
float GetTotalArea ()
 
float GetTotalPolygonsArea ()
 
Modes GetMode ()
 
float GetInertia ()
 
int GetLayersBit ()
 
int GetCollidableLayersBit ()
 
bool GetOverlapWithCollidableLayersBit (int layersBit)
 
bool GetOverlapWithLayersBit (int layersBit)
 
bool GetIsSleeping ()
 
bool GetCanSleep ()
 
SimulationModels GetSimulationModel ()
 
float GetFriction ()
 
float GetStaticFriction ()
 
float GetAirFriction ()
 
virtual float GetMass ()
 
float GetRestitution ()
 
float GetCircumference ()
 
bool GetBodySpecificTimeScaleEnabled ()
 
float GetBodySpesificTimeScale ()
 
bool GetEnabled ()
 
float GetVelocityLimit ()
 
bool GetIntegratedVelocitiesEnabled ()
 
QBodySetPosition (QVector value, bool withPreviousPosition=true)
 
QBodyAddPosition (QVector value, bool withPreviousPosition=true)
 
QBodySetPreviousPosition (QVector value)
 
QBodyAddPreviousPosition (QVector value)
 
QBodySetRotation (float angleRadian, bool withPreviousRotation=true)
 
QBodySetRotationDegree (float degree, bool withPreviousRotation=true)
 
QBodyAddRotation (float angleRadian, bool withPreviousRotation=true)
 
QBodySetPreviousRotation (float angleRadian)
 
QBodyAddPreviousRotation (float angleRadian)
 
QBodySetLayersBit (int value)
 
QBodySetCollidableLayersBit (int value)
 
QBodySetCanSleep (bool value)
 
QBodySetMode (QBody::Modes bodyMode)
 
QBodySetSimulationModel (SimulationModels model)
 
QBodySetFriction (float value)
 
QBodySetStaticFriction (float value)
 
QBodySetAirFriction (float value)
 
QBodySetMass (float value)
 
QBodySetRestitution (float value)
 
QBodySetBodySpecificTimeScaleEnabled (bool value)
 
QBodySetBodySpecificTimeScale (float value)
 
QBodySetEnabled (bool value)
 
QBodySetIntegratedVelocitiesEnabled (bool value)
 
QBodyAddMesh (QMesh *mesh)
 
QBodyRemoveMeshAt (int index)
 
QMeshGetMeshAt (int index)
 
int GetMeshCount ()
 
vector< QMesh * > * GetMeshes ()
 
QBodyAddMeshesFromFile (string filePath)
 
QBodyWakeUp ()
 
QBodySetVelocityLimit (float value)
 

Protected Attributes

float angularForce =0.0f
 
QVector force =QVector::Zero()
 
- Protected Attributes inherited from QBody
QWorldworld
 
QVector position =QVector(0,0)
 
QVector prevPosition =QVector::Zero()
 
float rotation =0.0f
 
float prevRotation =0.0f
 
QAABB aabb
 
Modes mode =QBody::Modes::DYNAMIC
 
bool inertiaNeedsUpdate =true
 
bool circumferenceNeedsUpdate =true
 
bool enableBodySpecificTimeScale =false
 
float bodySpecificTimeScale =1.0f
 
BodyTypes bodyType =BodyTypes::RIGID
 
bool enabled =true
 
float velocityLimit =0.0f
 
bool enableIntegratedVelocities =true
 
float friction =0.2f
 
float staticFriction =0.5f
 
float airFriction =0.01f
 
float mass =1.0f
 
float restitution =0.0f
 
int layersBit =1
 
int collidableLayersBit =1
 
bool isKinematic =false
 
bool allowKinematicCollisions =false
 
bool isSleeping =false
 
int sleepTick =120
 
int fixedVelocityTick =0
 
int fixedAngularTick =0
 
bool canSleep =true
 
vector< QMesh * > _meshes =vector<QMesh*>()
 
SimulationModels simulationModel =SimulationModels::RIGID_BODY
 

Additional Inherited Members

- Public Types inherited from QBody
enum  Modes { DYNAMIC , STATIC }
 
enum  BodyTypes { RIGID , AREA , SOFT }
 
enum  SimulationModels { MASS_SPRING , RIGID_BODY }
 
- Public Attributes inherited from QBody
std::function< void(QBody *body)> PreStepEventListener
 
std::function< void(QBody *body)> StepEventListener
 
std::function< bool(QBody *body, CollisionInfo)> CollisionEventListener
 
- Protected Member Functions inherited from QBody
void UpdateAABB ()
 
void UpdateMeshTransforms ()
 
virtual bool CanGiveCollisionResponseTo (QBody *otherBody)
 
- Static Protected Member Functions inherited from QBody
static QVector ComputeFriction (QBody *bodyA, QBody *bodyB, QVector &normal, float penetration, QVector &relativeVelocity)
 
static bool CanCollide (QBody *bodyA, QBody *bodyB, bool checkBodiesAreEnabled=true)
 

Detailed Description

QRigidBody is a type of body that is simulated with the dynamics of Rigid body. A rigid body is a type of object in physics simulations that models non-deformable, solid objects. Rigid bodies have properties such as momentum, center of mass, inertia, and mass, which affect their simulation. These properties are used to compute the motion and collisions of rigid bodies in a physics engine.

Rigid bodies are different from soft bodies and other particle-based physics objects, in that they are typically manipulated by adjusting their position and orientation directly, rather than by manipulating individual particles. The transformations applied to a rigid body are then used to update the positions and orientations of any associated meshes or graphics objects.

Rigid bodies are used to simulate a wide range of objects in physics simulations, such as rectangles, circles and complex shapes and are a fundamental part of most physics engines.

Member Function Documentation

◆ AddAngularForce()

QRigidBody * QRigidBody::AddAngularForce ( float  value)

Adds a value to the angular force of the body.

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

◆ AddForce()

QRigidBody * QRigidBody::AddForce ( QVector  value)

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

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

◆ ApplyForce()

QRigidBody * QRigidBody::ApplyForce ( QVector  force,
QVector  r,
bool  updateMeshTransforms = true 
)

Applies a force immediately to the body. You can use the method safely before the physics step (e.g. at the OnPreStep event). 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
forceThe force to apply.
rThe relative position to apply force.
updateMeshTransformsDetermines whether to update the transforms of the meshes. It is recommended to set this option to true in general use. If set to false, it changes the values such as position and rotation of the applied force, but does not update the corresponding mesh properties. This option is provided for optimization advantage for objects that are subjected to a lot of processing and where updating mesh transform until the end of the process is not important. In such cases, you can call the UpdateMeshTransforms() method externally after the process is completed.

◆ ApplyImpulse()

QRigidBody * QRigidBody::ApplyImpulse ( QVector  impulse,
QVector  r 
)

Applies a impulse immediately to the body. Since velocity values are implicit in this physical simulation, impulses are applied to previousPosition and previousRotation properties of the body.

Parameters
impulseThe impulse to apply.
rThe relative position to apply impulse.

◆ GetAngularForce()

float QRigidBody::GetAngularForce ( )
inline

Returns the current angular force value of the body.

◆ GetFixedRotationEnabled()

bool QRigidBody::GetFixedRotationEnabled ( )
inline

Returns whether the fixed rotation option is enabled.

◆ GetForce()

QVector QRigidBody::GetForce ( )
inline

Returns the current force value of the body.

◆ GetKinematicCollisionsEnabled()

bool QRigidBody::GetKinematicCollisionsEnabled ( )
inline

Sets whether collisions against other kinematic bodies are enabled.

◆ GetKinematicEnabled()

bool QRigidBody::GetKinematicEnabled ( )
inline

Returns whether kinematic option is enabled.

◆ PostUpdate()

void QRigidBody::PostUpdate ( )
virtual

Called after all bodies have completed their Update step to perform post-update operations.

Reimplemented from QBody.

Reimplemented in QPlatformerBody.

◆ SetAngularForce()

QRigidBody * QRigidBody::SetAngularForce ( float  value)

Sets the angular force of the body.

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

◆ SetFixedRotationEnabled()

QRigidBody* QRigidBody::SetFixedRotationEnabled ( bool  value)
inline

Sets whether the fixed rotation option is enabled. If set to true, the rotation value of the body never affected with the physics simulation.

◆ SetForce()

QRigidBody * QRigidBody::SetForce ( QVector  value)

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

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

◆ SetKinematicCollisionsEnabled()

QRigidBody* QRigidBody::SetKinematicCollisionsEnabled ( bool  value)
inline

Sets whether collisions against other kinematic bodies are enabled. By default, a kinematic body is not affected by collisions with other kinematic bodies. However, if set to true, a kinematic body can react to collisions with other kinematic bodies.

◆ SetKinematicEnabled()

QRigidBody* QRigidBody::SetKinematicEnabled ( bool  value)
inline

Sets whether the kinematic option is enabled. Physical interactions such as gravity and acceleration are not applied to Kinematic Body, and are not affected by collisions with dynamic objects. The values of these objects such as position and rotation are under the control of the user.

◆ SetPositionAndCollide()

QRigidBody * QRigidBody::SetPositionAndCollide ( QVector  value,
bool  withPreviousPosition = true 
)

Sets the position of the body and collides with other bodies. If you need to set the position after the physics step and you don't want to break the simulation, you can use this method. If you change the position of the body on the before the physics step ( e.g. at the OnPreStep event ), you don't need to use it.

Parameters
valueA position to set.
withPreviousPositionDetermines whether apply the position to the previous position of the body.In this simulation, since velocities are implicit, if the previous positions are the same as the newly set position, the positional velocity of the body will also be zeroed.Therefore, if you want to zero out the positional velocity when setting the new position, use this option.

◆ Update()

void QRigidBody::Update ( )
virtual

Updates properties of the rigid body and applies needed physical dynamics.

Reimplemented from QBody.


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