RotateToLookAtUserBillboardSample
/**
* A sample demonstrating how to combine [rotateToLookAtUser] and [gravityAligned] to achieve
* billboard behavior where the content automatically rotates to face the user. [gravityAligned]
* ensures the panel stays vertically upright and does not tilt forward or backward, even if the
* user views it from a high or low angle.
*/
@Sampled
@OptIn(ExperimentalRotateToLookAtUserApi::class)
@Composable
public fun RotateToLookAtUserBillboardSample() {
Subspace {
SpatialPanel(modifier = SubspaceModifier.rotateToLookAtUser().gravityAligned()) {
Text("I always face you and stay upright!")
}
}
}
/**
* A sample showing how to use rotation constraints with [rotateToLookAtUser]. By providing pitch
* limits and enabling/disabling yaw tracking, you can restrict how much the content rotates to face
* the user.
*/
RotateToLookAtUserWithConstraintsSample
@Sampled
@OptIn(ExperimentalRotateToLookAtUserApi::class)
@Composable
public fun RotateToLookAtUserWithConstraintsSample() {
Subspace {
SpatialPanel(
modifier =
SubspaceModifier.rotateToLookAtUser(
isYawUpdateEnabled = true,
pitchLimits = PitchLimits(minimumPitch = -15f, maximumPitch = 15f),
)
) {
Text("I track your yaw, but my pitch is restricted between -15 and 15 degrees.")
}
}
}
/**
* A sample showing how [rotateToLookAtUser] behaves within a parent spatial layout. In this
* example, even if the [SpatialBox] is moved or rotated, the panel with [rotateToLookAtUser] will
* independently calculate its local rotation to ensure it remains facing the user.
*/
RotateToLookAtUserUnderParentContainerSample
@Sampled
@OptIn(ExperimentalRotateToLookAtUserApi::class)
@Composable
public fun RotateToLookAtUserUnderParentContainerSample() {
val parentRotation = Quaternion.fromEulerAngles(pitch = 40f, yaw = 30f, roll = 20f)
Subspace {
SpatialBox(SubspaceModifier.rotate(parentRotation)) {
// This panel will rotate to face the user regardless of where
// the parent SpatialBox is placed in the ActivitySpace.
SpatialPanel(modifier = SubspaceModifier.rotateToLookAtUser()) {
Text("I'm inside a SpatialBox, but I still see you!")
}
}
}
}