VR-Engage  2.2
Loading...
Searching...
No Matches
vortexPagedTerrainProducer.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2024 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vortexPagedTerrainProducer.h
7//! \brief Producer that manages terrain insertion into the Vortex physics universe
8//! \ingroup vreVrfVortex
9
10#pragma once
11
12#include <vreVrfVortex/export.h>
13
14#include <VxTerrain/VxPagedTerrainProducer.h>
15
16#include <tbb/spin_mutex.h>
17
18namespace Vx
19{
20class VxCollisionGeometry;
21}
22
23namespace makVre
24{
25//! \brief Producer that manages terrain in the Vortex physics universe
26//!
27//! This class manages the terrain being inserted into the Vortex universe,
28//! maintaining a collection of paged cells with collision geometries.
29//! It also handles dynamic terrain within Vortex.
30class VREVRFVORTEX_DLL DtVortexPagedTerrainProducer : public VxTerrain::VxPagedTerrainProducer
31{
32public:
33 //! \brief Structure for managing paged terrain cells
34 //!
35 //! Represents a single cell of terrain in the paged terrain system,
36 //! with its request information and collision geometry.
37 struct PagedCell
38 {
39 //! \brief Constructor
41
42 //! \brief Destructor
44
45 int requestId; //!< Request ID of this paged cell
46 VxMath::BoundingBox requestBoundingBox; //!< Bounding box of this request
47 Vx::VxCollisionGeometry* collisionGeometry; //!< Collision geometry of the paged cell
48 };
49
50 //! \brief Map type for storing paged cells indexed by source ID
51 using PagedCells = std::unordered_map<int, PagedCell*>;
52
53public:
54 //! \brief Constructor
55 //!
56 //! Initializes a new terrain producer with default settings.
58
59 //! \brief Destructor
60 //!
61 //! Cleans up terrain cells and resources.
63
64 //! \brief Performs pre-step operations
65 //!
66 //! Gets collision geometries of parts, maps terrain requests, and sets request
67 //! priorities before stepping. Also manages the PagedCells being tracked.
68 virtual void preStep() override;
69
70 //! \brief Inserts terrain with new collision geometry
71 //!
72 //! Adds the specified parts and collision geometries to the area of a given request
73 //! with the received source ID. Use when the terrain element is not already present.
74 //! Also inserts this into the myPagedCells map.
75 //!
76 //! \param sourceId Source ID to link this collision geometry to
77 //! \param requestId Request ID to link this collision geometry to
78 //! \param requestBounds Request bounds of this terrain request
79 //! \param cg Collision geometry to insert
80 void insertTerrain(int sourceId, int requestId, VxMath::BoundingBox requestBounds, Vx::VxCollisionGeometry* cg);
81
82 //! \brief Inserts terrain with existing source ID
83 //!
84 //! Calls default insertTerrain where a request ID shares the same source ID as another request.
85 //!
86 //! \param sourceId Source ID to link this collision geometry to
87 //! \param requestId Request ID to link this collision geometry to
88 void insertTerrain(int sourceId, int requestId);
89
90 //! \brief Gets the paged cell for a source ID
91 //!
92 //! \param sourceId The source ID to look up
93 //! \return Pointer to the paged cell, or nullptr if not found
95
96 //! \brief Gets all paged cells
97 //!
98 //! \return Map of all paged cells indexed by source ID
100
101 //! \brief Gets all collision geometries
102 //!
103 //! \return Vector of all collision geometries in the terrain
104 virtual std::vector<Vx::VxCollisionGeometry*> getAllCollisionGeometries();
105
106 //! \brief Checks if terrain is available below coordinates
107 //!
108 //! \param inputCords Position to check for terrain
109 //! \return True if terrain exists below the coordinates, false otherwise
110 bool isTerrainAvailable(const VxMath::Vector3& inputCords);
111
112 //! \brief Sets the terrain cell size
113 //!
114 //! \param cellSize The new cell size in meters
115 void setTerrainCellSize(double cellSize);
116
117 //! \brief Gets the terrain cell size
118 //!
119 //! \return The current cell size in meters
120 double getTerrainCellSize() const;
121
122protected:
123 //! \brief Initializes the paged terrain producer
124 //!
125 //! Internal method called during initialization.
126 virtual void _initialize() override;
127
128protected:
129 double myPagedTerrainCellSize; //!< Size of terrain cells in meters
130 PagedCells myPagedCells; //!< Map of all paged cells by source ID
131 tbb::spin_mutex myInsertMutex; //!< Mutex for thread-safe insertion
132};
133} // namespace makVre
tbb::spin_mutex myInsertMutex
Mutex for thread-safe insertion.
Definition vortexPagedTerrainProducer.h:131
PagedCells getPagedCells()
Gets all paged cells.
void setTerrainCellSize(double cellSize)
Sets the terrain cell size.
PagedCell * getPagedCellForSourceID(int sourceId)
Gets the paged cell for a source ID.
void insertTerrain(int sourceId, int requestId)
Inserts terrain with existing source ID.
PagedCells myPagedCells
Map of all paged cells by source ID.
Definition vortexPagedTerrainProducer.h:130
virtual std::vector< Vx::VxCollisionGeometry * > getAllCollisionGeometries()
Gets all collision geometries.
virtual void preStep() override
Performs pre-step operations.
bool isTerrainAvailable(const VxMath::Vector3 &inputCords)
Checks if terrain is available below coordinates.
virtual ~DtVortexPagedTerrainProducer() override
Destructor.
double myPagedTerrainCellSize
Size of terrain cells in meters.
Definition vortexPagedTerrainProducer.h:129
double getTerrainCellSize() const
Gets the terrain cell size.
virtual void _initialize() override
Initializes the paged terrain producer.
void insertTerrain(int sourceId, int requestId, VxMath::BoundingBox requestBounds, Vx::VxCollisionGeometry *cg)
Inserts terrain with new collision geometry.
std::unordered_map< int, PagedCell * > PagedCells
Map type for storing paged cells indexed by source ID.
Definition vortexPagedTerrainProducer.h:51
Export macros for the VR-Forces Vortex extension library.
#define VREVRFVORTEX_DLL
Export macro for non-Windows platforms.
Definition export.h:30
Wheel articulated part IDs used in the system.
Definition surfaceToVxMaterialMapper.h:17
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
Structure for managing paged terrain cells.
Definition vortexPagedTerrainProducer.h:38
int requestId
Request ID of this paged cell.
Definition vortexPagedTerrainProducer.h:45
Vx::VxCollisionGeometry * collisionGeometry
Collision geometry of the paged cell.
Definition vortexPagedTerrainProducer.h:47
VxMath::BoundingBox requestBoundingBox
Bounding box of this request.
Definition vortexPagedTerrainProducer.h:46