@@ -30,6 +30,7 @@ import androidx.xr.runtime.internal.GltfEntity
3030import androidx.xr.runtime.math.Pose
3131import androidx.xr.runtime.math.Quaternion
3232import androidx.xr.runtime.math.Vector3
33+ import androidx.xr.runtime.math.toRadians
3334import androidx.xr.scenecore.scene
3435import kotlinx.coroutines.flow.Flow
3536import kotlinx.coroutines.launch
@@ -117,3 +118,27 @@ fun ComponentActivity.renderPlanetAtFingerTip(rightHandState: Hand.State) {
117118 indexFingerEntity.setPose(Pose (position, rotation))
118119 // [END androidxr_arcore_hand_entityAtIndexFingerTip]
119120}
121+
122+ private fun detectPinch (session : Session , handState : Hand .State ): Boolean {
123+ // [START androidxr_arcore_hand_pinch_gesture]
124+ val thumbTip = handState.handJoints[HandJointType .THUMB_TIP ] ? : return false
125+ val thumbTipPose = session.scene.perceptionSpace.transformPoseTo(thumbTip, session.scene.activitySpace)
126+ val indexTip = handState.handJoints[HandJointType .INDEX_TIP ] ? : return false
127+ val indexTipPose = session.scene.perceptionSpace.transformPoseTo(indexTip, session.scene.activitySpace)
128+ return Vector3 .distance(thumbTipPose.translation, indexTipPose.translation) < 0.05
129+ // [END androidxr_arcore_hand_pinch_gesture]
130+ }
131+
132+ private fun detectStop (session : Session , handState : Hand .State ): Boolean {
133+ // [START androidxr_arcore_hand_stop_gesture]
134+ val threshold = toRadians(angleInDegrees = 30f )
135+ fun pointingInSameDirection (joint1 : HandJointType , joint2 : HandJointType ): Boolean {
136+ val forward1 = handState.handJoints[joint1]?.forward ? : return false
137+ val forward2 = handState.handJoints[joint2]?.forward ? : return false
138+ return Vector3 .angleBetween(forward1, forward2) < threshold
139+ }
140+ return pointingInSameDirection(HandJointType .INDEX_PROXIMAL , HandJointType .INDEX_TIP ) &&
141+ pointingInSameDirection(HandJointType .MIDDLE_PROXIMAL , HandJointType .MIDDLE_TIP ) &&
142+ pointingInSameDirection(HandJointType .RING_PROXIMAL , HandJointType .RING_TIP )
143+ // [END androidxr_arcore_hand_stop_gesture]
144+ }
0 commit comments