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

QPlatformerBody provides a ready-to-use foundation for character physics in platformer games. It includes behaviors such as gravity, walking on slopes, and jumping. Additionally, it offers helper methods and properties for further customization. More...

#include <qplatformerbody.h>

Inheritance diagram for QPlatformerBody:
Collaboration diagram for QPlatformerBody:

Classes

struct  CollisionTestInfo
 

Public Member Functions

QPlatformerBodySetMovingFloorSnapOffset (float value)
 Sets the snap offset for moving floors. More...
 
float GetMovingFloorSnapOffset ()
 Gets the snap offset for moving floors. More...
 
QPlatformerBodySetFloorMaxAngle (float value)
 Sets the maximum angle for the floor. More...
 
float GetFloorMaxAngle ()
 Gets the maximum angle for the floor. More...
 
QPlatformerBodySetFloorMaxAngleDegree (float value)
 Sets the maximum angle for the floor in degrees. More...
 
float GetFloorMaxAngleDegree ()
 Gets the maximum angle for the floor in degrees. More...
 
bool GetIsOnFloor ()
 Checks if the body is currently on the floor. More...
 
bool GetIsOnCeiling ()
 Checks if the body is currently touching the ceiling. More...
 
QPlatformerBodySetGravity (QVector value)
 Sets the gravity vector. More...
 
QVector GetGravity ()
 Gets the gravity vector. More...
 
QPlatformerBodySetGravityMultiplier (float value)
 Sets the gravity multiplier. More...
 
float GetGravityMultiplier ()
 Gets the gravity multiplier. More...
 
QPlatformerBodySetWalkSpeed (float value)
 Sets the walking speed of the body. More...
 
float GetWalkSpeed ()
 Gets the walking speed of the body. More...
 
QPlatformerBodySetWalkAcelerationRate (float value)
 Sets the walking acceleration rate. More...
 
float GetWalkAcelerationRate ()
 Gets the walking acceleration rate. More...
 
QPlatformerBodySetWalkDecelerationRate (float value)
 Sets the walking deceleration rate. More...
 
float GetWalkDecelerationRate ()
 Gets the walking deceleration rate. More...
 
QPlatformerBodyWalk (int side)
 Moves the body in a specified horizontal direction. More...
 
QPlatformerBodySetControllerHorizontalVelocity (QVector value)
 Sets the horizontal velocity controlled by the character physics. More...
 
QVector GetControllerHorizontalVelocity ()
 Gets the horizontal velocity controlled by the character physics. More...
 
QPlatformerBodySetControllerVerticalVelocity (QVector value)
 Sets the vertical velocity controlled by the character physics. More...
 
QVector GetControllerVerticalVelocity ()
 Gets the vertical velocity controlled by the character physics. More...
 
bool GetIsFalling ()
 Checks if the body is falling. More...
 
bool GetIsRising ()
 Checks if the body is rising. More...
 
QPlatformerBodySetJumpDurationFrameCount (int value)
 Sets the duration for a jump in frames. More...
 
int GetJumpDurationFrameCount ()
 Gets the duration for a jump in frames. More...
 
QPlatformerBodySetJumpGravityMultiplier (float value)
 Sets the gravity multiplier during a jump. More...
 
float GetJumpGravityMultiplier ()
 Gets the gravity multiplier during a jump. More...
 
QPlatformerBodySetJumpFallGravityMultiplier (float value)
 Sets the gravity multiplier for the falling phase of a jump. More...
 
float GetJumpFallGravityMultiplier ()
 Gets the gravity multiplier for the falling phase of a jump. More...
 
QPlatformerBodySetMaxJumpCount (int value)
 Sets the maximum number of jumps allowed. More...
 
int GetMaxJumpCount ()
 Gets the maximum number of jumps allowed. More...
 
QPlatformerBodyJump (float force, bool unconditional=false)
 Initiates a jump with the specified force. More...
 
QPlatformerBodyReleaseJump ()
 Releases the jump phase. More...
 
bool GetIsJumping ()
 Checks if the body is currently jumping. More...
 
bool GetIsJumpReleased ()
 Checks if the jump phase has been released. More...
 
QPlatformerBodySetSpecificPlatformLayers (int layersBit)
 Sets specific platform layers bit. This determines which platform layers the platformer physics will apply to, such as sloped surfaces, ceilings, walls, etc. The default value is 0, which disables this functionality. More...
 
int GetSpecificPlatformLayers ()
 Gets specific platform layers bit. This determines which platform layers the platformer physics will apply to, such as sloped surfaces, ceilings, walls, etc. The default value is 0, which disables this functionality. More...
 
QPlatformerBody::CollisionTestInfo GetPlatformCollisions (QVector testPosition, QVector nearestOnAxis=QVector::Zero())
 Performs a platform collision test. More...
 
QPlatformerBody::CollisionTestInfo GetRightWall (float offset)
 Checks for a collision with a wall on the right. More...
 
QPlatformerBody::CollisionTestInfo GetLeftWall (float offset)
 Checks for a collision with a wall on the left. More...
 
QPlatformerBody::CollisionTestInfo GetFloor (float offset)
 Checks for a collision with the floor. More...
 
QPlatformerBody::CollisionTestInfo GetCeiling (float offset)
 Checks for a collision with the ceiling. More...
 
- Public Member Functions inherited from QRigidBody
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 ()
 
- 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 Member Functions

virtual void PostUpdate ()
 
- Protected Member Functions inherited from QBody
void UpdateAABB ()
 
void UpdateMeshTransforms ()
 
virtual bool CanGiveCollisionResponseTo (QBody *otherBody)
 

Protected Attributes

bool onFloor =false
 
bool onCeiling =false
 
int platformLayersBit =0
 
float maxFloorAngle =M_PI*0.25
 
float movingFloorSnapOffset =10.0f
 
QRigidBodylastMovableFloor =nullptr
 
QVector gravity =QVector(0,0.3)
 
float gravityMultiplier =1.0f
 
QVector velocity =QVector::Zero()
 
QVector upDirection =QVector::Up()
 
QVector rightDirection =QVector::Right()
 
float walkSpeed =3.0
 
QVector horizontalVelocity =QVector::Zero()
 
QVector verticalVelocity =QVector::Zero()
 
bool isFalling =false
 
bool isRising =false
 
int walkSide =0
 
float walkAccelerationRate =0.1f
 
float walkDecelerationRate =0.1f
 
bool prevJumpMode =false
 
bool jumpMode =false
 
float jumpForce =5.0f
 
int maxJumpCount =2
 
int currentJumpCount =0
 
int jumpDurationFrameCount =30
 
int jumpFrameCountDown =0
 
float jumpGravityMultiplier =0.4f
 
float jumpFallGravityMultiplier =1.0f
 
bool jumpReleased =true
 
- Protected Attributes inherited from QRigidBody
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
 
- 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

QPlatformerBody provides a ready-to-use foundation for character physics in platformer games. It includes behaviors such as gravity, walking on slopes, and jumping. Additionally, it offers helper methods and properties for further customization.

Member Function Documentation

◆ GetCeiling()

QPlatformerBody::CollisionTestInfo QPlatformerBody::GetCeiling ( float  offset)

Checks for a collision with the ceiling.

Parameters
offsetThe offset to apply during the check.
Returns
A CollisionTestInfo structure with the collision details.

◆ GetControllerHorizontalVelocity()

QVector QPlatformerBody::GetControllerHorizontalVelocity ( )

Gets the horizontal velocity controlled by the character physics.

Returns
The horizontal velocity vector.

◆ GetControllerVerticalVelocity()

QVector QPlatformerBody::GetControllerVerticalVelocity ( )

Gets the vertical velocity controlled by the character physics.

Returns
The vertical velocity vector.

◆ GetFloor()

QPlatformerBody::CollisionTestInfo QPlatformerBody::GetFloor ( float  offset)

Checks for a collision with the floor.

Parameters
offsetThe offset to apply during the check.
Returns
A CollisionTestInfo structure with the collision details.

◆ GetFloorMaxAngle()

float QPlatformerBody::GetFloorMaxAngle ( )

Gets the maximum angle for the floor.

Returns
The maximum angle in radians.

◆ GetFloorMaxAngleDegree()

float QPlatformerBody::GetFloorMaxAngleDegree ( )

Gets the maximum angle for the floor in degrees.

Returns
The maximum angle in degrees.

◆ GetGravity()

QVector QPlatformerBody::GetGravity ( )

Gets the gravity vector.

Returns
The gravity vector.

◆ GetGravityMultiplier()

float QPlatformerBody::GetGravityMultiplier ( )

Gets the gravity multiplier.

Returns
The gravity multiplier.

◆ GetIsFalling()

bool QPlatformerBody::GetIsFalling ( )

Checks if the body is falling.

Returns
True if the body is falling, false otherwise.

◆ GetIsJumping()

bool QPlatformerBody::GetIsJumping ( )

Checks if the body is currently jumping.

Returns
True if the body is jumping, false otherwise.

◆ GetIsJumpReleased()

bool QPlatformerBody::GetIsJumpReleased ( )

Checks if the jump phase has been released.

Returns
True if the jump phase is released, false otherwise.

◆ GetIsOnCeiling()

bool QPlatformerBody::GetIsOnCeiling ( )

Checks if the body is currently touching the ceiling.

Returns
True if the body is on the ceiling, false otherwise.

◆ GetIsOnFloor()

bool QPlatformerBody::GetIsOnFloor ( )

Checks if the body is currently on the floor.

Returns
True if the body is on the floor, false otherwise.

◆ GetIsRising()

bool QPlatformerBody::GetIsRising ( )

Checks if the body is rising.

Returns
True if the body is rising, false otherwise.

◆ GetJumpDurationFrameCount()

int QPlatformerBody::GetJumpDurationFrameCount ( )

Gets the duration for a jump in frames.

Returns
The jump duration in frames.

◆ GetJumpFallGravityMultiplier()

float QPlatformerBody::GetJumpFallGravityMultiplier ( )

Gets the gravity multiplier for the falling phase of a jump.

Returns
The gravity multiplier.

◆ GetJumpGravityMultiplier()

float QPlatformerBody::GetJumpGravityMultiplier ( )

Gets the gravity multiplier during a jump.

Returns
The gravity multiplier.

◆ GetLeftWall()

QPlatformerBody::CollisionTestInfo QPlatformerBody::GetLeftWall ( float  offset)

Checks for a collision with a wall on the left.

Parameters
offsetThe offset to apply during the check.
Returns
A CollisionTestInfo structure with the collision details.

◆ GetMaxJumpCount()

int QPlatformerBody::GetMaxJumpCount ( )

Gets the maximum number of jumps allowed.

Returns
The maximum jump count.

◆ GetMovingFloorSnapOffset()

float QPlatformerBody::GetMovingFloorSnapOffset ( )

Gets the snap offset for moving floors.

Returns
The snap offset value.

◆ GetPlatformCollisions()

QPlatformerBody::CollisionTestInfo QPlatformerBody::GetPlatformCollisions ( QVector  testPosition,
QVector  nearestOnAxis = QVector::Zero() 
)

Performs a platform collision test.

Parameters
testPositionThe position to test for collisions.
nearestOnAxisThe axis for prioritizing the nearest collision.
Returns
A CollisionTestInfo structure with the collision details.

◆ GetRightWall()

QPlatformerBody::CollisionTestInfo QPlatformerBody::GetRightWall ( float  offset)

Checks for a collision with a wall on the right.

Parameters
offsetThe offset to apply during the check.
Returns
A CollisionTestInfo structure with the collision details.

◆ GetSpecificPlatformLayers()

int QPlatformerBody::GetSpecificPlatformLayers ( )

Gets specific platform layers bit. This determines which platform layers the platformer physics will apply to, such as sloped surfaces, ceilings, walls, etc. The default value is 0, which disables this functionality.

Note
The object can still interact with objects in the physics world that are set to the layers specified for collision, but platformer-specific behavior (like gravity and movement on slopes) will be applied only to the specified platform layers.
Returns
The bitmask representing the platform layers.

◆ GetWalkAcelerationRate()

float QPlatformerBody::GetWalkAcelerationRate ( )

Gets the walking acceleration rate.

Returns
The acceleration rate.

◆ GetWalkDecelerationRate()

float QPlatformerBody::GetWalkDecelerationRate ( )

Gets the walking deceleration rate.

Returns
The deceleration rate.

◆ GetWalkSpeed()

float QPlatformerBody::GetWalkSpeed ( )

Gets the walking speed of the body.

Returns
The walking speed

◆ Jump()

QPlatformerBody * QPlatformerBody::Jump ( float  force,
bool  unconditional = false 
)

Initiates a jump with the specified force.

Parameters
forceThe force of the jump.
unconditionalIf true, the jump will execute regardless of current conditions.
Returns
A pointer to the body itself.

◆ PostUpdate()

void QPlatformerBody::PostUpdate ( )
protectedvirtual

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

Reimplemented from QRigidBody.

◆ ReleaseJump()

QPlatformerBody * QPlatformerBody::ReleaseJump ( )

Releases the jump phase.

Returns
A pointer to the body itself.

◆ SetControllerHorizontalVelocity()

QPlatformerBody * QPlatformerBody::SetControllerHorizontalVelocity ( QVector  value)

Sets the horizontal velocity controlled by the character physics.

Parameters
valueThe horizontal velocity vector.
Returns
A pointer to the body itself.

◆ SetControllerVerticalVelocity()

QPlatformerBody * QPlatformerBody::SetControllerVerticalVelocity ( QVector  value)

Sets the vertical velocity controlled by the character physics.

Parameters
valueThe vertical velocity vector.
Returns
A pointer to the body itself.

◆ SetFloorMaxAngle()

QPlatformerBody * QPlatformerBody::SetFloorMaxAngle ( float  value)

Sets the maximum angle for the floor.

Parameters
valueThe maximum angle in radians.
Returns
A pointer to the body itself.

◆ SetFloorMaxAngleDegree()

QPlatformerBody * QPlatformerBody::SetFloorMaxAngleDegree ( float  value)

Sets the maximum angle for the floor in degrees.

Parameters
valueThe maximum angle in degrees.
Returns
A pointer to the body itself.

◆ SetGravity()

QPlatformerBody * QPlatformerBody::SetGravity ( QVector  value)

Sets the gravity vector.

Parameters
valueThe gravity vector.
Returns
A pointer to the body itself.

◆ SetGravityMultiplier()

QPlatformerBody * QPlatformerBody::SetGravityMultiplier ( float  value)

Sets the gravity multiplier.

Parameters
valueThe gravity multiplier.
Returns
A pointer to the body itself.

◆ SetJumpDurationFrameCount()

QPlatformerBody * QPlatformerBody::SetJumpDurationFrameCount ( int  value)

Sets the duration for a jump in frames.

Parameters
valueThe jump duration in frames.
Returns
A pointer to the body itself.

◆ SetJumpFallGravityMultiplier()

QPlatformerBody * QPlatformerBody::SetJumpFallGravityMultiplier ( float  value)

Sets the gravity multiplier for the falling phase of a jump.

Parameters
valueThe gravity multiplier.
Returns
A pointer to the body itself.

◆ SetJumpGravityMultiplier()

QPlatformerBody * QPlatformerBody::SetJumpGravityMultiplier ( float  value)

Sets the gravity multiplier during a jump.

Parameters
valueThe gravity multiplier.
Returns
A pointer to the body itself.

◆ SetMaxJumpCount()

QPlatformerBody * QPlatformerBody::SetMaxJumpCount ( int  value)

Sets the maximum number of jumps allowed.

Parameters
valueThe maximum jump count.
Returns
A pointer to the body itself.

◆ SetMovingFloorSnapOffset()

QPlatformerBody * QPlatformerBody::SetMovingFloorSnapOffset ( float  value)

Sets the snap offset for moving floors.

Parameters
valueThe snap offset value.
Returns
A pointer to the body itself.

◆ SetSpecificPlatformLayers()

QPlatformerBody * QPlatformerBody::SetSpecificPlatformLayers ( int  layersBit)

Sets specific platform layers bit. This determines which platform layers the platformer physics will apply to, such as sloped surfaces, ceilings, walls, etc. The default value is 0, which disables this functionality.

Note
The object can still interact with objects in the physics world that are set to the layers specified for collision, but platformer-specific behavior (like gravity and movement on slopes) will be applied only to the specified platform layers.
Parameters
layersBitThe bitmask representing the platform layers.
Returns
A pointer to the body itself.

◆ SetWalkAcelerationRate()

QPlatformerBody * QPlatformerBody::SetWalkAcelerationRate ( float  value)

Sets the walking acceleration rate.

Parameters
valueThe acceleration rate.
Returns
A pointer to the body itself.

◆ SetWalkDecelerationRate()

QPlatformerBody * QPlatformerBody::SetWalkDecelerationRate ( float  value)

Sets the walking deceleration rate.

Parameters
valueThe deceleration rate.
Returns
A pointer to the body itself.

◆ SetWalkSpeed()

QPlatformerBody * QPlatformerBody::SetWalkSpeed ( float  value)

Sets the walking speed of the body.

Parameters
valueThe walking speed.
Returns
A pointer to the body itself.

◆ Walk()

QPlatformerBody * QPlatformerBody::Walk ( int  side)

Moves the body in a specified horizontal direction.

Parameters
sideThe direction (-1 for left, 1 for right, 0 for no movement).
Returns
A pointer to the body itself.

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