Pogosim
Loading...
Searching...
No Matches
PhysicalObject Class Referenceabstract

A physical object, i.e. with physics properties (e.g. collisions) modelled by Box2D. More...

#include <objects.h>

Inheritance diagram for PhysicalObject:
Object PassiveObject PogobotObject ActiveObject PogobjectObject Pogowall MembraneObject

Public Member Functions

 PhysicalObject (uint16_t _id, float _x, float _y, ObjectGeometry &geom, b2WorldId world_id, float _linear_damping=0.0f, float _angular_damping=0.0f, float _density=10.0f, float _friction=0.3f, float _restitution=0.5f, std::string const &_category="objects")
 Constructs a PhysicalObject.
 PhysicalObject (Simulation *simulation, uint16_t _id, float _x, float _y, b2WorldId world_id, Configuration const &config, std::string const &_category="objects")
 Constructs a PhysicalObject from a configuration entry.
virtual void launch_user_step (float t) override
 Launches the user-defined step function. For PhysicalObject, it is also used to compute acceleration statistics.
virtual b2Vec2 get_position () const
 Retrieves the object's current position.
float get_angle () const
 Retrieves the object's current orientation angle.
float get_angular_velocity () const
 Retrieves the object's current angular velocity.
b2Vec2 get_linear_acceleration () const
 Retrieves the object's current angular velocity.
virtual void render (SDL_Renderer *renderer, b2WorldId world_id) const override=0
 Renders the object on the given SDL renderer.
virtual void move (float x, float y, float theta=NAN) override
 Move the object to a given coordinate.
virtual bool is_tangible () const override
 Returns whether this object is tangible (e.g. collisions, etc) or not.
virtual arena_polygons_t generate_contours (std::size_t points_per_contour=0) const override
 Return one or more polygonal contours that represent the geometry of the object.
Public Member Functions inherited from Object
 Object (float _x, float _y, ObjectGeometry &_geom, std::string const &_category="objects")
 Constructs an Object.
 Object (Simulation *simulation, float _x, float _y, Configuration const &config, std::string const &_category="objects")
 Constructs an Object from a configuration entry.
virtual ~Object ()
 Destructor.
ObjectGeometryget_geometry ()
 Return the object's geometry.

Public Attributes

uint16_t id
 Object identifier.
Public Attributes inherited from Object
float x
 X position.
float y
 Y position.
float theta
 Orientation (in rad).
std::string category
 Category of the object.

Protected Member Functions

virtual void parse_configuration (Configuration const &config, Simulation *simulation) override
 Parse a provided configuration and set associated members values.
virtual void create_body (b2WorldId world_id)
 Creates the object's physical body in the simulation.

Protected Attributes

float linear_damping
float angular_damping
float density
float friction
float restitution
b2BodyId body_id
 Box2D body identifier.
float _estimated_dt = 0.0f
float _last_time = 0.0f
b2Vec2 _prev_v = {NAN, NAN}
b2Vec2 _lin_acc = {NAN, NAN}
Protected Attributes inherited from Object
ObjectGeometrygeom
 Geometry of the object.

Detailed Description

A physical object, i.e. with physics properties (e.g. collisions) modelled by Box2D.

Constructor & Destructor Documentation

◆ PhysicalObject() [1/2]

PhysicalObject::PhysicalObject ( uint16_t _id,
float _x,
float _y,
ObjectGeometry & geom,
b2WorldId world_id,
float _linear_damping = 0.0f,
float _angular_damping = 0.0f,
float _density = 10.0f,
float _friction = 0.3f,
float _restitution = 0.5f,
std::string const & _category = "objects" )

Constructs a PhysicalObject.

Parameters
_idUnique object identifier.
xInitial x-coordinate in the simulation.
yInitial y-coordinate in the simulation.
geomObject's geometry.
world_idThe Box2D world identifier.
_linear_dampingLinear damping value for the physical body (default is 0.0f).
_angular_dampingAngular damping value for the physical body (default is 0.0f).
_densityDensity of the body shape (default is 10.0f).
_frictionFriction coefficient of the body shape (default is 0.3f).
_restitutionRestitution (bounciness) of the body shape (default is 0.5f).
categoryName of the category of the object.

◆ PhysicalObject() [2/2]

PhysicalObject::PhysicalObject ( Simulation * simulation,
uint16_t _id,
float _x,
float _y,
b2WorldId world_id,
Configuration const & config,
std::string const & _category = "objects" )

Constructs a PhysicalObject from a configuration entry.

Parameters
simulationPointer to the underlying simulation.
_idUnique object identifier.
xInitial x-coordinate in the simulation.
yInitial y-coordinate in the simulation.
world_idThe Box2D world identifier.
configConfiguration entry describing the object properties.
categoryName of the category of the object.

Member Function Documentation

◆ create_body()

void PhysicalObject::create_body ( b2WorldId world_id)
protectedvirtual

Creates the object's physical body in the simulation.

Constructs a dynamic body in the Box2D world at the specified position, defines its shape based on the provided geometry.

Parameters
world_idThe Box2D world identifier.

◆ generate_contours()

arena_polygons_t PhysicalObject::generate_contours ( std::size_t points_per_contour = 0) const
overridevirtual

Return one or more polygonal contours that represent the geometry of the object.

Parameters
points_per_contourDesired number of vertices for each contour (a rectangle has one contour, a disk has one, an arena may have many – one per wall).
Returns
arena_polygons_t A vector of closed polygons (counter‑clockwise, last vertex different from the first – the caller may close the loop if needed).

Reimplemented from Object.

Reimplemented in MembraneObject.

◆ get_angle()

float PhysicalObject::get_angle ( ) const

Retrieves the object's current orientation angle.

Computes and returns the orientation angle (in radians) of the object's body.

Returns
float The orientation angle.

◆ get_angular_velocity()

float PhysicalObject::get_angular_velocity ( ) const

Retrieves the object's current angular velocity.

Returns
float The angular velocity

◆ get_linear_acceleration()

b2Vec2 PhysicalObject::get_linear_acceleration ( ) const

Retrieves the object's current angular velocity.

Returns
float The angular velocity

◆ get_position()

b2Vec2 PhysicalObject::get_position ( ) const
virtual

Retrieves the object's current position.

Returns the position of the object's physical body as a Box2D vector.

Returns
b2Vec2 The current position.

Reimplemented in MembraneObject.

◆ is_tangible()

virtual bool PhysicalObject::is_tangible ( ) const
inlineoverridevirtual

Returns whether this object is tangible (e.g. collisions, etc) or not.

Reimplemented from Object.

Reimplemented in MembraneObject, and Pogowall.

◆ launch_user_step()

void PhysicalObject::launch_user_step ( float t)
overridevirtual

Launches the user-defined step function. For PhysicalObject, it is also used to compute acceleration statistics.

Reimplemented from Object.

Reimplemented in PogobotObject.

◆ move()

void PhysicalObject::move ( float x,
float y,
float theta = NAN )
overridevirtual

Move the object to a given coordinate.

Parameters
xX coordinate.
yY coordinate.
thetaOrientation, in rad.

Reimplemented from Object.

Reimplemented in MembraneObject, and Pogowall.

◆ parse_configuration()

void PhysicalObject::parse_configuration ( Configuration const & config,
Simulation * simulation )
overrideprotectedvirtual

Parse a provided configuration and set associated members values.

Parameters
configConfiguration entry describing the object properties.

Reimplemented from Object.

Reimplemented in ActiveObject, MembraneObject, PassiveObject, and PogobotObject.

◆ render()

virtual void PhysicalObject::render ( SDL_Renderer * renderer,
b2WorldId world_id ) const
overridepure virtual

Renders the object on the given SDL renderer.

Parameters
rendererPointer to the SDL_Renderer.
world_idThe Box2D world identifier (unused in rendering).

Implements Object.

Implemented in ActiveObject, MembraneObject, PassiveObject, PogobjectObject, PogobotObject, and Pogowall.

Member Data Documentation

◆ _estimated_dt

float PhysicalObject::_estimated_dt = 0.0f
protected

◆ _last_time

float PhysicalObject::_last_time = 0.0f
protected

◆ _lin_acc

b2Vec2 PhysicalObject::_lin_acc = {NAN, NAN}
protected

◆ _prev_v

b2Vec2 PhysicalObject::_prev_v = {NAN, NAN}
protected

◆ angular_damping

float PhysicalObject::angular_damping
protected

◆ body_id

b2BodyId PhysicalObject::body_id
protected

Box2D body identifier.

◆ density

float PhysicalObject::density
protected

◆ friction

float PhysicalObject::friction
protected

◆ id

uint16_t PhysicalObject::id

Object identifier.

◆ linear_damping

float PhysicalObject::linear_damping
protected

◆ restitution

float PhysicalObject::restitution
protected

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