mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:21:16 +02:00
Merge pull request #10147 from alhighfidelity/Kinect-Hand-Filter
Kinect hand filter
This commit is contained in:
commit
e64e2614e3
3 changed files with 22 additions and 5 deletions
|
@ -71,7 +71,7 @@ public:
|
||||||
|
|
||||||
void addSample(T sample) {
|
void addSample(T sample) {
|
||||||
if (numSamples > 0) {
|
if (numSamples > 0) {
|
||||||
average = ((float)sample * WEIGHTING) + ((float)average * ONE_MINUS_WEIGHTING);
|
average = (sample * WEIGHTING) + (average * ONE_MINUS_WEIGHTING);
|
||||||
} else {
|
} else {
|
||||||
average = sample;
|
average = sample;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
Q_DECLARE_LOGGING_CATEGORY(inputplugins)
|
Q_DECLARE_LOGGING_CATEGORY(inputplugins)
|
||||||
Q_LOGGING_CATEGORY(inputplugins, "hifi.inputplugins")
|
Q_LOGGING_CATEGORY(inputplugins, "hifi.inputplugins")
|
||||||
|
|
||||||
|
|
||||||
const char* KinectPlugin::NAME = "Kinect";
|
const char* KinectPlugin::NAME = "Kinect";
|
||||||
const char* KinectPlugin::KINECT_ID_STRING = "Kinect";
|
const char* KinectPlugin::KINECT_ID_STRING = "Kinect";
|
||||||
|
|
||||||
|
@ -493,11 +492,23 @@ void KinectPlugin::ProcessBody(INT64 time, int bodyCount, IBody** bodies) {
|
||||||
//_joints[j].orientation = jointOrientation;
|
//_joints[j].orientation = jointOrientation;
|
||||||
if (joints[j].JointType == JointType_HandRight) {
|
if (joints[j].JointType == JointType_HandRight) {
|
||||||
static const quat kinectToHandRight = glm::angleAxis(-PI / 2.0f, Vectors::UNIT_Y);
|
static const quat kinectToHandRight = glm::angleAxis(-PI / 2.0f, Vectors::UNIT_Y);
|
||||||
_joints[j].orientation = jointOrientation * kinectToHandRight;
|
// add moving average of orientation quaternion
|
||||||
|
glm::quat jointSample = jointOrientation * kinectToHandRight;
|
||||||
|
if (glm::dot(jointSample, _RightHandOrientationAverage.getAverage()) < 0) {
|
||||||
|
jointSample = -jointSample;
|
||||||
|
}
|
||||||
|
_RightHandOrientationAverage.addSample(jointSample);
|
||||||
|
_joints[j].orientation = glm::normalize(_RightHandOrientationAverage.getAverage());
|
||||||
} else if (joints[j].JointType == JointType_HandLeft) {
|
} else if (joints[j].JointType == JointType_HandLeft) {
|
||||||
// To transform from Kinect to our LEFT Hand.... Postive 90 deg around Y
|
// To transform from Kinect to our LEFT Hand.... Postive 90 deg around Y
|
||||||
static const quat kinectToHandLeft = glm::angleAxis(PI / 2.0f, Vectors::UNIT_Y);
|
static const quat kinectToHandLeft = glm::angleAxis(PI / 2.0f, Vectors::UNIT_Y);
|
||||||
_joints[j].orientation = jointOrientation * kinectToHandLeft;
|
// add moving average of orientation quaternion
|
||||||
|
glm::quat jointSample = jointOrientation * kinectToHandLeft;
|
||||||
|
if (glm::dot(jointSample, _LeftHandOrientationAverage.getAverage()) < 0) {
|
||||||
|
jointSample = -jointSample;
|
||||||
|
}
|
||||||
|
_LeftHandOrientationAverage.addSample(jointSample);
|
||||||
|
_joints[j].orientation = glm::normalize(_LeftHandOrientationAverage.getAverage());
|
||||||
} else {
|
} else {
|
||||||
_joints[j].orientation = jointOrientation;
|
_joints[j].orientation = jointOrientation;
|
||||||
}
|
}
|
||||||
|
@ -643,4 +654,4 @@ void KinectPlugin::InputDevice::clearState() {
|
||||||
int poseIndex = KinectJointIndexToPoseIndex((KinectJointIndex)i);
|
int poseIndex = KinectJointIndexToPoseIndex((KinectJointIndex)i);
|
||||||
_poseStateMap[poseIndex] = controller::Pose();
|
_poseStateMap[poseIndex] = controller::Pose();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
// Kinect Header files
|
// Kinect Header files
|
||||||
#include <Kinect.h>
|
#include <Kinect.h>
|
||||||
|
#include <SimpleMovingAverage.h>
|
||||||
|
|
||||||
// Safe release for interfaces
|
// Safe release for interfaces
|
||||||
template<class Interface> inline void SafeRelease(Interface *& pInterfaceToRelease) {
|
template<class Interface> inline void SafeRelease(Interface *& pInterfaceToRelease) {
|
||||||
|
@ -58,6 +59,11 @@ public:
|
||||||
virtual void saveSettings() const override;
|
virtual void saveSettings() const override;
|
||||||
virtual void loadSettings() override;
|
virtual void loadSettings() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// add variables for moving average
|
||||||
|
ThreadSafeMovingAverage<glm::quat, 2> _LeftHandOrientationAverage;
|
||||||
|
ThreadSafeMovingAverage<glm::quat, 2> _RightHandOrientationAverage;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
struct KinectJoint {
|
struct KinectJoint {
|
||||||
|
|
Loading…
Reference in a new issue