VR-Engage  2.2
Loading...
Searching...
No Matches
vortexDynamicTerrainHandler.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2024 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vortexDynamicTerrainHandler.h
7//! \brief Provides management of dynamic terrain events within the Vortex physics engine
8//! \ingroup vreVrfVortex
9
10#pragma once
11
12#include <vreVrfVortex/export.h>
13
14#include <terrainInterface/terrainInterface.h>
15
16#include <tbb/concurrent_unordered_map.h>
17
18// Forward declares
19class DtTerrainImplementation;
20class DtLocalObject;
21class DtDynamicTerrainQueryHandle;
22
23namespace makVrv
24{
25class DtDynamicTerrainFeature;
26class DtDynamicTerrainChange;
27class DtDynamicTerrainChanges;
28} // namespace makVrv
29
30namespace Vx
31{
32class VxTriangleMeshBVTree;
33}
34
35namespace VxTerrain
36{
37class VxTerrainRequest;
38}
39
40namespace makVre
41{
42class DtVortexPhysicalWorld;
43class DtVortexPagedTerrainProducer;
44
45//! \brief Manages dynamic terrain events and updates in the Vortex physics engine
46//!
47//! This class is responsible for handling dynamic terrain modifications in VR-Forces
48//! and translating them to the Vortex physics engine. It processes terrain change
49//! notifications, identifies affected terrain cells, and schedules regeneration
50//! of collision geometries to reflect the terrain changes.
52{
53public:
54 //! \brief Map type for tracking dynamic terrain modification requests
55 //!
56 //! Maps terrain cell source IDs to new triangle meshes that need to be applied.
57 using DynamicTerrainRequestMap = tbb::concurrent_unordered_map<int, Vx::VxTriangleMeshBVTree*>;
58
59public:
60 //! \brief Constructor
61 //!
62 //! Initializes the dynamic terrain handler with a reference to the Vortex physical world.
63 //! Only the physical world should create this handler.
64 //!
65 //! \param physicalWorld Pointer to the Vortex physical world that owns this handler
67
68 //! \brief Destructor
70
71 //! \brief Registers this handler with the terrain system
72 //!
73 //! Connects to the terrain change notification callback in the terrain interface
74 //! to receive notifications when terrain is modified.
76
77 //! \brief Unregisters this handler from the terrain system
78 //!
79 //! Disconnects from the terrain change notification callback, stopping
80 //! the processing of terrain modifications.
82
83 //! \brief Swaps the internal dynamic terrain request map with the provided map
84 //!
85 //! Used to safely extract pending terrain modification requests for processing.
86 //! The provided map is typically empty before the call and contains all pending
87 //! requests after the call.
88 //!
89 //! \param reqMap Map to swap with the internal request map
91
92 //! \brief Checks if two bounding boxes intersect
93 //!
94 //! Determines if two Vortex bounding boxes overlap in 3D space.
95 //! Used to identify which terrain cells are affected by a terrain modification.
96 //!
97 //! \param firstBB First bounding box to check
98 //! \param secondBB Second bounding box to check
99 //! \return True if the boxes intersect, false otherwise
100 virtual bool doBoxesIntersect(const VxMath::BoundingBox& firstBB, const VxMath::BoundingBox& secondBB) const;
101
102 //! \brief Checks if new terrain modification requests are available
103 //!
104 //! \return True if there are pending terrain modification requests, false otherwise
105 virtual bool newRequestsAvailable() const;
106
107 //! \brief Resets all pending terrain modification requests
108 //!
109 //! Clears all pending terrain modification requests and performs cleanup.
110 //! This is typically called when the scenario is reset or a new terrain is loaded.
111 virtual void reset();
112
113protected:
114 //! \brief Static callback function for terrain change notifications
115 //!
116 //! This static function is registered with the terrain interface and
117 //! forwards terrain change notifications to the appropriate instance.
118 //!
119 //! \param terrainChangeInfo Information about the terrain change
120 //! \param usr Pointer to the DtVortexDynamicTerrainHandler instance
121 static void terrainChangeNotification(const DtTerrainChangeNotificationInfo& terrainChangeInfo, void* usr);
122
123 //! \brief Processes a terrain change notification
124 //!
125 //! Identifies terrain cells affected by the terrain change and creates
126 //! requests for regenerating their collision geometries. The affected cells
127 //! are determined by checking for intersection between the terrain change
128 //! bounding box and the cell bounding boxes.
129 //!
130 //! \param terrainChangeInfo Information about the terrain change
131 virtual void processTerrainChangeNotification(const DtTerrainChangeNotificationInfo& terrainChangeInfo);
132
133protected:
134 DtVortexPhysicalWorld* myPhysicalWorld; //!< Pointer to the Vortex physical world
135 DynamicTerrainRequestMap myDynamicTerrainRequests; //!< Map of pending terrain modification requests
136};
137} // namespace makVre
void unregisterDynamicTerrainHandler()
Unregisters this handler from the terrain system.
DtVortexPhysicalWorld * myPhysicalWorld
Pointer to the Vortex physical world.
Definition vortexDynamicTerrainHandler.h:134
virtual bool newRequestsAvailable() const
Checks if new terrain modification requests are available.
void registerDynamicTerrainHandler()
Registers this handler with the terrain system.
tbb::concurrent_unordered_map< int, Vx::VxTriangleMeshBVTree * > DynamicTerrainRequestMap
Map type for tracking dynamic terrain modification requests.
Definition vortexDynamicTerrainHandler.h:57
static void terrainChangeNotification(const DtTerrainChangeNotificationInfo &terrainChangeInfo, void *usr)
Static callback function for terrain change notifications.
virtual void swapDynamicTerrainRequests(DynamicTerrainRequestMap &reqMap)
Swaps the internal dynamic terrain request map with the provided map.
DynamicTerrainRequestMap myDynamicTerrainRequests
Map of pending terrain modification requests.
Definition vortexDynamicTerrainHandler.h:135
virtual bool doBoxesIntersect(const VxMath::BoundingBox &firstBB, const VxMath::BoundingBox &secondBB) const
Checks if two bounding boxes intersect.
virtual void processTerrainChangeNotification(const DtTerrainChangeNotificationInfo &terrainChangeInfo)
Processes a terrain change notification.
virtual void reset()
Resets all pending terrain modification requests.
virtual ~DtVortexDynamicTerrainHandler()
Destructor.
DtVortexDynamicTerrainHandler(DtVortexPhysicalWorld *physicalWorld)
Constructor.
Main class responsible for managing the Vortex physics simulation environment.
Definition vortexPhysicalWorld.h:55
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
Definition vortexDynamicTerrainHandler.h:36
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
Definition appLauncherComponent.h:28