better handling of when lost tracking of pucks

This commit is contained in:
Dante Ruiz 2017-05-11 20:44:08 +01:00
parent 3c652a52d8
commit 5d457eaa39
2 changed files with 26 additions and 6 deletions

View file

@ -32,8 +32,6 @@
#include <controllers/StandardControls.h>
#include "OpenVrHelpers.h"
extern PoseData _nextSimPoseData;
vr::IVRSystem* acquireOpenVrSystem();
@ -207,6 +205,7 @@ void ViveControllerManager::InputDevice::update(float deltaTime, const controlle
}
updateCalibratedLimbs();
_lastSimPoseData = _nextSimPoseData;
}
void ViveControllerManager::InputDevice::handleTrackedObject(uint32_t deviceIndex, const controller::InputCalibrationData& inputCalibrationData) {
@ -217,11 +216,30 @@ void ViveControllerManager::InputDevice::handleTrackedObject(uint32_t deviceInde
_nextSimPoseData.vrPoses[deviceIndex].bPoseIsValid &&
poseIndex <= controller::TRACKED_OBJECT_15) {
// process pose
const mat4& mat = _nextSimPoseData.poses[deviceIndex];
const vec3 linearVelocity = _nextSimPoseData.linearVelocities[deviceIndex];
const vec3 angularVelocity = _nextSimPoseData.angularVelocities[deviceIndex];
mat4& mat = mat4();
vec3 linearVelocity = vec3();
vec3 angularVelocity = vec3();
// check if the device is tracking out of range, then process the correct pose depending on the result.
if (_nextSimPoseData.vrPoses[deviceIndex].eTrackingResult != vr::TrackingResult_Running_OutOfRange) {
mat = _nextSimPoseData.poses[deviceIndex];
linearVelocity = _nextSimPoseData.linearVelocities[deviceIndex];
angularVelocity = _nextSimPoseData.angularVelocities[deviceIndex];
} else {
mat = _lastSimPoseData.poses[deviceIndex];
linearVelocity = _lastSimPoseData.linearVelocities[deviceIndex];
angularVelocity = _lastSimPoseData.angularVelocities[deviceIndex];
// make sure that we do not overwrite the pose in the _lastSimPose with incorrect data.
_nextSimPoseData.poses[deviceIndex] = _lastSimPoseData.poses[deviceIndex];
_nextSimPoseData.linearVelocities[deviceIndex] = _lastSimPoseData.linearVelocities[deviceIndex];
_nextSimPoseData.angularVelocities[deviceIndex] = _lastSimPoseData.angularVelocities[deviceIndex];
}
/* const mat4& mat;
const vec3 linearVelocity;
const vec3 angularVelocity;*/
controller::Pose pose(extractTranslation(mat), glmExtractRotation(mat), linearVelocity, angularVelocity);
// transform into avatar frame

View file

@ -25,6 +25,7 @@
#include <plugins/InputPlugin.h>
#include <RenderArgs.h>
#include <render/Scene.h>
#include "OpenVrHelpers.h"
namespace vr {
class IVRSystem;
@ -108,6 +109,7 @@ private:
std::vector<std::pair<uint32_t, controller::Pose>> _validTrackedObjects;
std::map<uint32_t, glm::mat4> _pucksOffset;
std::map<int, uint32_t> _jointToPuckMap;
PoseData _lastSimPoseData;
// perform an action when the InputDevice mutex is acquired.
using Locker = std::unique_lock<std::recursive_mutex>;
template <typename F>