Quark Physics
1.0
2D Rigid and Soft Body Physics Engine
|
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>
Protected Attributes | |
float | angularForce =0.0f |
QVector | force =QVector::Zero() |
Protected Attributes inherited from QBody | |
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 |
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) |
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.
QRigidBody * QRigidBody::AddAngularForce | ( | float | value | ) |
Adds a value to the angular force of the body.
value | A value to add. |
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.
value | A value to add. |
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.
force | The force to apply. |
r | The relative position to apply force. |
updateMeshTransforms | Determines 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. |
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.
impulse | The impulse to apply. |
r | The relative position to apply impulse. |
|
inline |
Returns the current angular force value of the body.
|
inline |
Returns whether the fixed rotation option is enabled.
|
inline |
Returns the current force value of the body.
|
inline |
Sets whether collisions against other kinematic bodies are enabled.
|
inline |
Returns whether kinematic option is enabled.
|
virtual |
Called after all bodies have completed their Update step to perform post-update operations.
Reimplemented from QBody.
Reimplemented in QPlatformerBody.
QRigidBody * QRigidBody::SetAngularForce | ( | float | value | ) |
Sets the angular force of the body.
value | A value to set. |
|
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.
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.
value | A value to set. |
|
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.
|
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.
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.
value | A position 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 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. |
|
virtual |
Updates properties of the rigid body and applies needed physical dynamics.
Reimplemented from QBody.