UAV Simulator
Loading...
Searching...
No Matches
world.h
Go to the documentation of this file.
1/********************************************************************
2 * @file world.h
3 * @brief Defines the World class responsible for ground, terrain, and grid visualization.
4 *
5 * This class encapsulates all rendering and geometric data needed to
6 * visualize a ground plane, terrain surface, and 3D reference grid for
7 * simulation environments in the UAV Simulator.
8 ********************************************************************/
9#ifndef WORLD_H
10#define WORLD_H
11
12#include <Eigen/Dense>
13#include <easy3d/viewer/viewer.h>
14#include <easy3d/renderer/drawable_triangles.h>
15#include <easy3d/renderer/drawable_lines.h>
16#include <easy3d/renderer/vertex_array_object.h>
17#include <easy3d/core/surface_mesh.h>
18#include <easy3d/fileio/surface_mesh_io.h>
19#include <easy3d/renderer/texture.h>
20#include <easy3d/renderer/texture_manager.h>
21#include <easy3d/renderer/renderer.h>
22
33class World
34{
35public:
41 World();
47 void createGround(easy3d::Viewer& viewer); //Flat ground
53 void createTerrain(easy3d::Viewer& viewer); // 3d terrain
59 void createTerrainWithTexture(easy3d::Viewer& viewer); // textured terrain
65 void createGridDrawable(easy3d::Viewer& viewer); // Creates the 3d grid system
66
67private:
68 // === Default parameters for the 3D grid visualization ===
69
70 // The total length of each axis in the grid (in world units).
71 // The grid spans from -size/2 to +size/2 along each axis plane.
72 // Increase this to make the grid larger, decrease for a smaller grid.
78 static constexpr float DEFAULT_GRID_SIZE = 6000.0f;
79
80 // The offset that shifts the grid's location along one or more axes.
81 // In the provided grid creation logic, this is used to "lift" the grid away from the world origin
82 // so that it doesn't obscure other objects like the aircraft.
86 static constexpr float DEFAULT_OFFSET = 3000.0f;
87
88 // The number of lines to draw along each axis.
89 // Controls the resolution (density) of the grid.
90 // A higher number results in finer divisions in the grid, a lower number creates a coarser grid.
96 static constexpr int DEFAULT_NUM_LINES = 70;
97
98 // === Instance variables for the grid system ===
99
100 // The actual grid size to be used for this world instance.
101 // Initialized from DEFAULT_GRID_SIZE but could be made configurable later.
107 const float size;
108
109 // The number of lines used in this world instance's grid.
115 const int numLines;
116
117 // The offset used for this grid instance to shift it away from the origin.
123 const float offset;
124
125 // Pointer to the Easy3D LinesDrawable, which represents the grid in the viewer.
126 // This object holds the OpenGL buffers for rendering the grid lines.
132 easy3d::LinesDrawable* gridDrawable;
133
134 // List of vertices that define the grid lines.
135 // Each consecutive pair of vertices forms a single line segment.
136 // Populated in createGridDrawable() and passed to gridDrawable for rendering.
142 std::vector<easy3d::vec3> grid_vertices;
143
144 std::unique_ptr<easy3d::Texture> terrainTexture;
145};
146
147#endif // WORLD_H
Manages terrain, ground, and 3D grid elements within the simulation scene.
Definition world.h:34
const float size
Actual grid size for this world instance.
Definition world.h:107
void createGridDrawable(easy3d::Viewer &viewer)
Generates and displays a 3D coordinate grid.
Definition world.cpp:230
static constexpr float DEFAULT_GRID_SIZE
Total size of the grid (length of each axis), in world units.
Definition world.h:78
static constexpr int DEFAULT_NUM_LINES
Number of lines along each axis of the grid.
Definition world.h:96
const int numLines
Number of grid lines for this world instance.
Definition world.h:115
std::vector< easy3d::vec3 > grid_vertices
Vertices defining the grid lines.
Definition world.h:142
easy3d::LinesDrawable * gridDrawable
Pointer to Easy3D's LinesDrawable used to render the grid.
Definition world.h:132
const float offset
Grid offset to displace it from the origin.
Definition world.h:123
void createTerrainWithTexture(easy3d::Viewer &viewer)
Creates a 3D terrain surface and applies a texture image.
Definition world.cpp:133
void createGround(easy3d::Viewer &viewer)
Creates a flat ground surface and adds it to the viewer.
Definition world.cpp:28
static constexpr float DEFAULT_OFFSET
Vertical offset for the grid to visually separate it from objects like aircraft.
Definition world.h:86
std::unique_ptr< easy3d::Texture > terrainTexture
Definition world.h:144
void createTerrain(easy3d::Viewer &viewer)
Creates a basic 3D terrain surface without textures.
Definition world.cpp:76
World()
Constructs a World object with default parameters.
Definition world.cpp:11