VR-Engage  2.2
Loading...
Searching...
No Matches
vortexPhysicalWorld.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2024 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vortexPhysicalWorld.h
7//! \brief Contains DtVortexPhysicalWorld class that manages the Vortex physics simulation environment
8//! \ingroup vreVrfVortex
9
10#pragma once
11
12#include <vreVrfVortex/export.h>
13
14#include <vrfobjcore/physicalWorld.h>
15
16#include <Vx/VxUniverse.h>
17
18#include <VxSim/VxSmartInterface.h>
19#include <VxSim/IMaterialTable.h>
20#include <VxSim/VxSimulationState.h>
21
22#include <VxPluginSystem/VxPluginManagerListener.h>
23
26
27class DtCgf;
28class DtLocalObjectManager;
29class DtSimulationServices;
30class DtScenario;
31
32namespace VxContent
33{
34class Scene;
35}
36
37namespace makVre
38{
39class DtInitializer;
41class DtVortexDebug;
45class DtVxSimModule;
46
48
49//! \brief Main class responsible for managing the Vortex physics simulation environment
50//!
51//! DtVortexPhysicalWorld handles the initialization, management, and execution of the
52//! Vortex physics engine within the simulation. It manages terrain, collision detection,
53//! and physics simulation updates.
54class VREVRFVORTEX_DLL DtVortexPhysicalWorld : public DtPhysicalWorld
55{
56public:
57 //! \brief Constructs a new Vortex physical world
58 //! \param simManager Pointer to the simulation services manager
59 //! \param localObjManager Pointer to the local object manager
60 //! \param cgf Pointer to the CGF instance
61 explicit DtVortexPhysicalWorld(DtSimulationServices* simManager, DtLocalObjectManager* localObjManager, DtCgf* cgf);
62
63 //! \brief Virtual destructor
64 virtual ~DtVortexPhysicalWorld() override;
65
66 //! \brief Gets the singleton instance of the Vortex Physical World
67 //! \return Pointer to the DtVortexPhysicalWorld instance
69
70 //! \brief Main update function for the physics simulation
71 //!
72 //! Updates the Vortex Application, VortexDebug, VortexCollisionProxyGenerator,
73 //! and VortexDynamicTerrainHandler components.
74 virtual void tick() override;
75
76 //! \brief Gets the Vortex application instance
77 //! \return Smart pointer to the VxApplication
78 Vx::VxSmartPtr<VxSim::VxApplication> vortexApplication();
79
80 //! \brief Gets the Vortex scene instance
81 //! \return Smart interface to the Scene
82 VxSim::VxSmartInterface<VxContent::Scene> vortexScene();
83
84 //! \brief Gets the configuration initializer
85 //! \return Pointer to the DtInitializer instance
87
88 //! \brief Gets the geocentric coordinate converter
89 //! \return Pointer to the coordinate converter, NULL if using flat earth/UTM/topographic terrain
91
92 //! \brief Updates the coordinate converter based on different conditions
93 //! Called from \sa processPostLoadScenario with a list of entities.
94 //! If there are local, vortex entities loaded: Gets the average position of them all and calls \sa
95 //! updateCoordinateConverterFromGeocentric() If there are no entities above, then waits for first vortex entity
96 //! created and then sets the origin at that location.
98
99 //! \brief Sets the Vortex universe instance
100 //! \param universe Pointer to the VxUniverse to set
101 virtual void setUniverse(Vx::VxUniverse* universe);
102
103 //! \brief Gets the current Vortex universe instance
104 //! \return Pointer to the current VxUniverse
105 virtual Vx::VxUniverse* getUniverse();
106
107 //! \brief Sets the paged terrain producer
108 //! \param producer Pointer to the terrain producer instance
110
111 //! \brief Gets the current paged terrain producer
112 //! \return Pointer to the current terrain producer
114
115 //! \brief Sets the paged terrain interface
116 //! \param pagedTerrainInterface Pointer to the terrain interface
117 virtual void setPagedTerrain(DtVortexPagedTerrainInterface* pagedTerrainInterface);
118
119 //! \brief Gets the current paged terrain interface
120 //! \return Pointer to the current terrain interface
122
123 //! \brief Gets the dynamic terrain handler
124 //! \return Shared pointer to the terrain handler
125 virtual std::shared_ptr<makVre::DtVortexDynamicTerrainHandler> vortexDynamicTerrainHandler();
126
127 //! \brief Sets the dynamic terrain handler
128 //! \param handler Shared pointer to the new terrain handler
129 virtual void setVortexDynamicTerrainHandler(std::shared_ptr<makVre::DtVortexDynamicTerrainHandler> handler);
130
131 //! \brief Gets the collision proxy generator
132 //! \return Pointer to the collision proxy generator
133 //! \note Returns NULL if enableNonVortexToVortexCollisions is false in vortexConfig.lua
135
136 //! \brief Gets the local object manager
137 //! \return Pointer to the local object manager
138 virtual DtLocalObjectManager* localObjectManager();
139
140 //! \brief Gets the debug interface
141 //! \return Shared pointer to the debug interface
142 virtual std::shared_ptr<DtVortexDebug> vortexDebug();
143
144 //! \brief Gets the thread pool for paged terrain
145 //! \return Shared pointer to the thread pool
146 virtual std::shared_ptr<DtVreThreadPool> threadPool();
147
148 //! \brief Gets the material table
149 //! \return Pointer to the material table
150 virtual Vx::VxMaterialTable* getMaterialTable();
151
152 //! \brief Checks if the CGF is being destroyed
153 //! \return true if CGF is in process of destruction, false otherwise
155
156 //! \brief Gets the distance to check to the coordinate origin.
157 //! Distance is in km. Set in the vortexConfig.lua
158 //! \return the distance (km)
160
161 //! \brief The distance to check for how the vehicle from the coordinate origin.
162 //! Distance is in km. Set in the vortexConfig.lua by default
163 //! \param val distance (km)
165
166 //! \brief Check for how far we are from the coordinate origin.
167 //! Purely informational check, provides no simulation impact.
168 //! \return true if we should do our check
170
171 //! \brief Set for Check distance from origin.
172 //! \param val
174
175protected:
176 //! \brief Updates the geocentric coordinate converter to a new position
177 //! Given a new world position, reinitializes the coordinate converter to reference the passed in point
178 //! as your new 0,0,0 in flat earth coordinates.
179 //! \param worldPos The world location in GeocentricCoordinates
180 virtual void updateCoordinateConverterFromGeocentric(const DtVector& worldPos);
181
182 //! \brief Updates the physics universe settings
183 //! \param univ Pointer to the universe to update
184 virtual void updateUniverseSettings(Vx::VxUniverse* univ);
185
186 //! \brief Resets the Vortex application to its initial state
188
189 //! \brief Starts the Vortex application
190 virtual void runVortexApplication();
191
192 //! \brief Pauses the Vortex application
194
195 //! \brief Updates Vortex until a condition is met
196 //! \param func Function returning bool that determines when to stop updating
197 virtual void updateVortex(const std::function<bool(void)> func);
198
199 //! \brief Updates Vortex until a specific application mode is reached
200 //! \param targetMode The target application mode
201 virtual void updateVortex(VxSim::eApplicationMode targetMode);
202
203 //! \brief Initializes the Vortex application
205
206 //! \brief Initializes the collision manager
207 //! \param cgf Pointer to the CGF instance
208 //! \return true if initialization successful, false otherwise
209 virtual bool initializeCollisionManager(DtCgf* cgf);
210
211 // Callback methods and their processors
212 //! \brief Static callback for pre-scenario rollback events
213 //! \param data Pointer to user data (typically the DtVortexPhysicalWorld instance)
214 static void preScenarioRollbackCallback(void* data);
215
216 //! \brief Processes pre-scenario rewind events
218
219 //! \brief Static callback for post-scenario rollback events
220 //! \param data Pointer to user data (typically the DtVortexPhysicalWorld instance)
221 static void postScenarioRollbackCallback(void* data);
222
223 //! \brief Processes post-scenario rewind events
225
226 //! \brief Static callback for pre-load scenario events
227 //! \param scenario Reference to the scenario being loaded
228 //! \param data Pointer to user data (typically the DtVortexPhysicalWorld instance)
229 static void preLoadScenarioCallback(DtScenario& scenario, void* data);
230
231 //! \brief Processes pre-load scenario events
233
234 //! \brief Static callback for post-load scenario events
235 //! \param scenario Reference to the loaded scenario
236 //! \param data Pointer to user data (typically the DtVortexPhysicalWorld instance)
237 static void postLoadScenarioCallback(const DtScenario& scenario, void* data);
238
239 //! \brief Processes post-load scenario events
241
242 //! \brief Static callback for pre-load terrain events
243 //! \param scenario Filename of the scenario being loaded
244 //! \param data Pointer to user data (typically the DtVortexPhysicalWorld instance)
245 static void preLoadTerrainCallback(const DtFilename& scenario, void* data);
246
247 //! \brief Processes pre-load terrain events
248 virtual void processPreLoadTerrain();
249
250 //! \brief Static callback for post-load terrain events
251 //! \param terrain Filename of the loaded terrain
252 //! \param data Pointer to user data (typically the DtVortexPhysicalWorld instance)
253 static void postLoadTerrainCallback(const DtFilename& terrain, void* data);
254
255 //! \brief Processes post-load terrain events
257
258 //! \brief Static callback for pre-close scenario events
259 //! \param data Pointer to user data (typically the DtVortexPhysicalWorld instance)
260 static void preCloseScenarioCallback(void* data);
261
262 //! \brief Processes pre-close scenario events
264
265 //! \brief Static callback for post-close scenario events
266 //! \param data Pointer to user data (typically the DtVortexPhysicalWorld instance)
267 static void postCloseScenarioCallback(void* data);
268
269 //! \brief Processes post-close scenario events
271
272 //! \brief Static callback for scenario run events
273 //! \param data Pointer to user data (typically the DtVortexPhysicalWorld instance)
274 static void scenarioRunCallback(void* data);
275
276 //! \brief Processes scenario run events
278
279 //! \brief Static callback for scenario pause events
280 //! \param data Pointer to user data (typically the DtVortexPhysicalWorld instance)
281 static void scenarioPauseCallback(void* data);
282
283 //! \brief Processes scenario pause events
285
286 //! \brief Static callback for post-tick initialization events
287 //! \param data Pointer to user data (typically the DtVortexPhysicalWorld instance)
288 static void postTickInitCallback(void* data);
289
290 //! \brief Processes post-tick initialization events
292
293 //! \brief Static callback for CGF destruction events
294 //! \param data Pointer to user data (typically the DtVortexPhysicalWorld instance)
295 static void cgfAboutToBeDestroyed(void* data);
296
297 //! \brief Processes CGF destruction events
299
300 //! \brief Static callback for ImGui rendering events
301 //! \param args Pointer to arguments for the callback
302 static void renderImguiCallback(void* args);
303
304 //! \brief Updates ImGui interface elements
305 virtual void updateImgui();
306
307protected:
308 //! \brief Flag indicating if CGF is being destroyed
310
311 //! \brief Singleton instance of the physical world
313
314 //! \brief Pointer to the CGF instance
315 DtCgf* myCgf;
316
317 //! \brief Collision proxy generator for handling collisions
319
320 // Vortex values
321 //! \brief Material table for physics interactions
322 VxSim::VxSmartInterface<VxSim::IMaterialTable> myMaterialTable;
323
324 //! \brief Vortex simulation module
325 VxSim::VxSmartInterface<DtVxSimModule> myModule;
326
327 //! \brief Terrain extension for Vortex
328 Vx::VxSmartPtr<VxSim::VxExtension> myTerrainExt;
329
330 //! \brief Vortex scene interface
331 VxSim::VxSmartInterface<VxContent::Scene> myScene;
332
333 //! \brief Vortex application instance
334 Vx::VxSmartPtr<VxSim::VxApplication> myApplication;
335
336 //! \brief Simulation state for Vortex
337 Vx::VxSmartPtr<VxSim::VxSimulationState> mySimulationState;
338
339 //! \brief Producer for paged terrain
341
342 //! \brief Interface for paged terrain
344
345 //! \brief Vortex universe instance
346 Vx::VxUniverse* myUniverse;
347
348 //! \brief Plugin manager listener
349 std::shared_ptr<DtVxPluginManagerListener> myListener;
350
351 //! \brief Thread pool for parallel processing
352 std::shared_ptr<DtVreThreadPool> myThreadPool;
353
354 //! \brief Configuration initializer
356
357 //! \brief Coordinate converter for transformations
360 boost::signals2::connection myFirstObjectCreatedConnection;
361
362 //! \brief Debug interface for Vortex
363 std::shared_ptr<DtVortexDebug> myVortexDebug;
364
365 //! \brief Handler for dynamic terrain
366 std::shared_ptr<makVre::DtVortexDynamicTerrainHandler> myDynamicTerrainHandler;
367
368 //! \brief
371};
372
373
374//! \brief Listener interface for Vortex plugin manager events
375//!
376//! DtVxPluginManagerListener implements the VxPluginManagerListener interface to
377//! receive notifications about plugin manager events, such as plugin initialization.
378class DtVxPluginManagerListener : public VxPluginSystem::VxPluginManagerListener
379{
380public:
381 //! \brief Constructor
383
384 //! \brief Destructor
385 //!
386 //! Destroys the listener and unregisters it from the plugin manager.
387 virtual ~DtVxPluginManagerListener() override;
388
389 //! \brief Called before a plugin is initialized
390 //! \param pluginInfo Information about the plugin being initialized
391 //! \return true to allow initialization, false to abort
392 //! \see VxPluginManager::load
393 virtual bool onAboutToInitialize(const VxPluginSystem::VxPluginInfo& pluginInfo) override;
394
395protected:
396 //! \brief Set of plugin names to ignore
397 std::set<std::string> myIgnoredNames;
398};
399} // namespace makVre
Class for converting between different coordinate systems.
Definition coordConverter.h:31
Configuration initializer for VREngage components.
Definition initializer.h:80
Manages collision detection and handling between Vortex physics objects and non-Vortex simulated obje...
Definition vortexCollisionProxyGenerator.h:45
Provides debugging capabilities for Vortex physics engine.
Definition vortexDebug.h:36
Manages dynamic terrain events and updates in the Vortex physics engine.
Definition vortexDynamicTerrainHandler.h:52
Main class that manages terrain translation between VR-Forces and Vortex.
Definition vortexPagedTerrain.h:67
Producer that manages terrain in the Vortex physics universe.
Definition vortexPagedTerrainProducer.h:31
DtCgf * myCgf
Pointer to the CGF instance.
Definition vortexPhysicalWorld.h:315
void setCheckToCoordinateOrigin(bool val)
Set for Check distance from origin.
virtual makVre::DtVortexCollisionProxyGenerator * getCollisionProxyGenerator()
Gets the collision proxy generator.
std::shared_ptr< DtVortexDebug > myVortexDebug
Debug interface for Vortex.
Definition vortexPhysicalWorld.h:363
bool isDestructingCGF()
Checks if the CGF is being destroyed.
static void preLoadScenarioCallback(DtScenario &scenario, void *data)
Static callback for pre-load scenario events.
DtVortexPagedTerrainInterface * myPagedTerrainInterface
Interface for paged terrain.
Definition vortexPhysicalWorld.h:343
std::shared_ptr< DtVxPluginManagerListener > myListener
Plugin manager listener.
Definition vortexPhysicalWorld.h:349
virtual void resetVortexApplication()
Resets the Vortex application to its initial state.
VxSim::VxSmartInterface< VxSim::IMaterialTable > myMaterialTable
Material table for physics interactions.
Definition vortexPhysicalWorld.h:322
virtual DtVortexPagedTerrainProducer * pagedTerrainProducer()
Gets the current paged terrain producer.
virtual void updateImgui()
Updates ImGui interface elements.
virtual void processScenarioRunCallback()
Processes scenario run events.
virtual void updateCoordinateConverterFromGeocentric(const DtVector &worldPos)
Updates the geocentric coordinate converter to a new position Given a new world position,...
virtual void processPostTickInitCallback()
Processes post-tick initialization events.
std::shared_ptr< makVre::DtVortexDynamicTerrainHandler > myDynamicTerrainHandler
Handler for dynamic terrain.
Definition vortexPhysicalWorld.h:366
virtual ~DtVortexPhysicalWorld() override
Virtual destructor.
makVre::DtVortexCollisionProxyGenerator * myVortexCollisionManager
Collision proxy generator for handling collisions.
Definition vortexPhysicalWorld.h:318
boost::signals2::connection myFirstObjectCreatedConnection
Definition vortexPhysicalWorld.h:360
VxSim::VxSmartInterface< VxContent::Scene > vortexScene()
Gets the Vortex scene instance.
virtual void processPreLoadTerrain()
Processes pre-load terrain events.
static void postLoadTerrainCallback(const DtFilename &terrain, void *data)
Static callback for post-load terrain events.
double checkDistanceToCoordinateOrigin() const
Gets the distance to check to the coordinate origin. Distance is in km. Set in the vortexConfig....
virtual void processScenarioPauseCallback()
Processes scenario pause events.
virtual std::shared_ptr< makVre::DtVortexDynamicTerrainHandler > vortexDynamicTerrainHandler()
Gets the dynamic terrain handler.
virtual void updateCoordinateConverter()
Updates the coordinate converter based on different conditions Called from.
virtual std::shared_ptr< DtVreThreadPool > threadPool()
Gets the thread pool for paged terrain.
static DtVortexPhysicalWorld * thePhysicalWorld
Singleton instance of the physical world.
Definition vortexPhysicalWorld.h:312
bool myOverrideCoordinateConverterLocation
Definition vortexPhysicalWorld.h:359
void setCheckDistanceToCoordinateOrigin(double val)
The distance to check for how the vehicle from the coordinate origin. Distance is in km....
makVre::DtCoordinateConvert myCoordConverter
Coordinate converter for transformations.
Definition vortexPhysicalWorld.h:358
makVre::DtInitializer * configInitializer()
Gets the configuration initializer.
static void renderImguiCallback(void *args)
Static callback for ImGui rendering events.
makVre::DtCoordinateConvert * geocentricCoordConverter()
Gets the geocentric coordinate converter.
static void postLoadScenarioCallback(const DtScenario &scenario, void *data)
Static callback for post-load scenario events.
virtual std::shared_ptr< DtVortexDebug > vortexDebug()
Gets the debug interface.
static void scenarioRunCallback(void *data)
Static callback for scenario run events.
virtual void processPostLoadTerrain()
Processes post-load terrain events.
static void postTickInitCallback(void *data)
Static callback for post-tick initialization events.
Vx::VxSmartPtr< VxSim::VxApplication > vortexApplication()
Gets the Vortex application instance.
virtual bool initializeCollisionManager(DtCgf *cgf)
Initializes the collision manager.
static void preScenarioRollbackCallback(void *data)
Static callback for pre-scenario rollback events.
virtual void processPostLoadScenario()
Processes post-load scenario events.
virtual void setUniverse(Vx::VxUniverse *universe)
Sets the Vortex universe instance.
makVre::DtInitializer * myConfigInitializer
Configuration initializer.
Definition vortexPhysicalWorld.h:355
Vx::VxSmartPtr< VxSim::VxApplication > myApplication
Vortex application instance.
Definition vortexPhysicalWorld.h:334
bool myCheckToCoordinateOrigin
Definition vortexPhysicalWorld.h:370
std::shared_ptr< DtVreThreadPool > myThreadPool
Thread pool for parallel processing.
Definition vortexPhysicalWorld.h:352
Vx::VxUniverse * myUniverse
Vortex universe instance.
Definition vortexPhysicalWorld.h:346
static void postCloseScenarioCallback(void *data)
Static callback for post-close scenario events.
DtVortexPhysicalWorld(DtSimulationServices *simManager, DtLocalObjectManager *localObjManager, DtCgf *cgf)
Constructs a new Vortex physical world.
VxSim::VxSmartInterface< DtVxSimModule > myModule
Vortex simulation module.
Definition vortexPhysicalWorld.h:325
Vx::VxSmartPtr< VxSim::VxSimulationState > mySimulationState
Simulation state for Vortex.
Definition vortexPhysicalWorld.h:337
DtVortexPagedTerrainProducer * myPagedTerrainProducer
Producer for paged terrain.
Definition vortexPhysicalWorld.h:340
virtual void processPostCloseScenarioCallback()
Processes post-close scenario events.
virtual void setPagedTerrainProducer(DtVortexPagedTerrainProducer *producer)
Sets the paged terrain producer.
static void preLoadTerrainCallback(const DtFilename &scenario, void *data)
Static callback for pre-load terrain events.
static DtVortexPhysicalWorld * instance()
Gets the singleton instance of the Vortex Physical World.
bool checkToCoordinateOrigin() const
Check for how far we are from the coordinate origin. Purely informational check, provides no simulati...
virtual DtVortexPagedTerrainInterface * pagedTerrain()
Gets the current paged terrain interface.
static void scenarioPauseCallback(void *data)
Static callback for scenario pause events.
bool myDestructingCGF
Flag indicating if CGF is being destroyed.
Definition vortexPhysicalWorld.h:309
virtual void processPreLoadScenario()
Processes pre-load scenario events.
virtual void processPreCloseScenarioCallback()
Processes pre-close scenario events.
virtual void updateVortex(const std::function< bool(void)> func)
Updates Vortex until a condition is met.
virtual void processPreScenarioRewindCallback()
Processes pre-scenario rewind events.
virtual void processCgfAboutToBeDestroyed()
Processes CGF destruction events.
virtual void pauseVortexApplication()
Pauses the Vortex application.
virtual void updateVortex(VxSim::eApplicationMode targetMode)
Updates Vortex until a specific application mode is reached.
virtual void runVortexApplication()
Starts the Vortex application.
Vx::VxSmartPtr< VxSim::VxExtension > myTerrainExt
Terrain extension for Vortex.
Definition vortexPhysicalWorld.h:328
virtual void setVortexDynamicTerrainHandler(std::shared_ptr< makVre::DtVortexDynamicTerrainHandler > handler)
Sets the dynamic terrain handler.
virtual void processPostScenarioRewindCallback()
Processes post-scenario rewind events.
virtual void setPagedTerrain(DtVortexPagedTerrainInterface *pagedTerrainInterface)
Sets the paged terrain interface.
virtual Vx::VxMaterialTable * getMaterialTable()
Gets the material table.
double myCheckDistanceToCoordinateOrigin
Definition vortexPhysicalWorld.h:369
static void postScenarioRollbackCallback(void *data)
Static callback for post-scenario rollback events.
static void cgfAboutToBeDestroyed(void *data)
Static callback for CGF destruction events.
virtual DtLocalObjectManager * localObjectManager()
Gets the local object manager.
static void preCloseScenarioCallback(void *data)
Static callback for pre-close scenario events.
virtual void updateUniverseSettings(Vx::VxUniverse *univ)
Updates the physics universe settings.
virtual void tick() override
Main update function for the physics simulation.
VxSim::VxSmartInterface< VxContent::Scene > myScene
Vortex scene interface.
Definition vortexPhysicalWorld.h:331
virtual void initializeVortexApplication()
Initializes the Vortex application.
virtual Vx::VxUniverse * getUniverse()
Gets the current Vortex universe instance.
Listener interface for Vortex plugin manager events.
Definition vortexPhysicalWorld.h:379
std::set< std::string > myIgnoredNames
Set of plugin names to ignore.
Definition vortexPhysicalWorld.h:397
virtual ~DtVxPluginManagerListener() override
Destructor.
virtual bool onAboutToInitialize(const VxPluginSystem::VxPluginInfo &pluginInfo) override
Called before a plugin is initialized.
Simulator module that integrates VR-Forces with the Vortex physics engine.
Definition vortexIntegrationModule.h:45
Provides coordinate conversion functionality between different coordinate systems.
Export macros for the VR-Forces Vortex extension library.
#define VREVRFVORTEX_DLL
Export macro for non-Windows platforms.
Definition export.h:30
Definition vortexIntegrationModule.h:23
Include export definitions for this library.
Definition glsVreMessageUtil.h:49