VR-Engage  2.2
Loading...
Searching...
No Matches
vortexCollisionProxyGenerator.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2024 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vortexCollisionProxyGenerator.h
7//! \brief Manages collisions between Vortex-simulated vehicles and non-Vortex vehicles
8//! \ingroup vreVrfVortex
9
10#pragma once
11
12#include <vreVrfVortex/export.h>
13
15
16#include <VxMath/VxMath.h>
17
18#include <matrix/vlVector.h>
19
20#include <vrfobjcore/simObjectReference.h>
21#include <vrfobjcore/compositePredicate.h>
22#include <vrfobjcore/simObject.h>
23
24#include <tbb/spin_mutex.h>
25
26class DtCgf;
27
28namespace Vx
29{
30class VxPart;
31}
32
33namespace makVre
34{
35// fwd declarations
37
38//! \brief Manages collision detection and handling between Vortex physics objects and non-Vortex simulated objects
39//!
40//! This class tracks VR-Forces (non-Vortex) vehicles using proxy representations and creates
41//! corresponding collision geometries in the Vortex physics universe. It maintains lists of
42//! nearby vehicles for each Vortex-simulated vehicle, updates their positions, and processes
43//! collision events between Vortex and non-Vortex objects.
45{
46public:
47 //! \brief Constructor
48 //!
49 //! Initializes the collision proxy generator with the provided physical world and CGF instance.
50 //! Sets up default values for proxy count, search radius, and vehicle mass.
51 //!
52 //! \param world Pointer to the Vortex physical world
53 //! \param cgf Pointer to the CGF instance for callback registration
55
56 //! \brief Destructor
57 //!
58 //! Cleans up all proxy vehicles from the Vortex universe and clears data structures.
60
61 //! \brief Default constructor, copy constructor, and copy assignment operator not allowed
65
66 //! \brief Updates lists of nearest vehicles and checks for collisions
67 //!
68 //! Called each simulation frame to update the positions of proxy vehicles
69 //! in the Vortex universe and process any collisions that occurred.
70 virtual void update();
71
72 //! \brief Adds a Vortex vehicle to the tracked vehicles list
73 //!
74 //! Registers a new Vortex-simulated vehicle by its UUID for collision handling.
75 //!
76 //! \param uuid The UUID of the Vortex vehicle to track
77 virtual void addVortexVehicle(const DtUUID& uuid);
78
79 //! \brief Removes a Vortex vehicle from the tracked vehicles list
80 //!
81 //! Unregisters a Vortex-simulated vehicle and removes its associated proxy vehicles.
82 //!
83 //! \param uuid The UUID of the Vortex vehicle to stop tracking
84 virtual void removeVortexVehicle(const DtUUID& uuid);
85
86 //! \brief Sets the entity types that Vortex vehicles will collide with
87 //!
88 //! Updates the filter for determining which object types should be considered
89 //! for collision detection with Vortex-simulated vehicles.
90 //!
91 //! \param entityTypes Vector of entity types to consider for collision detection
92 virtual void setTypesToCollideWith(std::vector<DtEntityType> entityTypes);
93
94 //! \brief Callback executed when a scenario is rewound
95 //!
96 //! Clears all vehicle lists and mappings to prevent accessing invalid data
97 //! after a scenario rewind operation.
99
100 //! \brief Renders ImGui debug interface for collision proxy visualization
101 //!
102 //! Provides a graphical user interface for debugging and monitoring the collision
103 //! proxy generator's state, including tracked vehicles and active proxies.
104 //! Override this method to customize debug visualization.
105 virtual void renderImgui();
106
107 //! \brief Clears all internal data structures
108 //!
109 //! Removes all tracked Vortex vehicles, proxy vehicles from the universe,
110 //! and clears all internal mappings between UUIDs and Vortex parts.
111 //! This method is called during destruction and scenario rewind to ensure
112 //! clean state and prevent accessing invalidated data.
113 //!
114 //! \note This method removes proxy vehicles from the Vortex universe before
115 //! clearing the data structures to ensure proper cleanup.
116 virtual void clearDataStructures();
117
118protected:
119 //! \brief Checks if a vehicle is player controlled
120 //!
121 //! Determines if a given vehicle is currently being controlled by a player
122 //! as a driver.
123 //!
124 //! \param vehicle The vehicle to check
125 //! \return True if the vehicle is player controlled, false otherwise
126 virtual bool isPlayerControlled(const DtSimObject& vehicle) const;
127
128protected:
129 //! \brief Structure representing a non-Vortex vehicle for collision detection
130 //!
131 //! This structure holds the necessary information to represent a VR-Forces simulated
132 //! ground vehicle in the Vortex physics universe for collision detection.
134 {
135 DtSimObjectReference vrfObject; //!< Reference to the VR-Forces simulation object
136 DtUUID uuid; //!< The VRF UUID of this entity (cached for when vrfObject no longer exists)
137 DtVector locationInWorld; //!< Location of this vehicle in local Dt coordinates (x-east, y-north, z-up)
138 double heading; //!< Heading of this vehicle in radians
139 double distance; //!< Distance between this vehicle and its associated Vortex vehicle
140
141 //! \brief Comparison operator for sorting by distance
142 //!
143 //! \param other The other proxy vehicle to compare against
144 //! \return True if this vehicle is closer than the other vehicle
145 bool operator<(const DtVrfProxyVehicle& other) const { return distance < other.distance; }
146 };
147
148 //! \brief Number of nearby non-Vortex vehicles to track for each Vortex vehicle
150
151 //! \brief Maximum distance in meters to search for nearby vehicles
153
154 //! \brief Default mass in kg for non-Vortex vehicles
155 //!
156 //! This value is used when creating collision proxies in the Vortex universe.
157 //! It's deliberately set high to make the vehicles behave as heavy objects.
159
160 //! \brief Adds a proxy vehicle to the Vortex physics universe
161 //!
162 //! Creates a Vortex VxPart representation of a VR-Forces vehicle for collision detection.
163 //!
164 //! \param vreProxyVehicle The proxy vehicle to add to the Vortex universe
166
167 //! \brief Updates the position of a proxy vehicle in the Vortex universe
168 //!
169 //! Adjusts the position and orientation of a proxy vehicle's Vortex representation
170 //! to match its current state in VR-Forces.
171 //!
172 //! \param proxyVehicleUUID The UUID of the proxy vehicle to update
173 //! \param vortexVehicleUUID The UUID of the corresponding Vortex vehicle
174 void updateProxyVehicleInVortexUniverse(const DtUUID& proxyVehicleUUID, const DtUUID& vortexVehicleUUID);
175
176 //! \brief Removes a proxy vehicle from the Vortex universe
177 //!
178 //! Deletes a proxy vehicle's Vortex representation and updates the tracking maps.
179 //!
180 //! \param VxProxyVehicle Pointer to the Vortex part representing the proxy vehicle
181 void removeProxyVehicleFromVortexUniverse(Vx::VxPart* VxProxyVehicle);
182
183 //! \brief Updates the list of closest vehicles for a given Vortex vehicle
184 //!
185 //! Finds the nearest non-Vortex vehicles to a specified Vortex vehicle
186 //! and creates or updates proxy representations for them.
187 //!
188 //! \param uuid The UUID of the Vortex vehicle to update proxies for
189 virtual void updateClosestVehicleList(const DtUUID& uuid);
190
191 //! \brief Removes proxy vehicles that are no longer within the search radius
192 //!
193 //! Cleans up proxies that have moved away from the specified Vortex vehicle.
194 //!
195 //! \param uuid The UUID of the Vortex vehicle to check proxies against
196 virtual void clearDistantVehicles(const DtUUID& uuid);
197
198 //! \brief Collects nearby simulation objects around a search center
199 //!
200 //! Finds all simulated objects of appropriate types within the search radius
201 //! of the specified position.
202 //!
203 //! \param searchCenter The center point for the search
204 //! \param results Vector to be filled with pointers to nearby objects
205 virtual void collectNearbySimObjects(const DtVector& searchCenter, std::vector<const DtSimObject*>& results);
206
207 //! \brief Handles a collision between two Vortex parts
208 //!
209 //! Processes a collision detected by the Vortex physics engine, generates
210 //! appropriate VR-Forces collision events, and removes the proxy to prevent
211 //! persistent collisions.
212 //!
213 //! \param part0 First Vortex part involved in the collision
214 //! \param part1 Second Vortex part involved in the collision
215 virtual void handleVortexCollision(Vx::VxPart* part0, Vx::VxPart* part1);
216
217 //! \brief Converts from VR-Forces coordinates to Vortex coordinates
218 //!
219 //! Translates position vectors between coordinate systems based on
220 //! whether the terrain is geocentric or local/flat.
221 //!
222 //! \param vec Position vector in VR-Forces coordinates
223 //! \return Equivalent position vector in Vortex coordinates
224 virtual VxMath::Vector3 toVxCoords(const DtVector& vec);
225
226 //! \brief Timestamp of the last sent collision interaction
227 //!
228 //! Used to limit the frequency of collision events for performance reasons.
230
231 //! \brief Flag indicating if the terrain uses geocentric coordinates
233
234 //! \brief Flag indicating if the coordinate converter has been set
236
237 //! \brief Coordinate converter for geocentric/local transformations
239
240 //! \brief List of UUIDs for all Vortex vehicles being tracked
241 std::vector<DtUUID> myVortexVehicles;
242
243 //! \brief Map from Vortex vehicle UUIDs to lists of nearby proxy vehicles
244 std::map<DtUUID, std::vector<DtVrfProxyVehicle>> myClosestVehicleMap;
245
246 //! \brief Pointer to the Vortex physical world
248
249 //! \brief List of all proxy vehicle parts in the Vortex universe
250 //!
251 //! Cached for efficient cleanup during destruction.
252 std::vector<Vx::VxPart*> myProxyVehiclesInUniverse;
253
254 //! \brief Mapping from Vortex parts to VR-Forces UUIDs
255 std::map<Vx::VxPart*, DtUUID> myVxPartToUUIDMap;
256
257 //! \brief Mapping from VR-Forces UUIDs to Vortex parts
258 std::map<DtUUID, Vx::VxPart*> myUUIDToVxPartMap;
259
260 //! \brief List of entity types that Vortex vehicles will collide with
261 std::vector<DtEntityType> myObjectTypesToCollideWith;
262
263 //! \brief Predicate for filtering objects by their types
265
266 //! \brief Mutex for thread-safe access to data structures
267 tbb::spin_mutex myMutex;
268};
269
270} // namespace makVre
Class for converting between different coordinate systems.
Definition coordConverter.h:31
DtVortexCollisionProxyGenerator(const DtVortexCollisionProxyGenerator &)=delete
DtVortexCollisionProxyGenerator()=delete
Default constructor, copy constructor, and copy assignment operator not allowed.
std::map< Vx::VxPart *, DtUUID > myVxPartToUUIDMap
Mapping from Vortex parts to VR-Forces UUIDs.
Definition vortexCollisionProxyGenerator.h:255
void removeProxyVehicleFromVortexUniverse(Vx::VxPart *VxProxyVehicle)
Removes a proxy vehicle from the Vortex universe.
bool myTerrainIsGeocentric
Flag indicating if the terrain uses geocentric coordinates.
Definition vortexCollisionProxyGenerator.h:232
virtual bool isPlayerControlled(const DtSimObject &vehicle) const
Checks if a vehicle is player controlled.
std::vector< DtEntityType > myObjectTypesToCollideWith
List of entity types that Vortex vehicles will collide with.
Definition vortexCollisionProxyGenerator.h:261
DtCoordinateConvert * myCoordConverter
Coordinate converter for geocentric/local transformations.
Definition vortexCollisionProxyGenerator.h:238
int mySearchRadius
Maximum distance in meters to search for nearby vehicles.
Definition vortexCollisionProxyGenerator.h:152
tbb::spin_mutex myMutex
Mutex for thread-safe access to data structures.
Definition vortexCollisionProxyGenerator.h:267
void updateProxyVehicleInVortexUniverse(const DtUUID &proxyVehicleUUID, const DtUUID &vortexVehicleUUID)
Updates the position of a proxy vehicle in the Vortex universe.
double myDefaultVrfVehicleMass
Default mass in kg for non-Vortex vehicles.
Definition vortexCollisionProxyGenerator.h:158
std::map< DtUUID, std::vector< DtVrfProxyVehicle > > myClosestVehicleMap
Map from Vortex vehicle UUIDs to lists of nearby proxy vehicles.
Definition vortexCollisionProxyGenerator.h:244
virtual void removeVortexVehicle(const DtUUID &uuid)
Removes a Vortex vehicle from the tracked vehicles list.
virtual void addVortexVehicle(const DtUUID &uuid)
Adds a Vortex vehicle to the tracked vehicles list.
std::vector< Vx::VxPart * > myProxyVehiclesInUniverse
List of all proxy vehicle parts in the Vortex universe.
Definition vortexCollisionProxyGenerator.h:252
DtVortexCollisionProxyGenerator(DtVortexPhysicalWorld *world, DtCgf *cgf)
Constructor.
virtual VxMath::Vector3 toVxCoords(const DtVector &vec)
Converts from VR-Forces coordinates to Vortex coordinates.
virtual void handleVortexCollision(Vx::VxPart *part0, Vx::VxPart *part1)
Handles a collision between two Vortex parts.
bool myCoordConverterIsSet
Flag indicating if the coordinate converter has been set.
Definition vortexCollisionProxyGenerator.h:235
virtual void collectNearbySimObjects(const DtVector &searchCenter, std::vector< const DtSimObject * > &results)
Collects nearby simulation objects around a search center.
DtVortexPhysicalWorld * myVortexPhysicalWorld
Pointer to the Vortex physical world.
Definition vortexCollisionProxyGenerator.h:247
DtCompositePredicate myCollideableObjectTypesPredicate
Predicate for filtering objects by their types.
Definition vortexCollisionProxyGenerator.h:264
std::vector< DtUUID > myVortexVehicles
List of UUIDs for all Vortex vehicles being tracked.
Definition vortexCollisionProxyGenerator.h:241
virtual void setTypesToCollideWith(std::vector< DtEntityType > entityTypes)
Sets the entity types that Vortex vehicles will collide with.
DtVortexCollisionProxyGenerator & operator=(const DtVortexCollisionProxyGenerator &)=delete
virtual void update()
Updates lists of nearest vehicles and checks for collisions.
virtual void clearDistantVehicles(const DtUUID &uuid)
Removes proxy vehicles that are no longer within the search radius.
virtual void renderImgui()
Renders ImGui debug interface for collision proxy visualization.
virtual void updateClosestVehicleList(const DtUUID &uuid)
Updates the list of closest vehicles for a given Vortex vehicle.
void addProxyVehicleToVortexUniverse(const DtVrfProxyVehicle &vreProxyVehicle)
Adds a proxy vehicle to the Vortex physics universe.
void rewindCallback()
Callback executed when a scenario is rewound.
virtual ~DtVortexCollisionProxyGenerator()
Destructor.
DtTime myLastCollisionInteractionTime
Timestamp of the last sent collision interaction.
Definition vortexCollisionProxyGenerator.h:229
std::map< DtUUID, Vx::VxPart * > myUUIDToVxPartMap
Mapping from VR-Forces UUIDs to Vortex parts.
Definition vortexCollisionProxyGenerator.h:258
virtual void clearDataStructures()
Clears all internal data structures.
int myNumProxyVehicles
Number of nearby non-Vortex vehicles to track for each Vortex vehicle.
Definition vortexCollisionProxyGenerator.h:149
Main class responsible for managing the Vortex physics simulation environment.
Definition vortexPhysicalWorld.h:55
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
Wheel articulated part IDs used in the system.
Definition surfaceToVxMaterialMapper.h:17
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
Structure representing a non-Vortex vehicle for collision detection.
Definition vortexCollisionProxyGenerator.h:134
bool operator<(const DtVrfProxyVehicle &other) const
Comparison operator for sorting by distance.
Definition vortexCollisionProxyGenerator.h:145
DtSimObjectReference vrfObject
Reference to the VR-Forces simulation object.
Definition vortexCollisionProxyGenerator.h:135
double heading
Heading of this vehicle in radians.
Definition vortexCollisionProxyGenerator.h:138
DtVector locationInWorld
Location of this vehicle in local Dt coordinates (x-east, y-north, z-up)
Definition vortexCollisionProxyGenerator.h:137
double distance
Distance between this vehicle and its associated Vortex vehicle.
Definition vortexCollisionProxyGenerator.h:139
DtUUID uuid
The VRF UUID of this entity (cached for when vrfObject no longer exists)
Definition vortexCollisionProxyGenerator.h:136