Ocean
Loading...
Searching...
No Matches
HandGestures.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_PLATFORM_META_QUEST_OPENXR_HAND_GESTURES_H
9#define META_OCEAN_PLATFORM_META_QUEST_OPENXR_HAND_GESTURES_H
10
13
15#include "ocean/math/Line3.h"
16#include "ocean/math/Vector3.h"
17
18namespace Ocean
19{
20
21namespace Platform
22{
23
24namespace Meta
25{
26
27namespace Quest
28{
29
30namespace OpenXR
31{
32
33/**
34 * This class implements hand gestures functionalities.
35 * @ingroup platformmetaquestopenxr
36 */
38{
39 public:
40
41 /**
42 * Determines the minimal and maximal angle between consecutive bones.
43 * @param jointPoints The 3D locations of the hand joints, at least 3
44 * @param jointIndices The indices of consecutive hand joints (e.g., of a finger), two indices define a bone, at least 3
45 * @param minAngle Optional resulting minimal angle between all consecutive bones, in radian, with range [0, maxAngle]
46 * @param maxAngle Optional resulting maximal angle between all consecutive bones, in radian, with range [minAngle, PI]
47 * @param medianAngle Optional resulting median angle between all consecutive bones, in radian, with range [minAngle, maxAngle]
48 * @return True, if succeeded
49 */
50 static bool determineBoneAngles(const Vectors3& jointPoints, const Indices32& jointIndices, Scalar* minAngle = nullptr, Scalar* maxAngle = nullptr, Scalar* medianAngle = nullptr);
51
52 /**
53 * Determines the distance between two finger joints of a hand.
54 * @param jointPoints The 3D locations of the hand joints, at least 3
55 * @param joint0 The index of the first joint, with range [0, jointPoints.size() - 1]
56 * @param joint1 The index of the second joint, with range [0, jointPoints.size() - 1]
57 * @param position0 Optional The resulting position of the first joint, nullptr if not of interest
58 * @param position1 Optional The resulting position of the second joint, nullptr if not of interest
59 * @return The resulting distance, Numeric::maxValue() otherwise
60 */
61 static Scalar distanceBetweenFingerJoints(const Vectors3& jointPoints, const Index32 joint0, const Index32 joint1, Vector3* position0 = nullptr, Vector3* position1 = nullptr);
62
63 /**
64 * Returns whether a hand is pinching (whether thumb and index finger tips are together).
65 * @param jointPositions The positions of the joints of a hand, defined in world, either XR_HAND_JOINT_COUNT_EXT positions (or zero to fail)
66 * @param position Optional resulting pinching position (position between thumb and index finger tip, in world), nullptr of not of interest
67 * @param maxDistance The maximal distance between both finger tips to count as pinching, in meter, with range [0, infinity)
68 * @return True, if so
69 */
70 static bool isHandPinching(const Vectors3& jointPositions, Vector3* position = nullptr, const Scalar maxDistance = Scalar(0.025));
71
72 /**
73 * Returns whether a hand is making a 'tunnel' gesture (whether thumb and index finger tips are together and forming a round tunnel with thumb and index finger).
74 * @param jointPositions The positions of the joints of a hand, defined in world, either XR_HAND_JOINT_COUNT_EXT positions (or zero to fail)
75 * @param isLeft True, if the hand is a left hand; False, if the hand is a right hand
76 * @param world_T_tunnelCenter The resulting transformation between the tunnel center and the world, with x-axis to the right (parallel to the line between the index knuckle and thumb tip), and z-axis outside the tunnel (towards the user)
77 * @param maxTipDistance The maximal distance between both finger tips to count as pinching, in meter, with range [0, infinity)
78 * @param minTunnelDistance The minimal distance between opposite tunnel bones (to ensure a round tunnel), in meters, with range [0, infinity)
79 * @return True, if so
80 */
81 static bool isHandTunneling(const Vectors3& jointPositions, const bool isLeft, HomogenousMatrix4& world_T_tunnelCenter, const Scalar maxTipDistance = Scalar(0.025), const Scalar minTunnelDistance = Scalar(0.05));
82
83 /**
84 * Returns whether a hand is making a pointing gesture with the index finger.
85 * @param jointPositions The positions of the joints of a hand, defined in world, either XR_HAND_JOINT_COUNT_EXT positions (or zero to fail)
86 * @param worldRay The resulting pointing ray along the index finger, in world
87 * @param maxIndexAngle The maximal angle between bones of the index finger, in radian, with range [0, PI)
88 * @param minAngle The minimal angle between bones in all other fingers, in radian, with range [0, PI)
89 * @param minTipDistance The minimal distance between index fingertip and all other fingertips, in meter, with range [0, infinity)
90 * @param maxTipDistance The maximal distance between fingertips (not including the index finger), in meter, with range [0, infinity)
91 * @return True, if so
92 */
93 static bool isHandPointing(const Vectors3& jointPositions, Line3& worldRay, const Scalar maxIndexAngle = Numeric::deg2rad(15), const Scalar minAngle = Numeric::deg2rad(35), const Scalar minTipDistance = Scalar(0.03), const Scalar maxTipDistance = Scalar(0.08));
94
95 /**
96 * Returns whether a hand is making a spreading gesture (whether the hand is flat and all fingers are spread away from each other).
97 * @param jointPositions The positions of the joints of a hand, defined in world, either XR_HAND_JOINT_COUNT_EXT positions (or zero to fail)
98 * @param isLeft True, if the hand is a left hand; False, if the hand is a right hand
99 * @param world_T_hand The resulting transformation between hand and world, with origin in the center of the hand, with y-axis along the middle finger, with z-axis upwards away from the hand, and x-axis to the right
100 * @param maxAngle The maximal angle between bones of the fingers, in radian, with range [0, PI)
101 * @param minTipDistance The minimal distance between all fingertips, in meter, with range [0, infinity)
102 * @return True, if so
103 */
104 static bool isHandSpreading(const Vectors3& jointPositions, const bool isLeft, HomogenousMatrix4& world_T_hand, const Scalar maxAngle = Numeric::deg2rad(20), const Scalar minTipDistance = Scalar(0.025));
105
106 /**
107 * Returns whether a hand is making a grab gesture (whether the hand is grabbing a ball like object).
108 * @param jointPositions The positions of the joints of a hand, defined in world, either XR_HAND_JOINT_COUNT_EXT positions (or zero to fail)
109 * @param isLeft True, if the hand is a left hand; False, if the hand is a right hand
110 * @param world_T_hand The resulting transformation between hand and world, with origin in the center of the hand, with y-axis along the middle finger, with z-axis upwards away from the hand, and x-axis to the right
111 * @param minAngle The minimal median angle between bones of the fingers, in radian, with range [0, maxAngle)
112 * @param maxAngle The maximal median angle between bones of the fingers, in radian, with range (minAngle, PI)
113 * @param minTipDistance The minimal distance between all fingertips and the thumb, in meter, with range [0, infinity)
114 * @return True, if so
115 */
116 static bool isHandGrabbing(const Vectors3& jointPositions, const bool isLeft, HomogenousMatrix4& world_T_hand, const Scalar minAngle = Numeric::deg2rad(25), const Scalar maxAngle = Numeric::deg2rad(65), const Scalar minTipDistance = Scalar(0.04));
117};
118
119}
120
121}
122
123}
124
125}
126
127}
128
129#endif // META_OCEAN_PLATFORM_META_QUEST_OPENXR_HAND_GESTURES_H
This class implements an infinite line in 3D space.
Definition Line3.h:68
static constexpr T deg2rad(const T deg)
Converts deg to rad.
Definition Numeric.h:3232
This class implements hand gestures functionalities.
Definition HandGestures.h:38
static bool isHandGrabbing(const Vectors3 &jointPositions, const bool isLeft, HomogenousMatrix4 &world_T_hand, const Scalar minAngle=Numeric::deg2rad(25), const Scalar maxAngle=Numeric::deg2rad(65), const Scalar minTipDistance=Scalar(0.04))
Returns whether a hand is making a grab gesture (whether the hand is grabbing a ball like object).
static bool isHandTunneling(const Vectors3 &jointPositions, const bool isLeft, HomogenousMatrix4 &world_T_tunnelCenter, const Scalar maxTipDistance=Scalar(0.025), const Scalar minTunnelDistance=Scalar(0.05))
Returns whether a hand is making a 'tunnel' gesture (whether thumb and index finger tips are together...
static bool isHandPinching(const Vectors3 &jointPositions, Vector3 *position=nullptr, const Scalar maxDistance=Scalar(0.025))
Returns whether a hand is pinching (whether thumb and index finger tips are together).
static Scalar distanceBetweenFingerJoints(const Vectors3 &jointPoints, const Index32 joint0, const Index32 joint1, Vector3 *position0=nullptr, Vector3 *position1=nullptr)
Determines the distance between two finger joints of a hand.
static bool determineBoneAngles(const Vectors3 &jointPoints, const Indices32 &jointIndices, Scalar *minAngle=nullptr, Scalar *maxAngle=nullptr, Scalar *medianAngle=nullptr)
Determines the minimal and maximal angle between consecutive bones.
static bool isHandSpreading(const Vectors3 &jointPositions, const bool isLeft, HomogenousMatrix4 &world_T_hand, const Scalar maxAngle=Numeric::deg2rad(20), const Scalar minTipDistance=Scalar(0.025))
Returns whether a hand is making a spreading gesture (whether the hand is flat and all fingers are sp...
static bool isHandPointing(const Vectors3 &jointPositions, Line3 &worldRay, const Scalar maxIndexAngle=Numeric::deg2rad(15), const Scalar minAngle=Numeric::deg2rad(35), const Scalar minTipDistance=Scalar(0.03), const Scalar maxTipDistance=Scalar(0.08))
Returns whether a hand is making a pointing gesture with the index finger.
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition Base.h:96
uint32_t Index32
Definition of a 32 bit index value.
Definition Base.h:84
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition Vector3.h:65
The namespace covering the entire Ocean framework.
Definition Accessor.h:15