11#include " TrackerDevice.hpp"
2+ #include < cmath>
23
34SlimeVRDriver::TrackerDevice::TrackerDevice (std::string serial, int device_id, TrackerRole tracker_role)
45 : serial_(serial)
@@ -42,24 +43,46 @@ void SlimeVRDriver::TrackerDevice::PositionMessage(messages::Position& position)
4243 if (device_index_ == vr::k_unTrackedDeviceIndexInvalid)
4344 return ;
4445
46+ #ifdef _DEBUG
47+ #define CHECK_CLASSIFICATION (D ) \
48+ if (auto classification = std::fpclassify ((D)); classification == FP_NAN ) { \
49+ logger_->Log (" Uh oh! fpclassify(" #D " ) returned FP_NAN for {}: {}, zeroing" , D, serial_); \
50+ D = 0.0 ; \
51+ }
52+ #else
53+ #define CHECK_CLASSIFICATION (D ) \
54+ if (auto classification = std::fpclassify ((D)); classification == FP_NAN ) \
55+ D = 0.0 ;
56+ #endif
57+
4558 // Setup pose for this frame
4659 auto pose = last_pose_;
4760 // send the new position and rotation from the pipe to the tracker object
4861 if (position.has_x ()) {
4962 pose.vecPosition [0 ] = position.x ();
5063 pose.vecPosition [1 ] = position.y ();
5164 pose.vecPosition [2 ] = position.z ();
65+ CHECK_CLASSIFICATION (pose.vecPosition [0 ]);
66+ CHECK_CLASSIFICATION (pose.vecPosition [1 ]);
67+ CHECK_CLASSIFICATION (pose.vecPosition [2 ]);
5268 }
5369
5470 pose.qRotation .w = position.qw ();
5571 pose.qRotation .x = position.qx ();
5672 pose.qRotation .y = position.qy ();
5773 pose.qRotation .z = position.qz ();
74+ CHECK_CLASSIFICATION (pose.qRotation .w );
75+ CHECK_CLASSIFICATION (pose.qRotation .x );
76+ CHECK_CLASSIFICATION (pose.qRotation .y );
77+ CHECK_CLASSIFICATION (pose.qRotation .z );
5878
5979 if (position.has_vx ()) {
6080 pose.vecVelocity [0 ] = position.vx ();
6181 pose.vecVelocity [1 ] = position.vy ();
6282 pose.vecVelocity [2 ] = position.vz ();
83+ CHECK_CLASSIFICATION (pose.vecVelocity [0 ]);
84+ CHECK_CLASSIFICATION (pose.vecVelocity [1 ]);
85+ CHECK_CLASSIFICATION (pose.vecVelocity [2 ]);
6386 } else { // If velocity isn't being sent, don't keep stale values
6487 pose.vecVelocity [0 ] = 0 .0f ;
6588 pose.vecVelocity [1 ] = 0 .0f ;
@@ -74,11 +97,16 @@ void SlimeVRDriver::TrackerDevice::PositionMessage(messages::Position& position)
7497 pose.vecWorldFromDriverTranslation [0 ] = -trans.translation .v [0 ];
7598 pose.vecWorldFromDriverTranslation [1 ] = -trans.translation .v [1 ];
7699 pose.vecWorldFromDriverTranslation [2 ] = -trans.translation .v [2 ];
100+ CHECK_CLASSIFICATION (pose.vecWorldFromDriverTranslation [0 ]);
101+ CHECK_CLASSIFICATION (pose.vecWorldFromDriverTranslation [1 ]);
102+ CHECK_CLASSIFICATION (pose.vecWorldFromDriverTranslation [2 ]);
77103
78104 pose.qWorldFromDriverRotation .w = cos (trans.yaw / 2 );
79- pose.qWorldFromDriverRotation .x = 0 ;
105+ pose.qWorldFromDriverRotation .x = 0.0 ;
80106 pose.qWorldFromDriverRotation .y = sin (trans.yaw / 2 );
81- pose.qWorldFromDriverRotation .z = 0 ;
107+ pose.qWorldFromDriverRotation .z = 0.0 ;
108+ CHECK_CLASSIFICATION (pose.qWorldFromDriverRotation .w );
109+ CHECK_CLASSIFICATION (pose.qWorldFromDriverRotation .y );
82110 }
83111
84112 pose.deviceIsConnected = true ;
0 commit comments