Skylicht Engine
Loading...
Searching...
No Matches
Skylicht::Physics::CRigidbody Class Reference

Represents a physical rigid body in the physics simulation. More...

#include <RigidBody/CRigidbody.h>

Inheritance diagram for Skylicht::Physics::CRigidbody:
Skylicht::Physics::ICollisionObject Skylicht::CComponentSystem Skylicht::IActivatorObject

Public Types

enum  EActivationState { Activate , Sleep , Alway , Disable }
 Activation states for the rigid body. More...
Public Types inherited from Skylicht::Physics::ICollisionObject
enum  ECollisionType { Unknown , RigidBody , Character }
 Types of collision objects.

Public Member Functions

virtual void initComponent ()
virtual void startComponent ()
virtual void updateComponent ()
virtual CObjectSerializablecreateSerializable ()
virtual void loadSerializable (CObjectSerializable *object)
virtual void setCollisionGroupAndFilter (int group, int filter)
 Sets the collision group and filter mask.
void setTag (int i)
 Sets a custom tag for the rigid body.
int getTag ()
 Gets the custom tag of the rigid body.
void setDynamic (bool b)
 Sets whether the body is dynamic.
bool isDynamic ()
 Checks if the body is dynamic.
void setFriction (float f)
 Sets the friction coefficient.
float getFriction ()
 Gets the friction coefficient.
void setRollingFriction (float f)
 Sets the rolling friction coefficient.
float getRollingFriction ()
 Gets the rolling friction coefficient.
void setSpinningFriction (float f)
 Sets the spinning friction coefficient.
float getSpinningFriction ()
 Gets the spinning friction coefficient.
void setMass (float m)
 Sets the mass of the rigid body.
float getMass ()
 Gets the mass of the rigid body.
void setRestitution (float s)
 Sets the restitution (bounciness) coefficient.
float getRestitution ()
 Gets the restitution coefficient.
void setSleepingThresholds (float linear, float angular)
 Sets the thresholds for linear and angular velocity to enter sleep mode.
void setCcdSweptSphereRadius (float r=0.0f)
 Sets the radius for Continuous Collision Detection (CCD).
void setCcdMotionThreshold (float m=0.0f)
 Sets the motion threshold for Continuous Collision Detection (CCD).
bool initRigidbody ()
 Initializes the rigid body in the physics world.
void releaseRigidbody ()
 Releases the rigid body from the physics world.
void setLocalScale (const core::vector3df &scale)
 Sets the local scale of the collision shape.
core::vector3df getLocalScale ()
 Gets the local scale of the collision shape.
core::vector3df getPosition ()
 Gets the world position of the rigid body.
void setPosition (const core::vector3df &pos)
 Sets the world position of the rigid body.
core::vector3df getRotationEuler ()
 Gets the world rotation as Euler angles.
core::quaternion getRotation ()
 Gets the world rotation as a quaternion.
void setRotation (const core::vector3df &eulerDeg)
 Sets the world rotation using Euler angles.
void setRotation (const core::quaternion &q)
 Sets the world rotation using a quaternion.
void syncTransform ()
 Synchronizes the GameObject's transform with the physics body's transform.
void setState (EActivationState state)
 Sets the activation state of the rigid body.
void activate ()
 Manually activates the rigid body (wakes it up).
EActivationState getState ()
 Gets the current activation state.
const char * getStateName ()
 Gets the name of the current activation state as a string.
void applyCenterForce (const core::vector3df &force)
 Applies a force at the center of mass.
void applyForce (const core::vector3df &force, const core::vector3df &localPosition)
 Applies a force at a specific local position.
void applyTorque (const core::vector3df &torque)
 Applies a torque (rotational force).
void clearForce ()
 Clears all active forces and torques.
void applyCenterImpulse (const core::vector3df &impulse)
 Applies an instantaneous impulse at the center of mass.
void applyImpulse (const core::vector3df &impulse, const core::vector3df &localPosition)
 Applies an instantaneous impulse at a specific local position.
void applyTorqueImpulse (const core::vector3df &torqueImpulse)
 Applies a torque impulse (instantaneous rotation).
void applyCenterPushImpulse (const core::vector3df &impulse)
 Applies a push impulse at the center of mass.
void applyPushImpulse (const core::vector3df &impulse, const core::vector3df &localPosition)
 Applies a push impulse at a specific local position.
void applyTorqueTurnImpulse (const core::vector3df &torqueImpulse)
 Applies a torque turn impulse.
core::vector3df getLinearVelocity ()
 Gets the current linear velocity.
core::vector3df getAngularVelocity ()
 Gets the current angular velocity.
void setLinearVelocity (const core::vector3df &v)
 Sets the linear velocity.
void setAngularVelocity (const core::vector3df &v)
 Sets the angular velocity.
bool needUpdateTransform ()
 Checks if the transform needs updating.
void notifyUpdateTransform (bool b)
 Notifies the component about transform update status.
void setDrawDebug (bool b)
 Enables or disables debug drawing for this specific rigid body.
bool enableDrawDebug ()
 Checks if debug drawing is enabled for this body.
core::matrix4 getWorldTransform ()
 Gets the current world transform matrix.
Public Member Functions inherited from Skylicht::Physics::ICollisionObject
ECollisionType getCollisionType ()
 Gets the collision type.
int getCollisionGroup ()
 Gets the collision group bitmask.
int getCollisionFilter ()
 Gets the collision filter bitmask.
Public Member Functions inherited from Skylicht::CComponentSystem
const char * getName ()
virtual void reset ()
virtual void endUpdate ()
virtual void onEnable (bool b)
virtual void onUpdateCullingLayer (u32 mask)
void setEnable (bool b)
bool isEnable ()
CGameObject * getGameObject ()
void setEnableSerializable (bool b)
bool isSerializable ()
void addLinkComponent (CComponentSystem *comp)
void removeAllLink ()
Public Member Functions inherited from Skylicht::IActivatorObject
virtual ~IActivatorObject ()
 Virtual destructor for polymorphic activator objects.

Protected Attributes

bool m_isDynamic
float m_mass
float m_restitution
float m_friction
float m_rollingFriction
float m_spinningFriction
bool m_needUpdateTransform
bool m_drawDebug
int m_tag
Protected Attributes inherited from Skylicht::Physics::ICollisionObject
ECollisionType m_collisionType
int m_group
int m_filter
Protected Attributes inherited from Skylicht::CComponentSystem
CGameObject * m_gameObject
bool m_enable
bool m_serializable
std::vector< CComponentSystem * > m_linkComponent

Friends

class CPhysicsEngine

Additional Inherited Members

Static Public Member Functions inherited from Skylicht::CComponentSystem
static int useComponent (CComponentSystem *used)
Public Attributes inherited from Skylicht::Physics::ICollisionObject
std::function< void(ICollisionObject *, ICollisionObject *, SCollisionContactPoint *, int)> OnCollision
 Callback function triggered when a collision occurs.
Protected Member Functions inherited from Skylicht::CComponentSystem
void setOwner (CGameObject *obj)

Detailed Description

Represents a physical rigid body in the physics simulation.

A rigid body can be dynamic (affected by forces and gravity) or static/kinematic. It must be attached to a GameObject that also has a CCollider component.

Example: Creating a dynamic box

CGameObject* cubeObj = zone->createEmptyObject();
cubeObj->addComponent<CCube>(); // Visual mesh
// 1. Add collider
cubeObj->addComponent<Physics::CBoxCollider>();
// 2. Add and init Rigidbody
Physics::CRigidbody* body = cubeObj->addComponent<Physics::CRigidbody>();
body->setMass(1.0f);
body->initRigidbody();
// 3. Set initial state
body->setPosition(core::vector3df(0.0f, 10.0f, 0.0f));
body->syncTransform();
Component for rendering cube primitives.
Definition CCube.h:44
A box collision shape.
Definition CBoxCollider.h:44
Represents a physical rigid body in the physics simulation.
Definition CRigidbody.h:77
void setMass(float m)
Sets the mass of the rigid body.

Example: Creating a static/kinematic floor

CGameObject* floorObj = zone->createEmptyObject();
floorObj->addComponent<Physics::CStaticPlaneCollider>();
Physics::CRigidbody* body = floorObj->addComponent<Physics::CRigidbody>();
body->setDynamic(false); // Static
body->initRigidbody();
void setDynamic(bool b)
Sets whether the body is dynamic.
A static infinite plane collision shape.
Definition CStaticPlaneCollider.h:38

Member Function Documentation

◆ applyCenterForce()

void Skylicht::Physics::CRigidbody::applyCenterForce ( const core::vector3df & force)

Applies a force at the center of mass.

Parameters
forceForce vector.

◆ applyCenterImpulse()

void Skylicht::Physics::CRigidbody::applyCenterImpulse ( const core::vector3df & impulse)

Applies an instantaneous impulse at the center of mass.

Parameters
impulseImpulse vector.

◆ applyCenterPushImpulse()

void Skylicht::Physics::CRigidbody::applyCenterPushImpulse ( const core::vector3df & impulse)

Applies a push impulse at the center of mass.

Parameters
impulsePush impulse vector.

◆ applyForce()

void Skylicht::Physics::CRigidbody::applyForce ( const core::vector3df & force,
const core::vector3df & localPosition )

Applies a force at a specific local position.

Parameters
forceForce vector.
localPositionLocal offset from the center of mass.

◆ applyImpulse()

void Skylicht::Physics::CRigidbody::applyImpulse ( const core::vector3df & impulse,
const core::vector3df & localPosition )

Applies an instantaneous impulse at a specific local position.

Parameters
impulseImpulse vector.
localPositionLocal offset from the center of mass.

◆ applyPushImpulse()

void Skylicht::Physics::CRigidbody::applyPushImpulse ( const core::vector3df & impulse,
const core::vector3df & localPosition )

Applies a push impulse at a specific local position.

Parameters
impulsePush impulse vector.
localPositionLocal offset from the center of mass.

◆ applyTorque()

void Skylicht::Physics::CRigidbody::applyTorque ( const core::vector3df & torque)

Applies a torque (rotational force).

Parameters
torqueTorque vector.

◆ applyTorqueImpulse()

void Skylicht::Physics::CRigidbody::applyTorqueImpulse ( const core::vector3df & torqueImpulse)

Applies a torque impulse (instantaneous rotation).

Parameters
torqueImpulseTorque impulse vector.

◆ applyTorqueTurnImpulse()

void Skylicht::Physics::CRigidbody::applyTorqueTurnImpulse ( const core::vector3df & torqueImpulse)

Applies a torque turn impulse.

Parameters
torqueImpulseTorque impulse vector.

◆ createSerializable()

virtual CObjectSerializable * Skylicht::Physics::CRigidbody::createSerializable ( )
virtual

Reimplemented from Skylicht::CComponentSystem.

◆ enableDrawDebug()

bool Skylicht::Physics::CRigidbody::enableDrawDebug ( )
inline

Checks if debug drawing is enabled for this body.

Returns
True if enabled.

◆ getAngularVelocity()

core::vector3df Skylicht::Physics::CRigidbody::getAngularVelocity ( )

Gets the current angular velocity.

Returns
Angular velocity vector.

◆ getFriction()

float Skylicht::Physics::CRigidbody::getFriction ( )
inline

Gets the friction coefficient.

Returns
Friction value.

◆ getLinearVelocity()

core::vector3df Skylicht::Physics::CRigidbody::getLinearVelocity ( )

Gets the current linear velocity.

Returns
Velocity vector.

◆ getLocalScale()

core::vector3df Skylicht::Physics::CRigidbody::getLocalScale ( )

Gets the local scale of the collision shape.

Returns
Scale vector.

◆ getMass()

float Skylicht::Physics::CRigidbody::getMass ( )
inline

Gets the mass of the rigid body.

Returns
Mass value.

◆ getPosition()

core::vector3df Skylicht::Physics::CRigidbody::getPosition ( )

Gets the world position of the rigid body.

Returns
Position vector.

◆ getRestitution()

float Skylicht::Physics::CRigidbody::getRestitution ( )
inline

Gets the restitution coefficient.

Returns
Restitution value.

◆ getRollingFriction()

float Skylicht::Physics::CRigidbody::getRollingFriction ( )
inline

Gets the rolling friction coefficient.

Returns
Rolling friction value.

◆ getRotation()

core::quaternion Skylicht::Physics::CRigidbody::getRotation ( )

Gets the world rotation as a quaternion.

Returns
Rotation quaternion.

◆ getRotationEuler()

core::vector3df Skylicht::Physics::CRigidbody::getRotationEuler ( )

Gets the world rotation as Euler angles.

Returns
Euler angles in degrees.

◆ getSpinningFriction()

float Skylicht::Physics::CRigidbody::getSpinningFriction ( )
inline

Gets the spinning friction coefficient.

Returns
Spinning friction value.

◆ getState()

EActivationState Skylicht::Physics::CRigidbody::getState ( )

Gets the current activation state.

Returns
Current state.

◆ getStateName()

const char * Skylicht::Physics::CRigidbody::getStateName ( )

Gets the name of the current activation state as a string.

Returns
State name string.

◆ getTag()

int Skylicht::Physics::CRigidbody::getTag ( )
inline

Gets the custom tag of the rigid body.

Returns
The tag value.

◆ getWorldTransform()

core::matrix4 Skylicht::Physics::CRigidbody::getWorldTransform ( )

Gets the current world transform matrix.

Returns
4x4 transform matrix.

◆ initComponent()

virtual void Skylicht::Physics::CRigidbody::initComponent ( )
virtual

◆ initRigidbody()

bool Skylicht::Physics::CRigidbody::initRigidbody ( )

Initializes the rigid body in the physics world.

Returns
True if successful, false otherwise.

◆ isDynamic()

bool Skylicht::Physics::CRigidbody::isDynamic ( )
inline

Checks if the body is dynamic.

Returns
True if dynamic, false otherwise.

◆ loadSerializable()

virtual void Skylicht::Physics::CRigidbody::loadSerializable ( CObjectSerializable * object)
virtual

Reimplemented from Skylicht::CComponentSystem.

◆ needUpdateTransform()

bool Skylicht::Physics::CRigidbody::needUpdateTransform ( )
inline

Checks if the transform needs updating.

Returns
True if update is needed.

◆ notifyUpdateTransform()

void Skylicht::Physics::CRigidbody::notifyUpdateTransform ( bool b)
inline

Notifies the component about transform update status.

Parameters
bUpdate status.

◆ setAngularVelocity()

void Skylicht::Physics::CRigidbody::setAngularVelocity ( const core::vector3df & v)

Sets the angular velocity.

Parameters
vAngular velocity vector.

◆ setCcdMotionThreshold()

void Skylicht::Physics::CRigidbody::setCcdMotionThreshold ( float m = 0.0f)

Sets the motion threshold for Continuous Collision Detection (CCD).

Parameters
mMotion threshold value.

◆ setCcdSweptSphereRadius()

void Skylicht::Physics::CRigidbody::setCcdSweptSphereRadius ( float r = 0.0f)

Sets the radius for Continuous Collision Detection (CCD).

Parameters
rRadius value.

◆ setCollisionGroupAndFilter()

virtual void Skylicht::Physics::CRigidbody::setCollisionGroupAndFilter ( int group,
int filter )
virtual

Sets the collision group and filter mask.

Parameters
groupBitmask representing the collision group.
filterBitmask representing which groups this object should collide with.

Reimplemented from Skylicht::Physics::ICollisionObject.

◆ setDrawDebug()

void Skylicht::Physics::CRigidbody::setDrawDebug ( bool b)
inline

Enables or disables debug drawing for this specific rigid body.

Parameters
bTrue to enable, false to disable.

◆ setDynamic()

void Skylicht::Physics::CRigidbody::setDynamic ( bool b)

Sets whether the body is dynamic.

Parameters
bTrue for dynamic, false for static/kinematic.

◆ setFriction()

void Skylicht::Physics::CRigidbody::setFriction ( float f)

Sets the friction coefficient.

Parameters
fFriction value.

◆ setLinearVelocity()

void Skylicht::Physics::CRigidbody::setLinearVelocity ( const core::vector3df & v)

Sets the linear velocity.

Parameters
vVelocity vector.

◆ setLocalScale()

void Skylicht::Physics::CRigidbody::setLocalScale ( const core::vector3df & scale)

Sets the local scale of the collision shape.

Parameters
scaleScale vector.

◆ setMass()

void Skylicht::Physics::CRigidbody::setMass ( float m)

Sets the mass of the rigid body.

Parameters
mMass value.

◆ setPosition()

void Skylicht::Physics::CRigidbody::setPosition ( const core::vector3df & pos)

Sets the world position of the rigid body.

Parameters
posPosition vector.

◆ setRestitution()

void Skylicht::Physics::CRigidbody::setRestitution ( float s)

Sets the restitution (bounciness) coefficient.

Parameters
sRestitution value.

◆ setRollingFriction()

void Skylicht::Physics::CRigidbody::setRollingFriction ( float f)

Sets the rolling friction coefficient.

Parameters
fRolling friction value.

◆ setRotation() [1/2]

void Skylicht::Physics::CRigidbody::setRotation ( const core::quaternion & q)

Sets the world rotation using a quaternion.

Parameters
qRotation quaternion.

◆ setRotation() [2/2]

void Skylicht::Physics::CRigidbody::setRotation ( const core::vector3df & eulerDeg)

Sets the world rotation using Euler angles.

Parameters
eulerDegEuler angles in degrees.

◆ setSleepingThresholds()

void Skylicht::Physics::CRigidbody::setSleepingThresholds ( float linear,
float angular )

Sets the thresholds for linear and angular velocity to enter sleep mode.

Parameters
linearLinear velocity threshold.
angularAngular velocity threshold.

◆ setSpinningFriction()

void Skylicht::Physics::CRigidbody::setSpinningFriction ( float f)

Sets the spinning friction coefficient.

Parameters
fSpinning friction value.

◆ setState()

void Skylicht::Physics::CRigidbody::setState ( EActivationState state)

Sets the activation state of the rigid body.

Parameters
stateNew activation state.

◆ setTag()

void Skylicht::Physics::CRigidbody::setTag ( int i)
inline

Sets a custom tag for the rigid body.

Parameters
iTag value.

◆ startComponent()

virtual void Skylicht::Physics::CRigidbody::startComponent ( )
virtual

Reimplemented from Skylicht::CComponentSystem.

◆ updateComponent()

virtual void Skylicht::Physics::CRigidbody::updateComponent ( )
virtual

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