Pogosim
Loading...
Searching...
No Matches
StaticLightObject Class Reference

Light-emitting object with optional radial gradient. More...

#include <lights.h>

Inheritance diagram for StaticLightObject:
Object

Public Types

enum class  LightMode { STATIC , GRADIENT , PLANE }
 Selects how intensity is distributed over the object geometry. More...

Public Member Functions

 StaticLightObject (float _x, float _y, ObjectGeometry &_geom, LightLevelMap *light_map, int16_t _value, LightMode _mode=LightMode::STATIC, int16_t _edge_value=0, float _gradient_radius=-1.0f, float _plane_angle=0.0f, float _plane_half_span=1000.0f, float _photo_start_at=-1.0f, float _photo_start_duration=1.0f, int16_t _photo_start_value=32767, std::string const &_category="objects")
 Construct a light object programmatically.
 StaticLightObject (Simulation *simulation, float _x, float _y, LightLevelMap *light_map, Configuration const &config, std::string const &_category="objects")
 Constructs a StaticLightObject object from a configuration entry.
virtual void render (SDL_Renderer *, b2WorldId) const override
 Renders the object on the given SDL renderer.
virtual void update_light_map (LightLevelMap &l)
 Updates the object's contribution to the light level map.
virtual void launch_user_step (float t) override
 Launches the user-defined step function.
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.
virtual void move (float x, float y, float theta=NAN)
 Move the object to a given coordinate.
virtual bool is_tangible () const
 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
 Return one or more polygonal contours that represent the geometry 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.

Protected Attributes

int16_t value = 0
int16_t orig_value = 0
int16_t edge_value = 0
float gradient_radius = -1.0f
float plane_angle = 0.0f
float plane_half_span = 1000.0f
LightMode mode = LightMode::STATIC
LightLevelMaplight_map = nullptr
float photo_start_at = -1.0f
 start time (s), negative ⇒ off
float photo_start_duration = 1.0f
 pulse width (s)
int16_t photo_start_value = 32767
 intensity during pulse
bool performing_photo_start = false
 internal state flag
Protected Attributes inherited from Object
ObjectGeometrygeom
 Geometry of the object.

Additional Inherited Members

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.

Detailed Description

Light-emitting object with optional radial gradient.

A StaticLightObject registers a callback on the global LightLevelMap given at construction time.
Once invoked, the callback iterates on every covered bin and calls LightLevelMap::add_light_level() with the intensity calculated according to the current LightMode.

The class is pod-friendly (all data members are trivially copyable / reset-able), yet provides high-level behaviour such as:

  • automatic update of the light map when switching in/out of a photo-start pulse;
  • automatic gradient-radius computation if the user passes gradient_radius ≤ 0.

Member Enumeration Documentation

◆ LightMode

enum class StaticLightObject::LightMode
strong

Selects how intensity is distributed over the object geometry.

Enumerator
STATIC 

All bins receive an identical intensity = value.

GRADIENT 

Bins receive an intensity that decays linearly with the distance from the geometrical centre (x,y).
The intensity at the outer edge of the gradient is edge_value.

PLANE 

Constructor & Destructor Documentation

◆ StaticLightObject() [1/2]

StaticLightObject::StaticLightObject ( float _x,
float _y,
ObjectGeometry & _geom,
LightLevelMap * light_map,
int16_t _value,
LightMode _mode = LightMode::STATIC,
int16_t _edge_value = 0,
float _gradient_radius = -1.0f,
float _plane_angle = 0.0f,
float _plane_half_span = 1000.0f,
float _photo_start_at = -1.0f,
float _photo_start_duration = 1.0f,
int16_t _photo_start_value = 32767,
std::string const & _category = "objects" )

Construct a light object programmatically.

Parameters
_xInitial x coordinate of the object centre (in world units, mm).
_yInitial y coordinate of the object centre.
_geomReference to the geometry that delimits where the object exists in space.
light_mapPointer to the global LightLevelMap (must remain valid for the lifetime of the object).
_valueCentre intensity in the range [0, 32767] (for STATIC this is also the only intensity).
_modeIntensity distribution strategy (default =STATIC).
_edge_valueIntensity at gradient_radius (only meaningful in GRADIENT mode).
_gradient_radiusRadius, in mm, at which the intensity reaches _edge_value.
If ≤ 0 the radius is computed automatically as the farthest covered bin centre.
_photo_start_atStart time (seconds, simulation clock) of the optional photo-start pulse.
Set to a negative value to disable.
_photo_start_durationDuration (seconds) of the pulse.
_photo_start_valueIntensity during the pulse. After the pulse the object reverts to _value.
_categoryCategory name for profiling / filtering.
Note
The object automatically registers a callback on light_map; do not call update_light_map() manually.

◆ StaticLightObject() [2/2]

StaticLightObject::StaticLightObject ( Simulation * simulation,
float _x,
float _y,
LightLevelMap * light_map,
Configuration const & config,
std::string const & _category = "objects" )

Constructs a StaticLightObject object from a configuration entry.

Parameters
simulationPointer to the underlying simulation.
xInitial x-coordinate in the simulation.
yInitial y-coordinate in the simulation.
light_mapPointer to the global light level map.
configConfiguration entry describing the object properties.
categoryName of the category of the object.

Member Function Documentation

◆ launch_user_step()

void StaticLightObject::launch_user_step ( float t)
overridevirtual

Launches the user-defined step function.

Updates the object's time, enables all registered stop watches, executes the user step function via pogo_main_loop_step, and then disables the stop watches.

Reimplemented from Object.

◆ parse_configuration()

void StaticLightObject::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.

◆ render()

virtual void StaticLightObject::render ( SDL_Renderer * ,
b2WorldId  ) const
inlineoverridevirtual

Renders the object on the given SDL renderer.

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

Implements Object.

◆ update_light_map()

void StaticLightObject::update_light_map ( LightLevelMap & l)
virtual

Updates the object's contribution to the light level map.

Member Data Documentation

◆ edge_value

int16_t StaticLightObject::edge_value = 0
protected

Intensity at gradient_radius (GRADIENT and PLANE modes only).

◆ gradient_radius

float StaticLightObject::gradient_radius = -1.0f
protected

Radius (mm) used for linear fall-off in GRADIENT mode. A non-positive value means “compute automatically”.

◆ light_map

LightLevelMap* StaticLightObject::light_map = nullptr
protected

Pointer to the light map this object contributes to.

◆ mode

LightMode StaticLightObject::mode = LightMode::STATIC
protected

Selected intensity distribution strategy.

◆ orig_value

int16_t StaticLightObject::orig_value = 0
protected

Saved intensity for restoring after a photo-start pulse.

◆ performing_photo_start

bool StaticLightObject::performing_photo_start = false
protected

internal state flag

◆ photo_start_at

float StaticLightObject::photo_start_at = -1.0f
protected

start time (s), negative ⇒ off

◆ photo_start_duration

float StaticLightObject::photo_start_duration = 1.0f
protected

pulse width (s)

◆ photo_start_value

int16_t StaticLightObject::photo_start_value = 32767
protected

intensity during pulse

◆ plane_angle

float StaticLightObject::plane_angle = 0.0f
protected

◆ plane_half_span

float StaticLightObject::plane_half_span = 1000.0f
protected

◆ value

int16_t StaticLightObject::value = 0
protected

Centre intensity (also the uniform level for STATIC mode).


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