Unravel Engine C++ Reference
Loading...
Searching...
No Matches
physics_system.h
Go to the documentation of this file.
1#pragma once
2#include <base/basetypes.hpp>
3#include <context/context.hpp>
4
6
7namespace unravel
8{
9
15{
16public:
18
19
25 auto init(rtti::context& ctx) -> bool;
26
32 auto deinit(rtti::context& ctx) -> bool;
33
39 static void on_create_component(entt::registry& r, entt::entity e);
40
46 static void on_destroy_component(entt::registry& r, entt::entity e);
47
49 float explosion_force,
50 const math::vec3& explosion_position,
51 float explosion_radius,
52 float upwards_modifier,
53 force_mode mode);
54
55 static void apply_force(physics_component& comp, const math::vec3& force, force_mode mode);
56
62 static void apply_torque(physics_component& comp, const math::vec3& torque, force_mode mode);
63
69
70 static void on_create_cc_component(entt::registry& r, entt::entity e);
71 static void on_destroy_cc_component(entt::registry& r, entt::entity e);
72
79 static void move_character(character_controller_component& comp, const math::vec3& displacement);
80 static void jump_character(character_controller_component& comp, const math::vec3& direction);
81 static void apply_impulse_character(character_controller_component& comp, const math::vec3& impulse);
82 static void warp_character(character_controller_component& comp, const math::vec3& position);
83 static void set_character_linear_velocity(character_controller_component& comp, const math::vec3& velocity);
84
85 auto ray_cast(const math::vec3& origin,
86 const math::vec3& direction,
87 float max_distance,
88 int layer_mask,
89 bool query_sensors) const -> hpp::optional<raycast_hit>;
90
91 auto ray_cast_all(const math::vec3& origin,
92 const math::vec3& direction,
93 float max_distance,
94 int layer_mask,
96
97 auto sphere_cast(const math::vec3& origin,
98 const math::vec3& direction,
99 float radius,
100 float max_distance,
101 int layer_mask,
102 bool query_sensors) const -> hpp::optional<raycast_hit>;
103
104 auto sphere_cast_all(const math::vec3& origin,
105 const math::vec3& direction,
106 float radius,
107 float max_distance,
108 int layer_mask,
110
111 auto sphere_overlap(const math::vec3& origin, float radius, int layer_mask, bool query_sensors) const
113
114private:
120 void on_frame_update(rtti::context& ctx, delta_t dt);
121
126 void on_play_begin(rtti::context& ctx);
127
132 void on_play_end(rtti::context& ctx);
133
138 void on_pause(rtti::context& ctx);
139
144 void on_resume(rtti::context& ctx);
145
150 void on_skip_next_frame(rtti::context& ctx);
151
152 std::shared_ptr<int> sentinel_ = std::make_shared<int>(0);
153
154 backend_type backend_;
155};
156
157} // namespace unravel
bool query_sensors
Component for character controller physics with sweep-based movement.
Component that handles physics properties and behaviors.
Manages the physics operations using the specified backend.
auto ray_cast(const math::vec3 &origin, const math::vec3 &direction, float max_distance, int layer_mask, bool query_sensors) const -> hpp::optional< raycast_hit >
static void on_destroy_component(entt::registry &r, entt::entity e)
Called when a physics component is destroyed.
static void apply_force(physics_component &comp, const math::vec3 &force, force_mode mode)
static void apply_torque(physics_component &comp, const math::vec3 &torque, force_mode mode)
Applies a torque to the specified physics component.
auto sphere_cast_all(const math::vec3 &origin, const math::vec3 &direction, float radius, float max_distance, int layer_mask, bool query_sensors) const -> physics_vector< raycast_hit >
static void clear_kinematic_velocities(physics_component &comp)
Clears kinematic velocities for the specified physics component.
auto deinit(rtti::context &ctx) -> bool
Deinitializes the physics system with the given context.
static void jump_character(character_controller_component &comp, const math::vec3 &direction)
static void warp_character(character_controller_component &comp, const math::vec3 &position)
auto sphere_overlap(const math::vec3 &origin, float radius, int layer_mask, bool query_sensors) const -> physics_vector< entt::entity >
auto ray_cast_all(const math::vec3 &origin, const math::vec3 &direction, float max_distance, int layer_mask, bool query_sensors) const -> physics_vector< raycast_hit >
static void apply_impulse_character(character_controller_component &comp, const math::vec3 &impulse)
static void move_character(character_controller_component &comp, const math::vec3 &displacement)
Moves a character controller by a displacement.
auto init(rtti::context &ctx) -> bool
Initializes the physics system with the given context.
static void on_create_component(entt::registry &r, entt::entity e)
Called when a physics component is created.
static void set_character_linear_velocity(character_controller_component &comp, const math::vec3 &velocity)
static void on_create_cc_component(entt::registry &r, entt::entity e)
auto sphere_cast(const math::vec3 &origin, const math::vec3 &direction, float radius, float max_distance, int layer_mask, bool query_sensors) const -> hpp::optional< raycast_hit >
static void on_destroy_cc_component(entt::registry &r, entt::entity e)
static void apply_explosion_force(physics_component &comp, float explosion_force, const math::vec3 &explosion_position, float explosion_radius, float upwards_modifier, force_mode mode)
std::chrono::duration< float > delta_t
math::vec3 position
Definition defaults.cpp:52
hpp::small_vector< T, SmallSizeCapacity > physics_vector