|
VR-Engage
2.3
|
The Vortex Collision Dynamics Extension classifies local parts, collects detected collisions between them, computes impulses to apply to remote proxies, and sends/receives those remote impulse messages.
This class extends Vortex's VxDynamicsExtension, and utilizes extensions of Vortex's IntersectSubscriber and UniverseObserver
This extension has three classifications of parts, these are assigned using the tagGeometryAs... methods for each type. Proxy: Inactive parts that either are not currently, or are unable to be simulated by Vortex. These can include fallback boxes. These have the proxy response type, which is used as a flag to configure the intersect subscriber Vortex: Active parts that are simulated by Vortex, on the local sim engine. These have the rigid body response type, which is used as a flag to configure the intersect subscriber Sensor: Active parts that are simulated by Vortex, but are not simulated on the local. These have the contact sensor response type, and do not have the rigid body response model
These three classifications are used in two pairs: Proxy <-> Vortex, and Sensor <-> Vortex. Each pair has its own intersect subscriber, which is used to collect contacts between the two classifications.
The PROXY subscriber will simply collect and store contacts, which are only used for CollisionEvents. The SENSOR subscriber will collect contacts, pass them into Vortex for local impulse, and calculate a remote impulse to send and apply.
#include <vortexCollisionDynamicsExtension.h>
Classes | |
| struct | ContactData |
| struct | ReceivedMessage |
Protected Member Functions | |
| bool | initializeIfPossible () |
| void | flushDeferredGeometryAssignments () |
| void | tagGeometryWithResponse (Vx::VxCollisionGeometry *geo, Vx::ResponseType responseType, std::vector< Vx::VxCollisionGeometry * > &deferredList) |
| void | registerPartUuidForGeometry (Vx::VxCollisionGeometry *geo, const DtUUID &uuid) |
| void | processReceivedMessages () |
| void | applyImpulse (const DtVector &impulse, const DtVector &position, const DtUUID &uuid, const std::string &partName) |
| Vx::VxPart * | findPartForApplication (const DtUUID &uuid, const std::string &partName, const DtSimObject *entity) |
| DtVector | calculateImpulseFromContact (const ContactData &data, Vx::VxPart *localPart) |
| double | calculateReducedMass (Vx::VxPart *remotePart, Vx::VxPart *localPart, Vx::VxVector3 normal, Vx::VxVector3 position) |
| int | handlePartUUIDsForMessage (Vx::VxPart *part0, Vx::VxPart *part1, VortexCollisionMessage *message) |
| void | worldPosToVortexFrame (const DtVector &worldPos, DtVector &vortexPosOut) |
| bool | getPosEntityRelativeVortex (Vx::VxPart *part, DtVector &outpos, Vx::VxVector3 &worldPos) |
Static Protected Member Functions | |
| static bool | invertVxReal33 (const Vx::VxReal33 &m, Vx::VxReal33 &invOut, double eps=1e-12) |
Protected Attributes | |
| bool | myInitialized |
| DtVortexPhysicalWorld * | myVortexPhysicalWorld |
| Vx::ResponseType | myProxyResponseType |
| Vx::ResponseType | myVortexResponseType |
| Vx::ResponseType | mySensorResponseType |
| int | myRequestId |
| std::unique_ptr< DtVortexIntersectSubscriber > | myProxyIntersectSubscriber |
| std::unique_ptr< DtVortexIntersectSubscriber > | mySensorIntersectSubscriber |
| std::vector< ContactData > | myProxyContacts |
| std::vector< ContactData > | mySensorContacts |
| DtVortexUniverseObserver | myUniverseObserver |
| std::vector< Vx::VxCollisionGeometry * > | myDeferredProxyGeometries |
| std::vector< Vx::VxCollisionGeometry * > | myDeferredVortexGeometries |
| std::vector< Vx::VxCollisionGeometry * > | myDeferredSensorGeometries |
| std::unordered_map< Vx::VxPart *, DtUUID > | myVortexPartUUIDMap |
| std::map< std::pair< DtUUID, std::string >, Vx::VxPart * > | myUUIDPartMap |
| std::unordered_map< Vx::VxCollisionGeometry *, Vx::VxPart * > | myGeometryPartMap |
| std::mutex | myVortexPartUUIDMapMutex |
| std::unordered_map< DtUUID, double > | myLastCollisionTimeMap |
| double | myMaxCollisionLatency = 0.15 |
| std::map< std::pair< DtUUID, std::string >, VxMath::Vector3 > | myCachedImpulses |
| std::map< std::pair< DtUUID, std::string >, VxMath::Vector3 > | myCachedImpulsesNextFrame |
| std::deque< ReceivedMessage > | myReceivedMessages |
| std::mutex | myReceivedMessagesMutex |
| bool | myUniverseObserverRegistered {false} |
Physics tuning parameters | |
These fields are all configurable in vortexConfig.lua, to allow for tuning the physics reactions The three fields related to impulse generation (BaumgarteFraction, BaumgarteSquared, Restitution) are all adjustable per sim-engine from the remote debugger, however, those values do not persist. When tuning, if needed, the most important number is myBaumgarteFraction, tune it first until collisions are decent. Increase myBaumgarteSquared if the entities are still penetrating too far/resolution is slow. Increase myRestitution to make the collisions more elastic Decrease myMaxSeparationVelocityForApplication if the entities are being flung too far apart, and if impulses continue to be applied after separation. myWarmStartFraction is probably the least significant parameter, but increasing it should make collisions smoother/prolong their effects. | |
| double | myBaumgarteFraction = 0.75 |
| double | myBaumgarteSquared = 1.0 |
| double | myRestitution = 0.1 |
| double | myWarmStartFraction |
| double | myMaxSeparationVelocityForApplication |
| bool | myEnableNetworkedCollisions = true |
| makVre::DtVortexCollisionDynamicsExtension::DtVortexCollisionDynamicsExtension | ( | ) |
Constructor.
Referenced by DtVortexCollisionDynamicsExtension(), DtVortexCollisionDynamicsExtension(), operator=(), and operator=().
| makVre::DtVortexCollisionDynamicsExtension::~DtVortexCollisionDynamicsExtension | ( | ) |
Destructor.
|
delete |
Copy construction is disabled.
References DtVortexCollisionDynamicsExtension().
|
delete |
Move construction is disabled.
References DtVortexCollisionDynamicsExtension().
| void makVre::DtVortexCollisionDynamicsExtension::detachFromUniverse | ( | Vx::VxUniverse * | universe | ) |
Detaches this extension's observer and clears its user dynamics contacts from universe.
| universe | Universe currently owning this extension. |
|
delete |
Copy assignment is disabled.
References DtVortexCollisionDynamicsExtension().
|
delete |
Move assignment is disabled.
References DtVortexCollisionDynamicsExtension().
|
overridevirtual |
Clears per-step contact state before simulation advances.
|
overridevirtual |
Initializes the extension on demand and processes queued remote collision messages.
|
overridevirtual |
Sends or applies collision impulses for contacts collected during the step.
|
virtual |
Registers proxy collision geometry with this extension.
If the universe is not yet available, the geometry is queued for deferred assignment once the universe is initialized.
| geo | Geometry to configure for proxy-vs-Vortex collision collection. |
|
virtual |
Registers Vortex collision geometry with this extension.
If the universe is not yet available, the geometry is queued for deferred assignment once the universe is initialized.
| geo | Geometry to configure for Vortex collision collection. |
|
virtual |
Registers Vortex collision geometry and associates its part with a simulation UUID.
If the universe is not yet available, the geometry is queued for deferred assignment once the universe is initialized.
| geo | Geometry to configure for Vortex collision collection. |
| uuid | UUID of the owning simulation object. |
|
virtual |
Registers sensor collision geometry with this extension, and associates its part with a simulation UUID.
If the universe is not yet available, the geometry is queued for deferred assignment once the universe is initialized.
| geo | Geometry to configure for sensor collision collection. |
| uuid | UUID of the owning simulation object. |
|
virtual |
Registers sensor collision geometry with this extension.
If the universe is not yet available, the geometry is queued for deferred assignment once the universe is initialized.
| geo | Geometry to configure for sensor collision collection. |
|
virtual |
Removes a cached Vortex part-to-UUID mapping.
| part | Part to remove from the mapping table. |
|
virtual |
Handles an incoming collision message from the message manager.
| message | Incoming message payload. |
HANDLED when accepted for deferred processing; IGNORED otherwise.
|
virtual |
Creates and queues a collision message from a Vortex contact.
| data | ContactData used to build the outgoing message. |
| const std::vector< ContactData > & makVre::DtVortexCollisionDynamicsExtension::getProxyContacts | ( | ) | const |
Returns proxy-vs-Vortex contacts collected for the current step.
| const std::vector< ContactData > & makVre::DtVortexCollisionDynamicsExtension::getSensorContacts | ( | ) | const |
Returns Vortex-vs-Vortex contacts collected for the current step.
| Vx::ResponseType makVre::DtVortexCollisionDynamicsExtension::getProxyResponseType | ( | ) |
Gets the response type used for proxy geometries.
| Vx::ResponseType makVre::DtVortexCollisionDynamicsExtension::getVortexResponseType | ( | ) |
Gets the response type used for Vortex geometries.
| Vx::ResponseType makVre::DtVortexCollisionDynamicsExtension::getSensorResponseType | ( | ) |
Gets the response type used for sensor (remotely active Vortex vehicle) geometries.
| DtVortexPhysicalWorld * makVre::DtVortexCollisionDynamicsExtension::getVortexPhysicalWorld | ( | ) |
Gets the Vortex Physical World singleton used by this extension.
|
inline |
Returns whether networked collision messages are enabled.
References myEnableNetworkedCollisions, and myInitialized.
| void makVre::DtVortexCollisionDynamicsExtension::renderImgui | ( | ) |
Renders ImGui controls for tuning collision physics parameters.
| DtUUID makVre::DtVortexCollisionDynamicsExtension::getVortexUUIDFromPart | ( | Vx::VxPart * | part | ) |
Looks up the simulation UUID mapped to a Vortex part.
| part | Part whose UUID is requested. |
DtUUID::nullUUID() when no mapping exists. | Vx::VxPart * makVre::DtVortexCollisionDynamicsExtension::resolvePartForGeometry | ( | Vx::VxCollisionGeometry * | geo | ) |
Resolves the owning VxPart for a collision geometry, falling back to the geometry->part map populated during tagging when the geometry is a leaf child of a VxCompositeCollisionGeometry and its own getPart() returns null.
| geo | Collision geometry to resolve. |
| void makVre::DtVortexCollisionDynamicsExtension::logResponseIDsForPart | ( | Vx::VxPart * | part, |
| const char * | label = "" ) |
Logs the assigned response IDs for every collision geometry on a part, recursing into composite geometries. Intended for debugging tagging and subscription issues; compares each ID against proxyResponseType, vortexResponseType, and kResponseSensorContact and annotates matches.
| part | Part whose geometries should be logged. |
| label | Optional label prefixed to each log line. |
|
protected |
Initializes response models, subscribers, and requests once a universe is available.
|
protected |
Applies response/request IDs to geometries queued before initialization completed.
|
protected |
Tags a geometry tree with the given response ID, deferring until initialization completes.
| geo | Root collision geometry to tag. |
| responseType | Response ID to assign to each leaf geometry. |
| deferredList | List to queue the geometry on when the universe is not yet available. |
|
protected |
Maps a geometry's owning part to a simulation UUID under both part lookup maps.
| geo | Geometry whose owning part should be registered. |
| uuid | Simulation UUID to associate with the part. |
|
protected |
Drains queued received messages and applies their impulses to mapped local parts.
|
protected |
Applies an impulse to a local Vortex part identified by UUID and part name.
Used to apply impulses for both received and locally generated collisions.
| impulse | Impulse vector in Vortex world frame (NWU). |
| position | Contact position expressed as the offset from the target entity's origin, in Vortex world axes (NOT rotated into any part's body frame). Must match the packing done by sendCollisionMessage(). |
| uuid | UUID of the target part's simulation object. |
| partName | Name of the target part. |
|
protected |
Looks up a Vortex part by simulation UUID and part name.
| uuid | Simulation UUID of the owning object. |
| partName | Name of the part to find. |
| entity | Non-null owning simulation object whose published VortexArtPartMap supplies the fallback chassis part name when the requested part is not mapped. |
|
protected |
Computes an impulse vector from a Vortex contact for a designated local part.
The impulse magnitude is based on the local part's mass only, so the result is independent of the sensor proxy mass (which is unreliable for remote Vortex vehicles). The caller is responsible for negating the result to obtain the reaction impulse for the remote side.
| data | Source contact inside ContactData struct. |
| localPart | Part that should receive the resulting impulse direction/sign convention. |
|
protected |
Calculates the reduced mass for physics calculation of a collision between two parts.
| remotePart | Pointer to the remote Vortex part involved in the collision. |
| localPart | Pointer to the local Vortex part involved in the collision. |
| normal | Collision normal vector. |
| position | Collision position vector. |
|
protected |
Sets message UUID fields and identifies which part is remote for message application.
| part0 | First part in the contact pair. |
| part1 | Second part in the contact pair. |
| message | Message to populate. |
0 when part0 is remote, 1 when part1 is remote, or -1 on error.
|
staticprotected |
Inverts a 3x3 matrix, returning false if the determinant is too small.
| m | Input matrix to invert. |
| invOut | Output matrix to receive the inverse. |
| eps | Threshold for determinant magnitude below which the matrix is considered singular. |
|
protected |
Converts a world position to the Vortex frame, accounting for coordinate system differences.
| worldPos | Position in the world frame |
| vortexPosOut | Output position in the Vortex frame |
|
protected |
Converts a world position to a Vortex coordinate frame, entity centered, format.
Converts a position in Vortex world coordinates (worldPos), to an entity centered position in the world frame (outpos), which is still in vortex coordinates
| part | Pointer to the Vortex part whose frame is used for the relative position. |
| outpos | Output position in the world frame, relative to the part's origin. |
| worldPos | Position in the Vortex frame to be converted (eg. of the collision) |
|
protected |
True once response models, requests, and subscribers have been initialized.
Referenced by networkCollisionEnabled().
|
protected |
Back-pointer to the global Vortex physical world singleton.
|
protected |
Response ID for box-proxy geometries (non-Vortex vehicles). Produces real dynamics contacts against Vortex vehicles.
|
protected |
Response ID for local Vortex-vehicle geometries. Pairs with myProxyResponseType (solver contacts) and mySensorResponseType (sensor contacts for remote Vortex peers, resolved via message exchange).
|
protected |
Response ID for local proxies of vehicles that actively simulated on a remote sim engine Used to filter intersect detections against remote proxies.
|
protected |
Universe collision request ID shared by proxy and Vortex geometries.
|
protected |
Fraction of penetration depth to resolve per step (Baumgarte linear term).
|
protected |
Coefficient for quadratic penetration correction term.
|
protected |
Coefficient of restitution (0 = inelastic, 1 = elastic).
|
protected |
Fraction of previous impulse applied as warm start; smooths out impulse application.
|
protected |
Maximum separation velocity for which impulses will be applied. Prevents applying impulses to parts that are separating too fast.
|
protected |
Whether collision impulses are exchanged over the network.
Referenced by networkCollisionEnabled().
|
protected |
Subscriber for proxy-vs-Vortex contact events.
|
protected |
Subscriber for Vortex-vs-Vortex contact events.
|
protected |
Contacts collected for proxy-vs-Vortex collisions this step.
|
protected |
Contacts collected for Vortex-vs-Vortex collisions this step.
|
protected |
Universe observer used to clean up part mappings on part removal.
|
protected |
Proxy geometries queued before initialization.
|
protected |
Vortex geometries queued before initialization.
|
protected |
Sensor geometries queued before initialization.
|
protected |
Mapping from Vortex part pointer to simulation UUID.
|
protected |
Reverse mapping from (UUID, partName) to Vortex part pointer.
|
protected |
Mapping from a leaf collision geometry (typically a child of a VxCompositeCollisionGeometry, whose getPart() returns null) to the owning VxPart. Populated when geometries are tagged for the collision subscriber so that contact reports referencing composite child geoms can still be resolved back to a part.
|
protected |
Mutex protecting myVortexPartUUIDMap.
|
protected |
Last known collision simulation time for each UUID.
|
protected |
Max age (seconds) of an incoming remote collision message before discard. Overridable via vortexSettings.collisionProxy.maxCollisionImpulseLatency.
|
protected |
Warm-start impulse cache keyed by UUID/part for the current frame.
|
protected |
Warm-start impulse cache built for use on the next frame.
|
protected |
Queue of received messages waiting to be processed in step().
|
protected |
Mutex protecting myReceivedMessages.
|
protected |
Indicates whether the universe observer is registered.