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.
*/
@Composable
public fun RotateToLookAtUserBillboardSample() {
Subspace {
SpatialPanel(modifier = SubspaceModifier.rotateToLookAtUser().gravityAligned()) {
Text("I always face you and stay upright!")
}
}
}
RotateToLookAtUserUnderParentContainerSample
/**
* 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.
*/
@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!")
}
}
}
}
RotateToLookAtUserWithUpVectorSample
/**
* A sample showing how to use the 'upDirection' parameter. By providing a custom up vector, you can
* change the reference frame for the content's orientation.
*/
@Composable
public fun RotateToLookAtUserWithUpVectorSample() {
Subspace {
SpatialPanel(
modifier =
SubspaceModifier.rotateToLookAtUser(
upDirection = Vector3(0f, 1f, 2f)
) // A slightly tilted "up" reference
) {
Text("I have a custom 'Up' vector.")
}
}
}