Skip to content

Commit f7e08bd

Browse files
committed
Add snippet that demonstrates how to detect a secondary hand
1 parent 8ea310f commit f7e08bd

File tree

1 file changed

+12
-0
lines changed
  • xr/src/main/java/com/example/xr/arcore

1 file changed

+12
-0
lines changed

xr/src/main/java/com/example/xr/arcore/Hands.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.example.xr.arcore
1818

19+
import android.app.Activity
1920
import androidx.activity.ComponentActivity
2021
import androidx.lifecycle.lifecycleScope
2122
import androidx.xr.arcore.Hand
@@ -30,6 +31,7 @@ import androidx.xr.runtime.math.Pose
3031
import androidx.xr.runtime.math.Quaternion
3132
import androidx.xr.runtime.math.Vector3
3233
import androidx.xr.scenecore.scene
34+
import kotlinx.coroutines.flow.Flow
3335
import kotlinx.coroutines.launch
3436

3537
fun ComponentActivity.configureSession(session: Session) {
@@ -64,6 +66,16 @@ fun ComponentActivity.collectHands(session: Session) {
6466
}
6567
}
6668

69+
fun secondaryHandDetection(activity: Activity, session: Session) {
70+
fun detectGesture(handState: Flow<Hand.State>) {}
71+
// [START androidxr_arcore_hand_handedness]
72+
val handedness = Hand.getHandedness(activity.contentResolver)
73+
val secondaryHand = if (handedness == Hand.Handedness.LEFT) Hand.right(session) else Hand.left(session)
74+
val handState = secondaryHand?.state ?: return
75+
detectGesture(handState)
76+
// [END androidxr_arcore_hand_handedness]
77+
}
78+
6779
fun ComponentActivity.renderPlanetAtHandPalm(leftHandState: Hand.State) {
6880
val session: Session = null!!
6981
val palmEntity: GltfEntity = null!!

0 commit comments

Comments
 (0)