29 LightLevelMap(
size_t num_bins_x,
size_t num_bins_y,
float bin_width,
float bin_height);
70 void render(SDL_Renderer* renderer)
const;
84 std::vector<std::vector<int16_t>> levels_;
164 int16_t _edge_value = 0,
165 float _gradient_radius = -1.0f,
166 float _plane_angle = 0.0f,
167 float _plane_half_span = 1000.0f,
168 float _photo_start_at = -1.0f,
169 float _photo_start_duration = 1.0f,
170 int16_t _photo_start_value = 32767,
171 std::string
const& _category =
"objects");
186 std::string
const& _category =
"objects");
194 virtual void render(SDL_Renderer*, b2WorldId)
const override {}
268 float ray_half_width = 0.1f,
269 float angular_speed = 3.0f,
270 float photo_start_at = -1.0f,
271 float photo_start_dur = 1.0f,
272 float _white_frame_dur = 1.0f,
273 int16_t _white_frame_val = 32767,
274 std::string
const&
category =
"objects");
279 std::string
const&
category =
"objects");
281 void render(SDL_Renderer*, b2WorldId)
const override {}
292 static float normalise_angle(
float a);
297 float ray_half_width = 0.1f;
298 float angular_speed = 3.0f;
299 float photo_start_at = -1.0f;
300 float photo_start_dur = 1.0f;
301 float white_frame_dur = 0.03f;
302 int16_t white_frame_val = 32767;
305 float current_angle = 0.0f;
306 bool ray_is_active =
true;
307 float previous_angle = 0.f;
308 bool white_frame_active =
false;
309 float white_frame_end_time = 0.f;
310 float sim_prev_t = 0.f;
311 float ray_current_t = 0.f;
319 float ray_half_width = 0.1f,
320 float angular_speed = 3.0f,
321 float long_white_frame_dur = 1.0f,
322 float short_white_frame_dur = 0.03f,
323 int16_t white_frame_val = 32767,
324 std::string
const&
category =
"objects");
329 std::string
const&
category =
"objects");
331 void render(SDL_Renderer*, b2WorldId)
const override {}
341 static float normalise_angle(
float a);
342 void recompute_geometry();
343 void request_map_refresh() { light_map->
update(); }
346 enum class phase_t { LONG_WHITE, LEFT_RAY, SHORT_WHITE, RIGHT_RAY };
348 void enter_phase(phase_t p,
float now_s);
351 LightLevelMap* light_map =
nullptr;
353 float ray_half_width = 0.1f;
354 float angular_speed = 3.0f;
355 float long_white_dur = 1.0f;
356 float short_white_dur = 0.03f;
357 int16_t white_val = 32767;
361 float cx = 0.f, cy = 0.f;
362 float ax_l = 0.f, ay_l = 0.f;
363 float ax_r = 0.f, ay_r = 0.f;
364 float left_a0 = 0.f, left_a1 = 0.f;
365 float right_a0 = 0.f, right_a1 = 0.f;
368 phase_t phase = phase_t::LONG_WHITE;
369 float phase_start_t = 0.f;
371 float current_angle = 0.f;
AlternatingDualRayOfLightObject(float x, float y, ObjectGeometry &geom, LightLevelMap *light_map, int16_t value, float ray_half_width=0.1f, float angular_speed=3.0f, float long_white_frame_dur=1.0f, float short_white_frame_dur=0.03f, int16_t white_frame_val=32767, std::string const &category="objects")
Definition lights.cpp:521
void parse_configuration(Configuration const &config, Simulation *simulation) override
Parse a provided configuration and set associated members values.
Definition lights.cpp:558
void update_light_map(LightLevelMap &l)
Definition lights.cpp:625
void render(SDL_Renderer *, b2WorldId) const override
Renders the object on the given SDL renderer.
Definition lights.h:331
void launch_user_step(float t) override
Launches the user-defined step function.
Definition lights.cpp:584
Class for managing hierarchical configuration parameters.
Definition configuration.h:64
A discretized 2D grid representing light intensities over a simulation area.
Definition lights.h:20
float get_bin_height() const
Definition lights.cpp:92
void register_callback(std::function< void(LightLevelMap &)> cb)
Definition lights.cpp:138
void clear()
Resets all bins to 0.
Definition lights.cpp:70
float get_light_level_at(float x, float y) const
Get the light level at a physical coordinate (world‐space).
Definition lights.cpp:31
void render(SDL_Renderer *renderer) const
Renders the light level map to the given SDL_Renderer.
Definition lights.cpp:96
float get_bin_width() const
Definition lights.cpp:87
float get_light_level(size_t bin_x, size_t bin_y) const
Returns the light level stored at the given bin (bin_x, bin_y).
Definition lights.cpp:49
size_t get_num_bins_x() const
Accessors for the grid properties.
Definition lights.cpp:77
LightLevelMap(size_t num_bins_x, size_t num_bins_y, float bin_width, float bin_height)
Construct a LightLevelMap.
Definition lights.cpp:18
size_t get_num_bins_y() const
Definition lights.cpp:82
void add_light_level(size_t bin_x, size_t bin_y, int16_t value)
Adds a given value to the light level at the given bin (bin_x, bin_y).
Definition lights.cpp:61
~LightLevelMap()
Destructor.
Definition lights.cpp:27
void update()
Clears the map and invokes all registered callbacks.
Definition lights.cpp:142
void set_light_level(size_t bin_x, size_t bin_y, int16_t value)
Sets the light level at the given bin (bin_x, bin_y).
Definition lights.cpp:55
Geometry of an object.
Definition objects_geometry.h:40
float y
Y position.
Definition objects.h:99
std::string category
Category of the object.
Definition objects.h:103
float x
X position.
Definition objects.h:98
ObjectGeometry * geom
Geometry of the object.
Definition objects.h:113
Object(float _x, float _y, ObjectGeometry &_geom, std::string const &_category="objects")
Constructs an Object.
Definition objects.cpp:16
RotatingRayOfLightObject(float x, float y, ObjectGeometry &geom, LightLevelMap *light_map, int16_t value, float ray_half_width=0.1f, float angular_speed=3.0f, float photo_start_at=-1.0f, float photo_start_dur=1.0f, float _white_frame_dur=1.0f, int16_t _white_frame_val=32767, std::string const &category="objects")
Definition lights.cpp:343
void render(SDL_Renderer *, b2WorldId) const override
Renders the object on the given SDL renderer.
Definition lights.h:281
void update_light_map(LightLevelMap &l)
Definition lights.cpp:407
void start_white_frame(float now_s)
Definition lights.cpp:400
void launch_user_step(float t) override
Launches the user-defined step function.
Definition lights.cpp:438
void parse_configuration(Configuration const &config, Simulation *simulation) override
Parse a provided configuration and set associated members values.
Definition lights.cpp:382
Class representing the simulation environment.
Definition simulator.h:43
float photo_start_duration
pulse width (s)
Definition lights.h:246
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.
Definition lights.cpp:155
int16_t value
Definition lights.h:217
float gradient_radius
Definition lights.h:229
virtual void update_light_map(LightLevelMap &l)
Updates the object's contribution to the light level map.
Definition lights.cpp:218
LightMode
Selects how intensity is distributed over the object geometry.
Definition lights.h:125
@ GRADIENT
Definition lights.h:125
@ PLANE
Definition lights.h:125
@ STATIC
Definition lights.h:125
virtual void parse_configuration(Configuration const &config, Simulation *simulation) override
Parse a provided configuration and set associated members values.
Definition lights.cpp:290
bool performing_photo_start
internal state flag
Definition lights.h:248
float plane_half_span
Definition lights.h:236
virtual void render(SDL_Renderer *, b2WorldId) const override
Renders the object on the given SDL renderer.
Definition lights.h:194
float photo_start_at
start time (s), negative ⇒ off
Definition lights.h:245
int16_t orig_value
Definition lights.h:220
LightMode mode
Definition lights.h:239
float plane_angle
Definition lights.h:232
LightLevelMap * light_map
Definition lights.h:242
virtual void launch_user_step(float t) override
Launches the user-defined step function.
Definition lights.cpp:319
int16_t edge_value
Definition lights.h:223
int16_t photo_start_value
intensity during pulse
Definition lights.h:247
std::unique_ptr< Simulation > simulation
Global simulation instance.
Definition simulator.cpp:74