UAV Simulator
Loading...
Searching...
No Matches
SimViewer Class Reference

Specialized Easy3D viewer class for UAV simulation with GUI integration. More...

#include <simviewer.h>

Inheritance diagram for SimViewer:
Collaboration diagram for SimViewer:

Public Member Functions

 SimViewer (const std::string &title)
 Constructor.
 
 ~SimViewer () override
 Destructor.
 
void setAircraft (Aircraft *aircraft)
 Sets the aircraft to be displayed in the viewer.
 
void setGNC (GNC *gnc)
 Sets the GNC object for displaying trim and linearisation results.
 
- Public Member Functions inherited from easy3d::ViewerImGui
 ViewerImGui (const std::string &title="Easy3D ViewerImGui", int samples=4, int gl_major=3, int gl_minor=2, bool full_screen=false, bool resizable=true, int depth_bits=24, int stencil_bits=8, int width=800, int height=600)
 Constructor for ViewerImGui.
 
 ~ViewerImGui () override
 Destructor. Cleans up ImGui and OpenGL resources.
 

Protected Member Functions

void draw () const override
 Custom draw function called every frame. Handles rendering of the aircraft and any overlays.
 
bool key_press_event (int key, int modifiers) override
 Key press event handler.
 
void pre_draw () override
 Called before rendering each frame (for ImGui setup).
 
void post_draw () override
 Called after rendering each frame (for ImGui overlays).
 
- Protected Member Functions inherited from easy3d::ViewerImGui
void init () override
 Initializes ImGui and binds it to the OpenGL and GLFW context.
 
void pre_draw () override
 Called before rendering the scene.
 
void post_draw () override
 Called after rendering the scene.
 
void post_resize (int w, int h) override
 Handles window resize events.
 
bool callback_event_cursor_pos (double x, double y) override
 Handles mouse movement.
 
bool callback_event_mouse_button (int button, int action, int modifiers) override
 Handles mouse button events.
 
bool callback_event_keyboard (int key, int action, int modifiers) override
 Handles keyboard key events.
 
bool callback_event_character (unsigned int codepoint) override
 Handles character input events.
 
bool callback_event_scroll (double dx, double dy) override
 Handles mouse scroll events.
 
void draw_menu_file ()
 Draws the "File" menu in the main menu bar.
 
void draw_menu_view ()
 Draws the "View" menu in the main menu bar.
 
float pixel_ratio ()
 Computes the pixel ratio between framebuffer and window size.
 
float widget_scaling ()
 Calculates the widget scaling factor.
 
void reload_font (int font_size=16)
 Reloads the ImGui font at a given font size.
 

Private Member Functions

void drawAnalysisTabs () const
 Draws the Analysis tab with trim and linearisation results.
 
void DisplayMatrix (const std::string &name, const Eigen::MatrixXd &M) const
 Utility function to display Eigen matrices in ImGui.
 

Private Attributes

easy3d::TextRenderer * text_renderer_
 Renders on-screen text such as FPS or labels.
 
Aircraftaircraft_ = nullptr
 Pointer to the Aircraft object for simulation.
 
GNCgnc_ = nullptr
 Pointer to the GNC object for analysis data (NEW)
 
bool show_controls_ = true
 If true, display control panel in ImGui.
 
std::vector< float > time_data_
 
std::vector< std::vector< float > > state_data_ = std::vector<std::vector<float>>(18)
 
float plot_time_ = 0.0f
 

Additional Inherited Members

- Protected Attributes inherited from easy3d::ViewerImGui
float menu_height_
 Height of the menu bar, used for adjusting overlay positions.
 
- Static Protected Attributes inherited from easy3d::ViewerImGui
static ImGuiContext * context_
 Global ImGui context shared across all viewer instances.
 

Detailed Description

Specialized Easy3D viewer class for UAV simulation with GUI integration.

Inherits from ViewerImGui to enable ImGui-based user interface. Allows for rendering an aircraft model and custom GUI panels.

Constructor & Destructor Documentation

◆ SimViewer()

SimViewer::SimViewer ( const std::string &  title)

Constructor.

Constructor for SimViewer. Initializes the Easy3D viewer with ImGui support and sets up a text renderer.

Parameters
titleTitle of the simulation window.
titleTitle of the window.

◆ ~SimViewer()

SimViewer::~SimViewer ( )
override

Destructor.

Destructor for SimViewer. Cleans up text renderer memory.

Member Function Documentation

◆ DisplayMatrix()

void SimViewer::DisplayMatrix ( const std::string &  name,
const Eigen::MatrixXd &  M 
) const
private

Utility function to display Eigen matrices in ImGui.

Displays an Eigen matrix in ImGui in a simple grid format.

Parameters
nameMatrix label.
MThe matrix to display.
nameMatrix label to display above the grid.
MThe Eigen matrix to display.

Each entry is shown with fixed precision formatting. Columns are separated with ImGui::SameLine() for compact layout.

◆ draw()

void SimViewer::draw ( ) const
overrideprotected

Custom draw function called every frame. Handles rendering of the aircraft and any overlays.

Main rendering function. Called every frame to render 3D geometry and aircraft HUD.

◆ drawAnalysisTabs()

void SimViewer::drawAnalysisTabs ( ) const
private

Draws the Analysis tab with trim and linearisation results.

Draws the Analysis tab with selectable sub-tabs for trim values and system matrices.

This method uses ImGui to present an "Analysis" window with sub-tabs for:

  • Trim values (e.g., α, β, φ, control inputs)
  • Full A/B matrices
  • Lateral A/B matrices
  • Longitudinal A/B matrices

Data is sourced from the associated GNC instance set via setGNC().

◆ key_press_event()

bool SimViewer::key_press_event ( int  key,
int  modifiers 
)
overrideprotected

Key press event handler.

Handles keyboard input for controlling aircraft.

Parameters
keyThe GLFW key code.
modifiersModifier keys (e.g., Shift, Ctrl).
Returns
true if the event is handled, false otherwise.
Parameters
keyGLFW key code
modifiersKey modifiers (Shift, Ctrl, etc.)
Returns
true if the key was handled, false if passed to base class.

◆ post_draw()

void SimViewer::post_draw ( )
overrideprotected

Called after rendering each frame (for ImGui overlays).

Called after the main draw function. Displays ImGui control panel for aircraft control surfaces. Displays Real-Time plots of the UAV state variables.

TODO get directly from sim

◆ pre_draw()

void SimViewer::pre_draw ( )
overrideprotected

Called before rendering each frame (for ImGui setup).

Called before each frame is drawn. Ensures ImGui and Easy3D are synchronized.

◆ setAircraft()

void SimViewer::setAircraft ( Aircraft aircraft)

Sets the aircraft to be displayed in the viewer.

Assigns an aircraft object to the viewer.

Parameters
aircraftPointer to the Aircraft object to visualize.
aircraftPointer to the Aircraft instance used in simulation and rendering.

◆ setGNC()

void SimViewer::setGNC ( GNC gnc)

Sets the GNC object for displaying trim and linearisation results.

Parameters
gncPointer to the GNC object. NEW: so we can fetch data for the Analysis tab
gncPointer to the GNC object.

Member Data Documentation

◆ aircraft_

Aircraft* SimViewer::aircraft_ = nullptr
private

Pointer to the Aircraft object for simulation.

◆ gnc_

GNC* SimViewer::gnc_ = nullptr
private

Pointer to the GNC object for analysis data (NEW)

◆ plot_time_

float SimViewer::plot_time_ = 0.0f
private

◆ show_controls_

bool SimViewer::show_controls_ = true
private

If true, display control panel in ImGui.

◆ state_data_

std::vector<std::vector<float> > SimViewer::state_data_ = std::vector<std::vector<float>>(18)
private

◆ text_renderer_

easy3d::TextRenderer* SimViewer::text_renderer_
private

Renders on-screen text such as FPS or labels.

◆ time_data_

std::vector<float> SimViewer::time_data_
private

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