Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
rigidbody_2d.h
Go to the documentation of this file.
1#pragma once
2
5
6constexpr float default_rigidbody_mass = 1.0f;
7constexpr bool default_rigidbody_use_gravity = true;
8constexpr float default_rigidbody_gravity_scale = 1.0f;
9
23class Rigidbody2D : public Component {
24 public:
29 ~Rigidbody2D() override;
30
31 void update(float dt) override;
32
33 Rigidbody2D& teleport(const Vector3& position) noexcept;
34
35 [[nodiscard]] BodyType2D::Type type() const noexcept;
36 Rigidbody2D& type(BodyType2D::Type value) noexcept;
37
38 [[nodiscard]] float mass() const noexcept;
39 Rigidbody2D& mass(float value) noexcept;
40
41 [[nodiscard]] bool use_gravity() const noexcept;
42 Rigidbody2D& use_gravity(bool value) noexcept;
43
44 [[nodiscard]] float gravity_scale() const noexcept;
45 Rigidbody2D& gravity_scale(float value) noexcept;
46
47 [[nodiscard]] Body2D body() const noexcept;
48 void body(const Body2D& value) noexcept;
49
54 void apply_force(const Vector3& force) noexcept;
55
60 void apply_impulse(const Vector3& impulse) noexcept;
61
66 void velocity(const Vector3& value) noexcept;
67
72 [[nodiscard]] Vector3 velocity() const noexcept;
73
74 void mark_network_dirty() noexcept;
75
76 void on_serialize(std::vector<uint8_t>& out) const override;
77 void on_deserialize(const std::vector<uint8_t>& data,
78 size_t& offset) override;
79
80 std::string type_name() const override;
81
82 private:
83 Body2D body_{};
84 BodyType2D::Type type_;
85 float mass_;
86
87 bool use_gravity_;
88 float gravity_scale_;
89 bool fresh_spawned_{true};
90};
Base class for all components that can be attached to GameObjects.
Definition component.h:24
A 2D rigidbody component that adds physics properties to a GameObject.
Definition rigidbody_2d.h:23
void on_deserialize(const std::vector< uint8_t > &data, size_t &offset) override
Deserializes the component's state from a byte array.
float mass() const noexcept
void on_serialize(std::vector< uint8_t > &out) const override
Serializes the component's state into a byte array.
void update(float dt) override
bool use_gravity() const noexcept
Rigidbody2D(BodyType2D::Type type=BodyType2D::Dynamic, float mass=default_rigidbody_mass, bool use_gravity=default_rigidbody_use_gravity, float gravity_scale=default_rigidbody_gravity_scale)
void mark_network_dirty() noexcept
~Rigidbody2D() override
Vector3 velocity() const noexcept
Retrieves the current velocity of the rigidbody.
std::string type_name() const override
Provides a consistent type name for the component.
Rigidbody2D & teleport(const Vector3 &position) noexcept
BodyType2D::Type type() const noexcept
void apply_impulse(const Vector3 &impulse) noexcept
Applies an impulse to the rigidbody.
float gravity_scale() const noexcept
void apply_force(const Vector3 &force) noexcept
Applies a force to the rigidbody.
Body2D body() const noexcept
Represents a 3D vector with x, y, and z components. This class provides basic vector operations such ...
Definition vector3.h:8
constexpr bool default_rigidbody_use_gravity
Definition rigidbody_2d.h:7
constexpr float default_rigidbody_gravity_scale
Definition rigidbody_2d.h:8
constexpr float default_rigidbody_mass
Definition rigidbody_2d.h:6
Structure representing a 2D physics body.
Definition body_2d.h:26
Enumeration of 2D body types.
Definition body_type_2d.h:13
Type
Definition body_type_2d.h:14
@ Dynamic
Definition body_type_2d.h:14