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

A discretized 2D grid representing light intensities over a simulation area. More...

#include <lights.h>

Public Member Functions

 LightLevelMap (size_t num_bins_x, size_t num_bins_y, float bin_width, float bin_height)
 Construct a LightLevelMap.
 ~LightLevelMap ()
 Destructor.
float get_light_level_at (float x, float y) const
 Get the light level at a physical coordinate (world‐space).
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).
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).
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).
void clear ()
 Resets all bins to 0.
size_t get_num_bins_x () const
 Accessors for the grid properties.
size_t get_num_bins_y () const
float get_bin_width () const
float get_bin_height () const
void render (SDL_Renderer *renderer) const
 Renders the light level map to the given SDL_Renderer.
void register_callback (std::function< void(LightLevelMap &)> cb)
void update ()
 Clears the map and invokes all registered callbacks.

Detailed Description

A discretized 2D grid representing light intensities over a simulation area.

Constructor & Destructor Documentation

◆ LightLevelMap()

LightLevelMap::LightLevelMap ( size_t num_bins_x,
size_t num_bins_y,
float bin_width,
float bin_height )

Construct a LightLevelMap.

Parameters
num_bins_xNumber of bins along the x-axis.
num_bins_yNumber of bins along the y-axis.
bin_widthPhysical width of each bin.
bin_heightPhysical height of each bin.

◆ ~LightLevelMap()

LightLevelMap::~LightLevelMap ( )

Destructor.

Member Function Documentation

◆ add_light_level()

void LightLevelMap::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).

◆ clear()

void LightLevelMap::clear ( )

Resets all bins to 0.

◆ get_bin_height()

float LightLevelMap::get_bin_height ( ) const

◆ get_bin_width()

float LightLevelMap::get_bin_width ( ) const

◆ get_light_level()

float LightLevelMap::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).

◆ get_light_level_at()

float LightLevelMap::get_light_level_at ( float x,
float y ) const

Get the light level at a physical coordinate (world‐space).

Parameters
xX coordinate in the same units as bin_width_.
yY coordinate in the same units as bin_height_.
Returns
The light level at the bin containing (x,y), or 0 if outside.

◆ get_num_bins_x()

size_t LightLevelMap::get_num_bins_x ( ) const

Accessors for the grid properties.

◆ get_num_bins_y()

size_t LightLevelMap::get_num_bins_y ( ) const

◆ register_callback()

void LightLevelMap::register_callback ( std::function< void(LightLevelMap &)> cb)

Register a callback which will be called with the map whenever update() is run.

◆ render()

void LightLevelMap::render ( SDL_Renderer * renderer) const

Renders the light level map to the given SDL_Renderer.

This method scales each bin's light level into a brightness value. For each bin, it:

  • Normalizes the light level from the int16_t range [-32768, 32767] to [0, 1].
  • Maps that normalized value to a brightness in the range [100, 200].
  • Renders a filled rectangle with that brightness.
Parameters
rendererA pointer to the SDL_Renderer used for drawing.

◆ set_light_level()

void LightLevelMap::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).

◆ update()

void LightLevelMap::update ( )

Clears the map and invokes all registered callbacks.


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