lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
Loading...
Searching...
No Matches
lmgl::scene::LOD Class Reference

Level of Detail (LOD) management class. More...

#include <lod.hpp>

Public Member Functions

 LOD ()=default
 Default constructor.
 
 ~LOD ()=default
 Default destructor.
 
void add_level (std::shared_ptr< Mesh > mesh, float max_distance)
 Adds a new LOD level.
 
std::shared_ptr< Meshget_mesh (float distance_sq) const
 Retrieves the appropriate mesh based on the squared distance.
 
std::shared_ptr< Meshget_mesh (const glm::vec3 &camera_pos, const glm::vec3 &object_pos) const
 Retrieves the appropriate mesh based on camera and object positions.
 
size_t get_level_count () const
 Retrieves the number of LOD levels.
 
const LODLevelget_level (size_t index) const
 Retrieves a specific LOD level by index.
 
bool has_levels () const
 Checks if there are any LOD levels defined.
 
void clear ()
 Clears all LOD levels.
 

Detailed Description

Level of Detail (LOD) management class.

This class manages multiple levels of detail for 3D objects, allowing for efficient rendering based on the distance from the camera. It provides methods to add LOD levels and retrieve the appropriate mesh based on distance.

Member Function Documentation

◆ add_level()

void lmgl::scene::LOD::add_level ( std::shared_ptr< Mesh > mesh,
float max_distance )

Adds a new LOD level.

The levels should be added in order of increasing maximum distance.

Parameters
meshShared pointer to the mesh for the new LOD level.
max_distanceMaximum distance at which this LOD level is used.

◆ get_level()

const LODLevel & lmgl::scene::LOD::get_level ( size_t index) const
inline

Retrieves a specific LOD level by index.

Parameters
indexIndex of the LOD level to retrieve.
Returns
Reference to the LODLevel at the specified index.

◆ get_level_count()

size_t lmgl::scene::LOD::get_level_count ( ) const
inline

Retrieves the number of LOD levels.

Returns
Number of LOD levels.

◆ get_mesh() [1/2]

std::shared_ptr< Mesh > lmgl::scene::LOD::get_mesh ( const glm::vec3 & camera_pos,
const glm::vec3 & object_pos ) const

Retrieves the appropriate mesh based on camera and object positions.

This method calculates the squared distance between the camera and the object, then calls the other get_mesh method to retrieve the appropriate mesh.

Parameters
camera_posPosition of the camera in 3D space.
object_posPosition of the object in 3D space.
Returns
Shared pointer to the mesh corresponding to the appropriate LOD level.

◆ get_mesh() [2/2]

std::shared_ptr< Mesh > lmgl::scene::LOD::get_mesh ( float distance_sq) const

Retrieves the appropriate mesh based on the squared distance.

The method iterates through the LOD levels and returns the mesh corresponding to the first level where the squared distance is less than or equal to the maximum distance squared for that level. If no such level is found, it returns the mesh of the highest LOD level.

Parameters
distance_sqSquared distance from the camera to the object.
Returns
Shared pointer to the mesh corresponding to the appropriate LOD level.

◆ has_levels()

bool lmgl::scene::LOD::has_levels ( ) const
inline

Checks if there are any LOD levels defined.

Returns
True if there are LOD levels, false otherwise.

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