2#include <engine/engine_export.h>
8#include <hpp/variant.hpp>
100 hpp::variant<physics_box_shape, physics_sphere_shape, physics_capsule_shape, physics_cylinder_shape, physics_mesh_shape>;
231 auto get_mass()
const noexcept -> float;
250 auto is_dirty(uint8_t
id)
const noexcept -> bool;
257 void set_dirty(uint8_t
id,
bool dirty)
noexcept;
309 auto get_shapes()
const ->
const std::vector<physics_compound_shape>&;
330 const math::vec3& explosion_position,
331 float explosion_radius,
332 float upwards_modifier = 0.0f,
372 void on_change_gravity();
377 void on_change_mass();
382 void on_change_kind();
387 void on_change_shape();
392 void on_change_material();
397 void on_change_sensor();
400 bool is_kinematic_{};
402 bool is_using_gravity_{};
406 bool is_autoscaled_{
true};
415 math::vec3 velocity_{};
418 math::vec3 angular_velocity_{};
421 math::bvec3 freeze_position_xyz_{};
424 math::bvec3 freeze_rotation_xyz_{};
430 std::vector<physics_compound_shape> compound_shape_{};
433 using underlying_t = std::underlying_type_t<physics_property>;
437 std::bitset<8> dirty_;
Base class for materials used in rendering.
Component that handles physics properties and behaviors.
auto get_angular_velocity() const -> const math::vec3 &
void apply_torque(const math::vec3 &torque, force_mode mode=force_mode::force)
Applies a torque impulse to the component.
void set_shape_by_index(size_t index, const physics_compound_shape &shape)
Sets a shape by its index.
void apply_force(const math::vec3 &force, force_mode mode=force_mode::force)
auto get_shapes() const -> const std::vector< physics_compound_shape > &
Gets all shapes.
void set_is_using_gravity(bool use_gravity)
Sets whether the component uses gravity.
auto is_using_gravity() const noexcept -> bool
Checks if the component uses gravity.
void set_dirty(uint8_t id, bool dirty) noexcept
Sets the dirty flag for a specific property.
void set_is_autoscaled(bool autoscaled)
Sets whether to autoscale the physics shape.
void set_collision_include_mask(layer_mask group)
auto is_autoscaled() const noexcept -> bool
Checks if the physics shape is autoscaled.
void apply_explosion_force(float explosion_force, const math::vec3 &explosion_position, float explosion_radius, float upwards_modifier=0.0f, force_mode mode=force_mode::force)
auto get_collision_mask() const -> layer_mask
auto get_mass() const noexcept -> float
Gets the mass of the component.
void set_property_dirty(physics_property prop, bool dirty) noexcept
Sets the dirty flag for a specific physics property.
auto get_collision_include_mask() const -> layer_mask
auto get_freeze_position() const -> const math::bvec3 &
auto are_all_properties_dirty() const noexcept -> bool
Checks if all properties are dirty.
void set_collision_exclude_mask(layer_mask group)
auto get_velocity() const -> const math::vec3 &
void set_freeze_position(const math::bvec3 &xyz)
void set_shapes(const std::vector< physics_compound_shape > &shape)
Sets the shapes.
void set_velocity(const math::vec3 &velocity)
auto are_any_properties_dirty() const noexcept -> bool
Checks if any properties are dirty.
auto get_collision_exclude_mask() const -> layer_mask
void set_material(const asset_handle< physics_material > &material)
Sets the material of the component.
void set_angular_velocity(const math::vec3 &velocity)
static void on_destroy_component(entt::registry &r, entt::entity e)
Called when the component is destroyed.
void clear_kinematic_velocities()
Clears kinematic velocities.
auto get_freeze_rotation() const -> const math::bvec3 &
static void on_create_component(entt::registry &r, entt::entity e)
Called when the component is created.
auto is_kinematic() const noexcept -> bool
Checks if the component is kinematic.
auto is_sensor() const noexcept -> bool
Checks if the component is a sensor.
auto is_property_dirty(physics_property prop) const noexcept -> bool
Checks if a specific physics property is dirty.
auto get_material() const -> const asset_handle< physics_material > &
Gets the material of the component.
void set_mass(float mass)
Sets the mass of the component.
auto get_shape_by_index(size_t index) const -> const physics_compound_shape &
Gets a shape by its index.
auto get_shapes_count() const -> size_t
Gets the count of shapes.
void set_freeze_rotation(const math::bvec3 &xyz)
void set_is_kinematic(bool kinematic)
Sets whether the component is kinematic.
auto is_dirty(uint8_t id) const noexcept -> bool
Checks if a specific property is dirty.
void set_is_sensor(bool sensor)
Sets whether the component is a sensor.
mesh_collision_type
Specifies the type of mesh collision shape.
@ concave
Concave mesh collision (static only, slower but accurate)
@ convex
Convex mesh collision (can be dynamic, faster)
physics_property
Enum for different physics properties.
Represents a handle to an asset, providing access and management functions.
CRTP (Curiously Recurring Template Pattern) base structure for components.
Represents a box shape for physics calculations.
friend auto operator==(const physics_box_shape &lhs, const physics_box_shape &rhs) -> bool=default
math::vec3 extends
Extents of the box.
math::vec3 center
Center of the box.
Represents a capsule shape for physics calculations.
friend auto operator==(const physics_capsule_shape &lhs, const physics_capsule_shape &rhs) -> bool=default
float length
Length of the capsule.
math::vec3 center
Center of the capsule.
float radius
Radius of the capsule.
Represents a compound shape that can contain multiple types of shapes.
shape_t shape
The shape contained in the compound shape.
hpp::variant< physics_box_shape, physics_sphere_shape, physics_capsule_shape, physics_cylinder_shape, physics_mesh_shape > shape_t
friend auto operator==(const physics_compound_shape &lhs, const physics_compound_shape &rhs) -> bool=default
Represents a cylinder shape for physics calculations.
friend auto operator==(const physics_cylinder_shape &lhs, const physics_cylinder_shape &rhs) -> bool=default
float length
Length of the cylinder.
math::vec3 center
Center of the cylinder.
float radius
Radius of the cylinder.
Represents a mesh shape for physics calculations.
math::vec3 center
Center offset of the mesh.
friend auto operator==(const physics_mesh_shape &lhs, const physics_mesh_shape &rhs) -> bool=default
mesh_collision_type collision_type
Type of collision shape.
asset_handle< mesh > mesh_asset
Reference to the mesh asset.
Represents a sphere shape for physics calculations.
float radius
Radius of the sphere.
friend auto operator==(const physics_sphere_shape &lhs, const physics_sphere_shape &rhs) -> bool=default
math::vec3 center
Center of the sphere.