From 1d077119379facbf8d23dfe59b515c996f199b23 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Mon, 12 Dec 2016 17:36:01 -0800 Subject: [PATCH] CR feedback --- plugins/hifiKinect/src/KinectPlugin.cpp | 92 +++++-------------------- plugins/hifiKinect/src/KinectPlugin.h | 4 +- 2 files changed, 18 insertions(+), 78 deletions(-) diff --git a/plugins/hifiKinect/src/KinectPlugin.cpp b/plugins/hifiKinect/src/KinectPlugin.cpp index e333c38e9d..844d4af962 100644 --- a/plugins/hifiKinect/src/KinectPlugin.cpp +++ b/plugins/hifiKinect/src/KinectPlugin.cpp @@ -58,9 +58,6 @@ QStringList kinectJointNames = { const bool DEFAULT_ENABLED = false; -// indices of joints of the Kinect standard skeleton. -// This is 'almost' the same as the High Fidelity standard skeleton. -// It is missing a thumb joint. enum KinectJointIndex { SpineBase = 0, SpineMid, @@ -98,11 +95,8 @@ enum KinectJointIndex { Size }; -// -1 or 0??? #define UNKNOWN_JOINT (controller::StandardPoseChannel)0 -// Almost a direct mapping except for LEFT_HAND_THUMB1 and RIGHT_HAND_THUMB1, -// which are not present in the Kinect standard skeleton. static controller::StandardPoseChannel KinectJointIndexToPoseIndexMap[KinectJointIndex::Size] = { controller::HIPS, controller::SPINE, @@ -137,52 +131,6 @@ static controller::StandardPoseChannel KinectJointIndexToPoseIndexMap[KinectJoin controller::RIGHT_HAND_INDEX4, controller::RIGHT_HAND_THUMB4, - - /** - controller::SPINE1, - controller::SPINE2, - controller::SPINE3, - - controller::RIGHT_HAND_THUMB2, - controller::RIGHT_HAND_THUMB3, - controller::RIGHT_HAND_THUMB4, - controller::RIGHT_HAND_INDEX1, - controller::RIGHT_HAND_INDEX2, - controller::RIGHT_HAND_INDEX3, - controller::RIGHT_HAND_INDEX4, - controller::RIGHT_HAND_MIDDLE1, - controller::RIGHT_HAND_MIDDLE2, - controller::RIGHT_HAND_MIDDLE3, - controller::RIGHT_HAND_MIDDLE4, - controller::RIGHT_HAND_RING1, - controller::RIGHT_HAND_RING2, - controller::RIGHT_HAND_RING3, - controller::RIGHT_HAND_RING4, - controller::RIGHT_HAND_PINKY1, - controller::RIGHT_HAND_PINKY2, - controller::RIGHT_HAND_PINKY3, - controller::RIGHT_HAND_PINKY4, - - controller::LEFT_HAND_THUMB2, - controller::LEFT_HAND_THUMB3, - controller::LEFT_HAND_THUMB4, - controller::LEFT_HAND_INDEX1, - controller::LEFT_HAND_INDEX2, - controller::LEFT_HAND_INDEX3, - controller::LEFT_HAND_INDEX4, - controller::LEFT_HAND_MIDDLE1, - controller::LEFT_HAND_MIDDLE2, - controller::LEFT_HAND_MIDDLE3, - controller::LEFT_HAND_MIDDLE4, - controller::LEFT_HAND_RING1, - controller::LEFT_HAND_RING2, - controller::LEFT_HAND_RING3, - controller::LEFT_HAND_RING4, - controller::LEFT_HAND_PINKY1, - controller::LEFT_HAND_PINKY2, - controller::LEFT_HAND_PINKY3, - controller::LEFT_HAND_PINKY4 - **/ }; // in rig frame @@ -269,19 +217,9 @@ static const char* getControllerJointName(controller::StandardPoseChannel i) { return "unknown"; } -// convert between YXZ Kinect euler angles in degrees to quaternion -// this is the default setting in the Axis Kinect server. -static quat eulerToQuat(const vec3& e) { - // euler.x and euler.y are swaped, WTF. - return (glm::angleAxis(e.x * RADIANS_PER_DEGREE, Vectors::UNIT_Y) * - glm::angleAxis(e.y * RADIANS_PER_DEGREE, Vectors::UNIT_X) * - glm::angleAxis(e.z * RADIANS_PER_DEGREE, Vectors::UNIT_Z)); -} - // // KinectPlugin // - void KinectPlugin::init() { loadSettings(); @@ -375,17 +313,17 @@ void KinectPlugin::updateBody() { if (SUCCEEDED(hr)) { INT64 nTime = 0; hr = pBodyFrame->get_RelativeTime(&nTime); - IBody* ppBodies[BODY_COUNT] = {0}; + IBody* bodies[BODY_COUNT] = {0}; if (SUCCEEDED(hr)) { - hr = pBodyFrame->GetAndRefreshBodyData(_countof(ppBodies), ppBodies); + hr = pBodyFrame->GetAndRefreshBodyData(_countof(bodies), bodies); } if (SUCCEEDED(hr)) { - ProcessBody(nTime, BODY_COUNT, ppBodies); + ProcessBody(nTime, BODY_COUNT, bodies); } - for (int i = 0; i < _countof(ppBodies); ++i) { - SafeRelease(ppBodies[i]); + for (int i = 0; i < _countof(bodies); ++i) { + SafeRelease(bodies[i]); } } @@ -394,12 +332,6 @@ void KinectPlugin::updateBody() { } #ifdef HAVE_KINECT -/// -/// Handle new body data -/// timestamp of frame -/// body data count -/// body data in frame -/// void KinectPlugin::ProcessBody(INT64 time, int bodyCount, IBody** bodies) { bool foundOneBody = false; if (_coordinateMapper) { @@ -443,6 +375,17 @@ void KinectPlugin::ProcessBody(INT64 time, int bodyCount, IBody** bodies) { // Kinect Documentation is unclear on what these orientations are, are they absolute? // or are the relative to the parent bones. It appears as if it has changed between the // older 1.x SDK and the 2.0 sdk + // + // https://social.msdn.microsoft.com/Forums/en-US/31c9aff6-7dab-433d-9af9-59942dfd3d69/kinect-v20-preview-sdk-jointorientation-vs-boneorientation?forum=kinectv2sdk + // seems to suggest these are absolute... + // "These quaternions are absolute, so you can take a mesh in local space, transform it by the quaternion, + // and it will match the exact orientation of the bone. If you want relative orientation quaternion, you + // can multiply the absolute quaternion by the inverse of the parent joint's quaternion." + // + // - Bone direction(Y green) - always matches the skeleton. + // - Normal(Z blue) - joint roll, perpendicular to the bone + // - Binormal(X orange) - perpendicular to the bone and normal + glm::quat jointOrientation { jointOrientations[j].Orientation.x, jointOrientations[j].Orientation.y, jointOrientations[j].Orientation.z, @@ -560,14 +503,13 @@ void KinectPlugin::InputDevice::update(float deltaTime, const controller::InputC if (joints.size() > JointType_SpineBase) { kinectHipPos = joints[JointType_SpineBase].position; } - auto hipOffset = -1.0f * kinectHipPos; for (size_t i = 0; i < joints.size(); i++) { int poseIndex = KinectJointIndexToPoseIndex((KinectJointIndex)i); glm::vec3 linearVel, angularVel; // Adjust the position to be hip (avatar) relative, and rotated to match the avatar rotation - const glm::vec3& pos = controllerToAvatarRotation * (joints[i].position + hipOffset); + const glm::vec3& pos = controllerToAvatarRotation * (joints[i].position - kinectHipPos); if (Vectors::ZERO == pos) { _poseStateMap[poseIndex] = controller::Pose(); diff --git a/plugins/hifiKinect/src/KinectPlugin.h b/plugins/hifiKinect/src/KinectPlugin.h index 488f661860..c66d746427 100644 --- a/plugins/hifiKinect/src/KinectPlugin.h +++ b/plugins/hifiKinect/src/KinectPlugin.h @@ -41,9 +41,7 @@ template inline void SafeRelease(Interface *& pInterfaceToRelea class KinectPlugin : public InputPlugin { Q_OBJECT public: - //friend void FrameDataReceivedCallback(void* context, void* sender, _BvhDataHeaderEx* header, float* data); - - bool isHandController() const override { return false; } + bool isHandController() const override { return true; } // Plugin functions virtual void init() override;