QBody objects are the base class for all types of bodies. Any class derived from QBody shares these methods and properties. Additionally, this base type provides flexible and common references for independent operations from qualified and named body types in the entire simulation. Virtual methods are defined for users to create different body types that inherit QBody. For example, the Update() method is used to apply different dynamics for all body types. QRigidBody instances derived from QBody have their own Update() solution, while QSoftBody instances have their own Update() solution. With these and similar virtual methods, unique new body types can be created.
More...
#include <qbody.h>
|
enum | Modes { DYNAMIC
, STATIC
} |
|
enum | BodyTypes { RIGID
, AREA
, SOFT
} |
|
enum | SimulationModels { MASS_SPRING
, RIGID_BODY
} |
|
|
void | UpdateAABB () |
|
void | UpdateMeshTransforms () |
|
virtual void | Update () |
|
virtual void | PostUpdate () |
|
virtual bool | CanGiveCollisionResponseTo (QBody *otherBody) |
|
|
static QVector | ComputeFriction (QBody *bodyA, QBody *bodyB, QVector &normal, float penetration, QVector &relativeVelocity) |
|
static bool | CanCollide (QBody *bodyA, QBody *bodyB, bool checkBodiesAreEnabled=true) |
|
|
QWorld * | world |
|
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 |
|
|
class | QMesh |
|
class | QWorld |
|
class | QManifold |
|
class | QParticle |
|
class | QJoint |
|
class | QBroadPhase |
|
QBody objects are the base class for all types of bodies. Any class derived from QBody shares these methods and properties. Additionally, this base type provides flexible and common references for independent operations from qualified and named body types in the entire simulation. Virtual methods are defined for users to create different body types that inherit QBody. For example, the Update() method is used to apply different dynamics for all body types. QRigidBody instances derived from QBody have their own Update() solution, while QSoftBody instances have their own Update() solution. With these and similar virtual methods, unique new body types can be created.
◆ Modes
Determines whether the body is dynamic or static. A static body does not react to any force, constraint or collision and does not move.A dynamic body reacts to forces, constraints, collisions, and any other world event.
◆ SimulationModels
Determines which approach will be used to simulate a body object.
◆ AddMesh()
Adds a mesh to the body.
- Parameters
-
mesh | A pointer of the mesh to add. |
- Returns
- A pointer to the body itself.
◆ AddMeshesFromFile()
QBody * QBody::AddMeshesFromFile |
( |
string |
filePath | ) |
|
Adds meshes with a json based *.qmesh file.
- Parameters
-
- Returns
- A pointer to the body itself.
◆ AddPosition()
QBody* QBody::AddPosition |
( |
QVector |
value, |
|
|
bool |
withPreviousPosition = true |
|
) |
| |
|
inline |
Adds a vector value the position of the body.
- Parameters
-
value | A vector value to add. |
withPreviousPosition | Determines whether apply the position to the previous position of the body.In this simulation, since velocities are implicit, if the previous position 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. |
- Returns
- A pointer to the body itself.
◆ AddPreviousPosition()
Adds a vector the previous position of the body.
- Parameters
-
value | A position value to add. |
- Returns
- A pointer to the body itself.
◆ AddPreviousRotation()
QBody* QBody::AddPreviousRotation |
( |
float |
angleRadian | ) |
|
|
inline |
Adds a value to the previous rotation of the body.
- Parameters
-
angleRadian | A value to add, in radians. |
- Returns
- A pointer to the body itself.
◆ AddRotation()
QBody* QBody::AddRotation |
( |
float |
angleRadian, |
|
|
bool |
withPreviousRotation = true |
|
) |
| |
|
inline |
Adds a value to the rotation of the body.
- Parameters
-
angleRadian | A value to add, in radians. |
withPreviousRotation | Determines whether apply the rotation to the previous rotation of the body.In this simulation, since velocities are implicit, if the previous rotation are the same as the newly set rotation, the angular velocity of the body will also be zeroed.Therefore, if you want to zero out the angular velocity when setting the new rotation, use this option. |
- Returns
- A pointer to the body itself.
◆ GetAABB()
QAABB QBody::GetAABB |
( |
| ) |
const |
|
inline |
Returns the AABB feature of the body.
◆ GetAirFriction()
float QBody::GetAirFriction |
( |
| ) |
|
|
inline |
Returns the air friction value of the body.
◆ GetBodySpecificTimeScaleEnabled()
bool QBody::GetBodySpecificTimeScaleEnabled |
( |
| ) |
|
|
inline |
Returns whether the body spesific time scale is enabled.
◆ GetBodySpesificTimeScale()
float QBody::GetBodySpesificTimeScale |
( |
| ) |
|
|
inline |
Returns the body spesific time scale
◆ GetBodyType()
BodyTypes QBody::GetBodyType |
( |
| ) |
|
|
inline |
Returns the type of the body.
◆ GetCanSleep()
bool QBody::GetCanSleep |
( |
| ) |
|
|
inline |
Returns whether the body can sleep.
◆ GetCircumference()
float QBody::GetCircumference |
( |
| ) |
|
|
inline |
Returns the circumference of the body.
◆ GetCollidableLayersBit()
int QBody::GetCollidableLayersBit |
( |
| ) |
|
|
inline |
Returns the bit mask that represents the collidable layers in which the body object is present.
◆ GetEnabled()
bool QBody::GetEnabled |
( |
| ) |
|
|
inline |
Returns whether the body is enabled.
◆ GetFriction()
float QBody::GetFriction |
( |
| ) |
|
|
inline |
Returns the friction value of the body.
◆ GetInertia()
float QBody::GetInertia |
( |
| ) |
|
|
inline |
Returns the inertia of the body.
◆ GetIntegratedVelocitiesEnabled()
bool QBody::GetIntegratedVelocitiesEnabled |
( |
| ) |
|
Returns whether the application of gravity and various velocity integrators necessary for the body's movement in the physics world is enabled. It is set to true by default. Typically, it is disabled for specific body objects that require manual control.
◆ GetIsSleeping()
bool QBody::GetIsSleeping |
( |
| ) |
|
|
inline |
Returns whether the body is sleeping.
◆ GetLayersBit()
int QBody::GetLayersBit |
( |
| ) |
|
|
inline |
Returns the bit mask that represents the layers in which the body object is present.
◆ GetMass()
virtual float QBody::GetMass |
( |
| ) |
|
|
inlinevirtual |
Returns the mass value of the body.
Reimplemented in QSoftBody.
◆ GetMeshAt()
QMesh * QBody::GetMeshAt |
( |
int |
index | ) |
|
Returns the mesh of the body with specified index.
- Parameters
-
index | The index of the mesh. |
◆ GetMeshCount()
int QBody::GetMeshCount |
( |
| ) |
|
Returns the count of the meshes of to the body.
◆ GetMeshes()
vector< QMesh * > * QBody::GetMeshes |
( |
| ) |
|
Returns the collection of the meshes of the body.
◆ GetMode()
Returns whether the body is dynamic or static.
◆ GetOverlapWithCollidableLayersBit()
bool QBody::GetOverlapWithCollidableLayersBit |
( |
int |
layersBit | ) |
|
|
inline |
Returns whether a body object can collide with other body objects that have the given layers bit as parameters.
- Parameters
-
layersBit | A bit value representing the layers to check.
|
◆ GetOverlapWithLayersBit()
bool QBody::GetOverlapWithLayersBit |
( |
int |
layersBit | ) |
|
|
inline |
Checks whether a body object overlaps with a given bit value that represents layers. Returns true if the body object is in at least one of the layers represented by the given bit.
- Parameters
-
layersBit | A bit value representing the layers to check.
|
◆ GetPosition()
Returns the position of the body.
◆ GetPreviousPosition()
QVector QBody::GetPreviousPosition |
( |
| ) |
|
|
inline |
Returns the previous position of the body.
◆ GetPreviousRotation()
float QBody::GetPreviousRotation |
( |
| ) |
|
|
inline |
Returns the previous rotation of the body.
◆ GetRestitution()
float QBody::GetRestitution |
( |
| ) |
|
|
inline |
Returns the restitution value of the body.
◆ GetRotation()
float QBody::GetRotation |
( |
| ) |
|
|
inline |
Returns the rotation of the body.
◆ GetRotationDegree()
float QBody::GetRotationDegree |
( |
| ) |
|
|
inline |
Returns the rotation of the body as degree.
◆ GetSimulationModel()
Returns which approach will be used to simulate a body object.
◆ GetStaticFriction()
float QBody::GetStaticFriction |
( |
| ) |
|
|
inline |
Returns the static friction value of the body.
◆ GetTotalArea()
float QBody::GetTotalArea |
( |
| ) |
|
|
inline |
Returns the total area of the body.
◆ GetTotalInitialArea()
float QBody::GetTotalInitialArea |
( |
| ) |
|
|
inline |
Returns the total initial area of the body. Initial area means the calculated total area with non-transformed meshes of the body.
◆ GetTotalPolygonsArea()
float QBody::GetTotalPolygonsArea |
( |
| ) |
|
|
inline |
Returns the total area of the polygons of the body.
◆ GetTotalPolygonsInitialArea()
float QBody::GetTotalPolygonsInitialArea |
( |
| ) |
|
|
inline |
Returns the total initial area of the polygons of the body. Initial area means the calculated total area with non-transformed meshes of the body.
◆ GetVelocityLimit()
float QBody::GetVelocityLimit |
( |
| ) |
|
Returns the velocity limit of the physics body. If set to 0, no velocity limit is applied. The default value is 0.
◆ GetWorld()
◆ OnCollision()
The event is triggered when a body object collides with another body object during a physics step.
- Parameters
-
- Returns
- If the event method returns true, collision responses are applied. If it returns false, collision responses are not applied.
◆ OnPreStep()
virtual void QBody::OnPreStep |
( |
| ) |
|
|
inlinevirtual |
The event is triggered at the beginning of a physics step, before any collision or constraint operations have been applied to body objects. It is a good time to perform instantaneous operations that will manipulate the presence of a body object in the world.
◆ OnStep()
virtual void QBody::OnStep |
( |
| ) |
|
|
inlinevirtual |
The event is triggered after collision and constraint operations are applied in a physics step. It is a good time to perform operations that are not instantaneous but rather intended to be applied in the next physics step on body objects.
◆ PostUpdate()
virtual void QBody::PostUpdate |
( |
| ) |
|
|
inlineprotectedvirtual |
◆ RemoveMeshAt()
QBody * QBody::RemoveMeshAt |
( |
int |
index | ) |
|
Removes a mesh from the body.
- Parameters
-
index | The index of the mesh to remove. |
- Returns
- A pointer to the body itself.
◆ SetAirFriction()
QBody* QBody::SetAirFriction |
( |
float |
value | ) |
|
|
inline |
Sets the air friction value of the body.
- Parameters
-
- Returns
- A pointer to the body itself.
◆ SetBodySpecificTimeScale()
QBody* QBody::SetBodySpecificTimeScale |
( |
float |
value | ) |
|
|
inline |
Sets the time scale specific to the body. The world has a time scale, but this allows you to assign a specific time scale to the body object as an exception.
- Parameters
-
- Returns
- A pointer to the body itself.
◆ SetBodySpecificTimeScaleEnabled()
QBody* QBody::SetBodySpecificTimeScaleEnabled |
( |
bool |
value | ) |
|
|
inline |
Sets whether the body-specific time scale is enabled. The world has a time scale, but this allows you to assign a specific time scale to the body object as an exception.
- Parameters
-
- Returns
- A pointer to the body itself.
◆ SetCanSleep()
QBody* QBody::SetCanSleep |
( |
bool |
value | ) |
|
|
inline |
Sets whether the body can sleep in the active sleep mode.
- Parameters
-
- Returns
- A pointer to the body itself.
◆ SetCollidableLayersBit()
QBody* QBody::SetCollidableLayersBit |
( |
int |
value | ) |
|
|
inline |
Sets the bit mask that represents the collidable layers in which the body object is present.A body object can collide with other body objects present in the layers defined by the user.
- Parameters
-
value | A bit mask value to set. |
- Returns
- A pointer to the body itself.
◆ SetEnabled()
QBody* QBody::SetEnabled |
( |
bool |
value | ) |
|
|
inline |
Sets whether the body is enabled.
- Parameters
-
- Returns
- A pointer to the body itself.
◆ SetFriction()
QBody* QBody::SetFriction |
( |
float |
value | ) |
|
|
inline |
Sets the friction value of the body.
- Parameters
-
- Returns
- A pointer to the body itself.
◆ SetIntegratedVelocitiesEnabled()
QBody * QBody::SetIntegratedVelocitiesEnabled |
( |
bool |
value | ) |
|
Sets whether the application of gravity and various velocity integrators necessary for the body's movement in the physics world is enabled. It is set to true by default. Typically, it is disabled for specific body objects that require manual control.
◆ SetLayersBit()
QBody* QBody::SetLayersBit |
( |
int |
value | ) |
|
|
inline |
Sets the bit mask that represents the layers in which the body object is present.
- Parameters
-
value | A bit mask value to set. |
- Returns
- A pointer to the body itself.
◆ SetMass()
QBody* QBody::SetMass |
( |
float |
value | ) |
|
|
inline |
Sets the mass value of the body.
- Parameters
-
- Returns
- A pointer to the body itself.
◆ SetMode()
Sets whether the body is dynamic or static.
- Parameters
-
- Returns
- A pointer to the body itself.
◆ SetPosition()
QBody* QBody::SetPosition |
( |
QVector |
value, |
|
|
bool |
withPreviousPosition = true |
|
) |
| |
|
inline |
Sets the position of the body.
- Parameters
-
value | A position value to set. |
withPreviousPosition | Determines whether apply the position to the previous position of the body.In this simulation, since velocities are implicit, if the previous position 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. |
- Returns
- A pointer to the body itself.
◆ SetPreviousPosition()
Sets the previous position of the body.
- Parameters
-
value | A position value to set. |
- Returns
- A pointer to the body itself.
◆ SetPreviousRotation()
QBody* QBody::SetPreviousRotation |
( |
float |
angleRadian | ) |
|
|
inline |
Sets the previous rotation of the body.
- Parameters
-
angleRadian | A rotation value to set, in radians. |
- Returns
- A pointer to the body itself.
◆ SetRestitution()
QBody* QBody::SetRestitution |
( |
float |
value | ) |
|
|
inline |
Sets the restitution value of the body.
- Parameters
-
- Returns
- A pointer to the body itself.
◆ SetRotation()
QBody* QBody::SetRotation |
( |
float |
angleRadian, |
|
|
bool |
withPreviousRotation = true |
|
) |
| |
|
inline |
Sets the rotation of the body.
- Parameters
-
angleRadian | A rotation value to set, in radians. |
withPreviousRotation | Determines whether apply the rotation to the previous rotation of the body.In this simulation, since velocities are implicit, if the previous rotation are the same as the newly set rotation, the angular velocity of the body will also be zeroed.Therefore, if you want to zero out the angular velocity when setting the new rotation, use this option. |
- Returns
- A pointer to the body itself.
◆ SetRotationDegree()
QBody* QBody::SetRotationDegree |
( |
float |
degree, |
|
|
bool |
withPreviousRotation = true |
|
) |
| |
|
inline |
Sets the rotation of the body with specified angle in degrees.
- Parameters
-
degree | A rotation value to set, in degrees. |
withPreviousRotation | Determines whether apply the rotation to the previous rotation of the body.In this simulation, since velocities are implicit, if the previous rotation are the same as the newly set rotation, the angular velocity of the body will also be zeroed.Therefore, if you want to zero out the angular velocity when setting the new rotation, use this option. |
- Returns
- A pointer to the body itself.
◆ SetSimulationModel()
Sets which approach will be used to simulate a body object.
- Parameters
-
bodyMode | A simulation model to set. |
- Returns
- A pointer to the body itself.
◆ SetStaticFriction()
QBody* QBody::SetStaticFriction |
( |
float |
value | ) |
|
|
inline |
Sets the static friction value of the body.
- Parameters
-
- Returns
- A pointer to the body itself.
◆ SetVelocityLimit()
QBody * QBody::SetVelocityLimit |
( |
float |
value | ) |
|
Limits the velocity of the physics body. If set to 0, no velocity limit is applied. The default value is 0.
- Returns
- A pointer to the body itself.
◆ Update()
virtual void QBody::Update |
( |
| ) |
|
|
inlineprotectedvirtual |
Updates properties of the soft body and applies needed physical dynamics.
Reimplemented in QSoftBody, and QRigidBody.
◆ WakeUp()
Wakes up a body that is in a sleeping state.
- Returns
- A pointer to the body itself.
◆ CollisionEventListener
This is the event listener callback function for the OnCollision event.
- Parameters
-
body | The body object that triggers the event. |
CollisionInfo | Contains collision informations. |
◆ PreStepEventListener
std::function<void(QBody *body)> QBody::PreStepEventListener |
This is the event listener callback function for the OnPreStep event.
- Parameters
-
body | The body object that triggers the event. |
◆ StepEventListener
std::function<void(QBody *body)> QBody::StepEventListener |
This is the event listener callback function for the OnStep event.
- Parameters
-
body | The body object that triggers the event. |
The documentation for this class was generated from the following files:
- QuarkPhysics/qbody.h
- QuarkPhysics/qbody.cpp