Skip to content

Commit

Permalink
adding pitch node support.
Browse files Browse the repository at this point in the history
  • Loading branch information
yifeifang committed Feb 3, 2021
1 parent 5074338 commit 56e3fae
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project2/NULL
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SUCCESS: The process "Cortana.exe" with PID 15632 has been terminated.
SUCCESS: The process "Cortana.exe" with PID 23088 has been terminated.
17 changes: 17 additions & 0 deletions Project2/gesturetree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,21 @@ bool gestureTree::set_state(gestureNode * Node)
return true;
}

pitchNode::pitchNode(unsigned id, bool leaf, k4abt_joint_id_t joint, double pitch, float threshold): gestureNode(id, leaf, joint), _pitch(pitch), _threshold(threshold)
{
}

bool pitchNode::activate(k4abt_joint_t read)
{
auto q = read.orientation.wxyz;
double pitch = atan2(2.0 * q.w * q.x + 2.0 * q.y * q.z, 1 - 2.0 * q.x * q.x - 2.0 * q.y * q.y) * (180.0 / 3.14);
printf("pitch = %f\n", pitch);
if (std::abs(std::abs(_pitch) - std::abs(pitch)) < _threshold)
{
return true;
}
else
{
return false;
}
}
9 changes: 7 additions & 2 deletions Project2/gesturetree.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ class positionNode : public gestureNode
virtual bool activate(k4abt_joint_t read) override;
};

class orientationNode : public gestureNode
class pitchNode : public gestureNode
{
// depreciated
private:
double _pitch;
float _threshold;
public:
pitchNode(unsigned id, bool leaf, k4abt_joint_id_t joint, double pitch, float threshold);
virtual bool activate(k4abt_joint_t read) override;
};

class gestureTree
Expand Down
17 changes: 15 additions & 2 deletions Project2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ int main()
positionNode* left2 = new positionNode(5, true, K4ABT_JOINT_HAND_RIGHT, k4a_float3_t{ 250,-25,500 }, 200);
positionNode* volume = new positionNode(6, true, K4ABT_JOINT_HAND_LEFT, k4a_float3_t{ 250,-60,250 }, 200);
positionNode* volume_start = new positionNode(7, false, K4ABT_JOINT_HAND_LEFT, k4a_float3_t{ 490,-80,300 }, 200);
positionNode* cortana = new positionNode(8, true, K4ABT_JOINT_HAND_LEFT, k4a_float3_t{ 250,-100,275 }, 200);
positionNode* cortana = new positionNode(8, false, K4ABT_JOINT_HAND_LEFT, k4a_float3_t{ 250,-100,275 }, 200);
pitchNode* cortana_look = new pitchNode(9, true, K4ABT_JOINT_HEAD, -70, 8);

gesture mygesture1(1, "Display Desktop", gesture_display_desktop);
gesture mygesture2(2, "Multi task", gesture_multi_task);
Expand All @@ -278,12 +279,13 @@ int main()
left2->set_gesture(mygesture2, gesture_map);
//test->set_gesture(3);
volume->set_gesture(mygesture3, gesture_map);
cortana->set_gesture(mygesture4, gesture_map);
cortana_look->set_gesture(mygesture4, gesture_map);

front->add_child(back);
front->add_child(left2);
left->add_child(right);
volume_start->add_child(volume);
cortana->add_child(cortana_look);
//left_left_land->add_child(test);

root->add_child(front);
Expand Down Expand Up @@ -320,8 +322,18 @@ int main()
joint_map[K4ABT_JOINT_HAND_RIGHT] = device._skeleton.joints[K4ABT_JOINT_HAND_RIGHT];
joint_map[K4ABT_JOINT_HAND_LEFT] = device._skeleton.joints[K4ABT_JOINT_HAND_LEFT];
joint_map[K4ABT_JOINT_WRIST_RIGHT] = device._skeleton.joints[K4ABT_JOINT_WRIST_RIGHT];
joint_map[K4ABT_JOINT_HEAD] = device._skeleton.joints[K4ABT_JOINT_HEAD];

//printf("X = %f, Y= %f, Z = %f\n", device._skeleton.joints[K4ABT_JOINT_HAND_LEFT].position.xyz.x, device._skeleton.joints[K4ABT_JOINT_HAND_LEFT].position.xyz.y, device._skeleton.joints[K4ABT_JOINT_HAND_LEFT].position.xyz.z);
//printf("W = %f, X = %f, Y= %f, Z = %f\n", device._skeleton.joints[K4ABT_JOINT_WRIST_LEFT].orientation.wxyz.w, device._skeleton.joints[K4ABT_JOINT_WRIST_LEFT].orientation.wxyz.x, device._skeleton.joints[K4ABT_JOINT_WRIST_LEFT].orientation.wxyz.y, device._skeleton.joints[K4ABT_JOINT_WRIST_LEFT].orientation.wxyz.z);
//auto q = device._skeleton.joints[K4ABT_JOINT_HEAD].orientation.wxyz;
//double pitch = atan2(2.0 * q.w * q.x + 2.0 * q.y * q.z, 1 - 2.0 * q.x * q.x - 2.0 * q.y * q.y);
//double yaw = 2.0 * q.w * q.y - 2.0 * q.z * q.x;
//yaw = yaw > 1.0 ? 1.0 : yaw;
//yaw = yaw < -1.0 ? -1.0 : yaw;
//yaw = asin(yaw);
//double roll = atan2(2.0 * q.w * q.z + 2.0 * q.y * q.x, 1 - 2.0 * q.y * q.y - 2.0 * q.z * q.z);
//printf("pitch = %f, yaw = %f, rolll = %f\n", pitch * (180.0 / 3.14), yaw * (180.0 / 3.14), roll * (180.0 / 3.14));
int gesture = mytree.traverse_map();
if (gesture == -1)// timeout
{
Expand All @@ -331,6 +343,7 @@ int main()
process_gesture(gesture, device, gesture_map);
Sleep(1000);
}

//}
}
else
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Plesae refer to [Usage section](#Usage) for how to navigate in 3D with gestures
# 3. Usage
After Launching `HoloGesture.exe` you can start to play around with gestures. Currently all the gesture presets are refer to absolute coordinate frame of Azure Kinect. Relative coordinate frame feature would be added in future releases.

**Supported Gestures**
**Supported Gestures**
1. Display Desktop
Right hand forward then backword will trigger a display desktop. Do it again will bring your desktop back.
![Display Desktop](https://github.com/yifeifang/HoloGesture/blob/gesture_object/gifs/desktop.gif)
Expand Down

0 comments on commit 56e3fae

Please sign in to comment.