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

The main physics engine manager. More...

#include <PhysicsEngine/CPhysicsEngine.h>

Public Member Functions

 DECLARE_SINGLETON (CPhysicsEngine)
void initPhysics ()
 Initializes the physics world and configuration.
void exitPhysics ()
 Cleans up and releases physics world resources.
bool isInitialized ()
 Checks if the physics engine has been initialized.
void updatePhysics (float timestepSec, int step=1)
 Steps the physics simulation.
void syncTransformToPhysics ()
 Synchronizes Skylicht transforms to the physics engine.
void debugDrawWorld ()
 Draws the physics world for debugging.
void enableDrawDebug (bool b, bool alwayDraw=false)
 Enables or disables physics debug visualization.
float getGravity ()
 Gets the current gravity value.
void setGravity (float g)
 Sets the gravity on the Y-axis.
void updateAABBs ()
 Updates the Axis-Aligned Bounding Boxes (AABBs) for all objects.
bool rayTest (const core::vector3df &from, const core::vector3df &to, SAllRaycastResult &result)
 Performs a raycast test returning all hits.
bool rayTest (const core::vector3df &from, const core::vector3df &to, SClosestRaycastResult &result)
 Performs a raycast test returning only the closest hit.
core::array< SRigidbodyData * > & getBodies ()
 Gets all registered rigid bodies.
core::array< SCharacterData * > & getCharacters ()
 Gets all registered character controllers.

Public Attributes

bool IsInEditor
 Indicates if the engine is running within the editor.

Protected Attributes

float m_gravity
core::array< SRigidbodyData * > m_bodies
core::array< SCharacterData * > m_characters
bool m_enableDrawDebug

Friends

class CRigidbody
class CCharacterController

Detailed Description

The main physics engine manager.

This singleton class orchestrates the physics simulation, manages collision objects, and provides raycasting utilities. It wraps the Bullet Physics engine.

Example: Initializing the physics engine

// Initialize the physics engine singleton
Physics::CPhysicsEngine::createGetInstance();
// Initialize the physics world (usually in your ViewInit or similar)
Physics::CPhysicsEngine::getInstance()->initPhysics();
// Set gravity
Physics::CPhysicsEngine::getInstance()->setGravity(-9.81f);
// In your update loop
float timestepSec = getTimeStep() / 1000.0f;
Physics::CPhysicsEngine::getInstance()->updatePhysics(timestepSec);
float getTimeStep()
Get the current time step in milliseconds, scaled by the time scale.

Example: Performing a raycast

Physics::CPhysicsEngine* physicsEngine = Physics::CPhysicsEngine::getInstance();
if (physicsEngine->rayTest(from, to, result))
{
if (result.Body)
{
// Hit a rigid body
}
}
The main physics engine manager.
Definition CPhysicsEngine.h:114
bool rayTest(const core::vector3df &from, const core::vector3df &to, SAllRaycastResult &result)
Performs a raycast test returning all hits.
void applyCenterImpulse(const core::vector3df &impulse)
Applies an instantaneous impulse at the center of mass.
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition vector3d.h:445
Result structure for a raycast that returns only the closest hit.
Definition CPhysicsRaycast.h:56
CRigidbody * Body
Closest rigid body hit by the ray.
Definition CPhysicsRaycast.h:58

Member Function Documentation

◆ enableDrawDebug()

void Skylicht::Physics::CPhysicsEngine::enableDrawDebug ( bool b,
bool alwayDraw = false )

Enables or disables physics debug visualization.

Parameters
bTrue to enable, false to disable.
alwayDrawIf true, debug lines are drawn even if objects are inactive.

◆ getBodies()

core::array< SRigidbodyData * > & Skylicht::Physics::CPhysicsEngine::getBodies ( )
inline

Gets all registered rigid bodies.

Returns
Array of rigid body data.

◆ getCharacters()

core::array< SCharacterData * > & Skylicht::Physics::CPhysicsEngine::getCharacters ( )
inline

Gets all registered character controllers.

Returns
Array of character controller data.

◆ getGravity()

float Skylicht::Physics::CPhysicsEngine::getGravity ( )
inline

Gets the current gravity value.

Returns
The gravity on the Y-axis.

◆ isInitialized()

bool Skylicht::Physics::CPhysicsEngine::isInitialized ( )

Checks if the physics engine has been initialized.

Returns
True if initialized, false otherwise.

◆ rayTest() [1/2]

bool Skylicht::Physics::CPhysicsEngine::rayTest ( const core::vector3df & from,
const core::vector3df & to,
SAllRaycastResult & result )

Performs a raycast test returning all hits.

Parameters
fromRay start position.
toRay end position.
resultStructure to store all hit results.
Returns
True if any hits were found.

◆ rayTest() [2/2]

bool Skylicht::Physics::CPhysicsEngine::rayTest ( const core::vector3df & from,
const core::vector3df & to,
SClosestRaycastResult & result )

Performs a raycast test returning only the closest hit.

Parameters
fromRay start position.
toRay end position.
resultStructure to store the closest hit result.
Returns
True if a hit was found.

◆ setGravity()

void Skylicht::Physics::CPhysicsEngine::setGravity ( float g)

Sets the gravity on the Y-axis.

Parameters
gGravity value.

◆ updatePhysics()

void Skylicht::Physics::CPhysicsEngine::updatePhysics ( float timestepSec,
int step = 1 )

Steps the physics simulation.

Parameters
timestepSecTime elapsed since the last frame in seconds.
stepMaximum number of sub-steps (default: 1).

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