Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
Rigidbody2D Class Reference

A 2D rigidbody component that adds physics properties to a GameObject. More...

#include <rigidbody_2d.h>

Inheritance diagram for Rigidbody2D:
[legend]

Public Member Functions

 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)
 
 ~Rigidbody2D () override
 
void update (float dt) override
 
Rigidbody2Dteleport (const Vector3 &position) noexcept
 
BodyType2D::Type type () const noexcept
 
Rigidbody2Dtype (BodyType2D::Type value) noexcept
 
float mass () const noexcept
 
Rigidbody2Dmass (float value) noexcept
 
bool use_gravity () const noexcept
 
Rigidbody2Duse_gravity (bool value) noexcept
 
float gravity_scale () const noexcept
 
Rigidbody2Dgravity_scale (float value) noexcept
 
Body2D body () const noexcept
 
void body (const Body2D &value) noexcept
 
void apply_force (const Vector3 &force) noexcept
 Applies a force to the rigidbody.
 
void apply_impulse (const Vector3 &impulse) noexcept
 Applies an impulse to the rigidbody.
 
void velocity (const Vector3 &value) noexcept
 Retrieves the current velocity of the rigidbody.
 
Vector3 velocity () const noexcept
 Retrieves the current velocity of the rigidbody.
 
void mark_network_dirty () noexcept
 
void on_serialize (std::vector< uint8_t > &out) const override
 Serializes the component's state into a byte array.
 
void on_deserialize (const std::vector< uint8_t > &data, size_t &offset) override
 Deserializes the component's state from a byte array.
 
std::string type_name () const override
 Provides a consistent type name for the component.
 
- Public Member Functions inherited from Component
 Component ()
 
virtual ~Component ()=default
 
bool active () const noexcept
 Checks if the component is active.
 
Componentactive (bool value) noexcept
 
bool marked_for_deletion () const noexcept
 Activates the component.
 
Componentmark_for_deletion () noexcept
 
virtual void on_attach ()
 Called when the component is attached to a GameObject.
 
virtual void on_detach ()
 Called when the component is detached from a GameObject.
 
const std::optional< std::reference_wrapper< GameObject > > & parent () const noexcept
 Gets the parent GameObject of this component.
 
std::optional< std::reference_wrapper< GameObject > > & parent () noexcept
 Gets the parent GameObject of this component.
 
Componentparent (GameObject &parent)
 
Componentparent (std::nullopt_t nullopt)
 
size_t add_on_attach (const std::function< void(Component &)> &action)
 Retrieves the type information of the component.
 
void remove_on_attach (size_t index)
 
size_t add_on_detach (const std::function< void(Component &)> &action)
 Adds an action to be performed when the component is attached.
 
void remove_on_detach (size_t index)
 

Detailed Description

A 2D rigidbody component that adds physics properties to a GameObject.

This component allows a GameObject to interact with the physics engine, enabling features such as gravity, collisions, and movement based on physical forces.

Usage:

Constructor & Destructor Documentation

◆ Rigidbody2D()

Rigidbody2D::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 
)

◆ ~Rigidbody2D()

Rigidbody2D::~Rigidbody2D ( )
override

Member Function Documentation

◆ apply_force()

void Rigidbody2D::apply_force ( const Vector3 force)
noexcept

Applies a force to the rigidbody.

Parameters
forceThe force vector to apply.

◆ apply_impulse()

void Rigidbody2D::apply_impulse ( const Vector3 impulse)
noexcept

Applies an impulse to the rigidbody.

Parameters
impulseThe impulse vector to apply.

◆ body() [1/2]

Body2D Rigidbody2D::body ( ) const
noexcept

◆ body() [2/2]

void Rigidbody2D::body ( const Body2D value)
noexcept

◆ gravity_scale() [1/2]

float Rigidbody2D::gravity_scale ( ) const
noexcept

◆ gravity_scale() [2/2]

Rigidbody2D & Rigidbody2D::gravity_scale ( float  value)
noexcept

◆ mark_network_dirty()

void Rigidbody2D::mark_network_dirty ( )
noexcept

◆ mass() [1/2]

float Rigidbody2D::mass ( ) const
noexcept

◆ mass() [2/2]

Rigidbody2D & Rigidbody2D::mass ( float  value)
noexcept

◆ on_deserialize()

void Rigidbody2D::on_deserialize ( const std::vector< uint8_t > &  ,
size_t &   
)
overridevirtual

Deserializes the component's state from a byte array.

Parameters
dataThe byte array containing the serialized state.
offsetThe current offset in the byte array from which to start reading. This offset will be updated as bytes are read.
Returns
void

Reimplemented from Component.

◆ on_serialize()

void Rigidbody2D::on_serialize ( std::vector< uint8_t > &  ) const
overridevirtual

Serializes the component's state into a byte array.

Parameters
outA vector to which the serialized bytes will be appended.
Returns
A vector of bytes representing the serialized state of the component.

Reimplemented from Component.

◆ teleport()

Rigidbody2D & Rigidbody2D::teleport ( const Vector3 position)
noexcept

◆ type() [1/2]

BodyType2D::Type Rigidbody2D::type ( ) const
noexcept

◆ type() [2/2]

Rigidbody2D & Rigidbody2D::type ( BodyType2D::Type  value)
noexcept

◆ type_name()

std::string Rigidbody2D::type_name ( ) const
overridevirtual

Provides a consistent type name for the component.

Returns
A string representing the type name of the component. @CAUTION: All derived components must implement this method to ensure consistent serialization across different compilers and platforms.

Implements Component.

◆ update()

void Rigidbody2D::update ( float  dt)
overridevirtual

Implements Component.

◆ use_gravity() [1/2]

bool Rigidbody2D::use_gravity ( ) const
noexcept

◆ use_gravity() [2/2]

Rigidbody2D & Rigidbody2D::use_gravity ( bool  value)
noexcept

◆ velocity() [1/2]

Vector3 Rigidbody2D::velocity ( ) const
noexcept

Retrieves the current velocity of the rigidbody.

Returns
Vector3 The current velocity vector.

◆ velocity() [2/2]

void Rigidbody2D::velocity ( const Vector3 value)
noexcept

Retrieves the current velocity of the rigidbody.

Returns
Vector3 The current velocity vector.

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