|
Capycore Engine
0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
|
Represents the physics world using Box2D. More...
#include <physics_world.h>
Public Member Functions | |
| PhysicsWorld () | |
| Constructs a new physics world. | |
| PhysicsWorld (const PhysicsWorld &)=delete | |
| PhysicsWorld & | operator= (const PhysicsWorld &)=delete |
| PhysicsWorld (PhysicsWorld &&)=delete | |
| PhysicsWorld & | operator= (PhysicsWorld &&)=delete |
| ~PhysicsWorld () | |
| void | step (float dt) |
| Steps the physics simulation forward by the fixed time step. | |
| void | check_collision (const std::vector< std::reference_wrapper< GameObject > > &objects) |
| Checks for collisions in the physics world. | |
| std::optional< std::reference_wrapper< Collider2D > > | find_collider_in_objects (const std::vector< std::reference_wrapper< GameObject > > &objects, Component *comp, b2ShapeId shape_id) |
| Finds a collider in the given objects based on the component and shape ID. | |
| void | check_contact_touch_begin_events (const std::vector< std::reference_wrapper< GameObject > > &objects) |
| Checks for the beginning of contact touch events. | |
| void | check_contact_touch_end_events (const std::vector< std::reference_wrapper< GameObject > > &objects) |
| Checks for the ending of contact touch events. | |
| void | check_sensor_touch_begin_events (const std::vector< std::reference_wrapper< GameObject > > &objects) |
| Checks for the beginning of sensor touch events. | |
| void | check_sensor_touch_end_events (const std::vector< std::reference_wrapper< GameObject > > &objects) |
| Checks for the ending of sensor touch events. | |
| void | execute_valid_collider (const std::vector< std::reference_wrapper< GameObject > > &objects, b2ShapeId a, b2ShapeId b, const std::function< void(Collider2D &, Collider2D &)> &callback) |
| Executes a callback if the given shape IDs are valid. | |
| b2WorldId | world_id () const noexcept |
| int32_t | velocity_iterations () const noexcept |
| int32_t | velocity_iterations (int32_t iterations) noexcept |
| float | gravity_x () const noexcept |
| float | gravity_x (float gx) noexcept |
| float | gravity_y () const noexcept |
| float | gravity_y (float gy) noexcept |
| bool | world_exists () const noexcept |
Static Public Member Functions | |
| static BodyDistance2D | distance (const Body2DTransform &a, const Body2DTransform &b) |
| Calculate the distance between two bodies. | |
| static BodyDistance2D | fixture_distance (const Body2DTransform &a, const Body2DTransform &b) |
| Calculate the distance between two bodies using their fixtures. | |
Static Public Attributes | |
| static constexpr float | pixels_per_meters = 16.0f |
| static constexpr float | meters_per_pixels = 1.0f / pixels_per_meters |
Represents the physics world using Box2D.
This class encapsulates a Box2D world instance and provides settings such as gravity, time step, and conversion ratios.
| PhysicsWorld::PhysicsWorld | ( | ) |
Constructs a new physics world.
|
delete |
|
delete |
| PhysicsWorld::~PhysicsWorld | ( | ) |
| void PhysicsWorld::check_collision | ( | const std::vector< std::reference_wrapper< GameObject > > & | objects | ) |
Checks for collisions in the physics world.
This method processes collision detection and resolution for the current state of the physics world. Its based on Box2D's internal collision handling and objects
| void PhysicsWorld::check_contact_touch_begin_events | ( | const std::vector< std::reference_wrapper< GameObject > > & | objects | ) |
Checks for the beginning of contact touch events.
| void PhysicsWorld::check_contact_touch_end_events | ( | const std::vector< std::reference_wrapper< GameObject > > & | objects | ) |
Checks for the ending of contact touch events.
| void PhysicsWorld::check_sensor_touch_begin_events | ( | const std::vector< std::reference_wrapper< GameObject > > & | objects | ) |
Checks for the beginning of sensor touch events.
| void PhysicsWorld::check_sensor_touch_end_events | ( | const std::vector< std::reference_wrapper< GameObject > > & | objects | ) |
Checks for the ending of sensor touch events.
|
static |
Calculate the distance between two bodies.
| a | The first body's transform. |
| b | The second body's transform. |
| void PhysicsWorld::execute_valid_collider | ( | const std::vector< std::reference_wrapper< GameObject > > & | objects, |
| b2ShapeId | a, | ||
| b2ShapeId | b, | ||
| const std::function< void(Collider2D &, Collider2D &)> & | callback | ||
| ) |
Executes a callback if the given shape IDs are valid.
| std::optional< std::reference_wrapper< Collider2D > > PhysicsWorld::find_collider_in_objects | ( | const std::vector< std::reference_wrapper< GameObject > > & | objects, |
| Component * | comp, | ||
| b2ShapeId | shape_id | ||
| ) |
Finds a collider in the given objects based on the component and shape ID.
|
static |
Calculate the distance between two bodies using their fixtures.
Fixture means the actual shapes attached to the bodies. So for instance a box body with multiple box fixtures will calculate the distance based on the closest fixture.
| a | The first body's transform. |
| b | The second body's transform. |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
delete |
|
delete |
| void PhysicsWorld::step | ( | float | dt | ) |
Steps the physics simulation forward by the fixed time step.
This method advances the physics world by the configured time step, applying velocity and position updates to all bodies in the world.
| dt | The (deltatime) time step duration for the physics update. |
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
staticconstexpr |
|
staticconstexpr |