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