Rotation

data class Rotation(val x: Float, val y: Float, val z: Float, val w: Float)

A 3-D rotation, stored as a unit quaternion. See Position for the rationale behind the distinct type — the same one applies doubly here, since filament-utils' Quaternion has mutable components and so is an unstable Compose input.

Build one with axisAngle or euler rather than the raw component constructor, and combine with * (right operand applied first):

Cube(rotation = Rotation.axisAngle(Direction.Up, degrees = spin))
Cube(rotation = Rotation.euler(yaw = 45f) * Rotation.euler(pitch = 30f))

// Aim an entity at a target, and blend towards a new pose over time
Cube(rotation = Rotation.lookTowards(target - turret))
Cube(rotation = Rotation.slerp(from, to, t))

fromTo, lookTowards, slerp, nlerp, toEuler, angleTo and normalized cover the usual scene work. For anything beyond them — matrix interop, swizzles, custom interpolation — hop to filament-utils' Quaternion and back; the two are the same four floats and the conversion is lossless:

val blended = Rotation(myOwnInterpolation(a.toQuaternion(), b.toQuaternion()))
val asRotation = someQuaternion.toRotation() // or Rotation(someQuaternion)

Equality is component-wise, as for any data class — which is not the same as "same orientation": r and its all-components-negated twin turn an entity to the identical pose but compare unequal, and accumulated products drift. That is what you want for Compose (equal values let a composable skip), but to ask whether two orientations agree use angleTo against a tolerance rather than ==.

Constructors

Link copied to clipboard
constructor(x: Float, y: Float, z: Float, w: Float)
constructor(q: Quaternion)

From a filament-utils Quaternion.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val w: Float
Link copied to clipboard
val x: Float
Link copied to clipboard
val y: Float
Link copied to clipboard
val z: Float

Functions

Link copied to clipboard
fun angleTo(other: Rotation): Float

The smallest angle in degrees between this orientation and other.

Link copied to clipboard

The inverse rotation — undoes this one. Exact for a drifted rotation too, where the bare conjugate would leave the length error behind.

Link copied to clipboard

Unit-length copy. Use it to shed drift after accumulating many products.

Link copied to clipboard
operator fun times(d: Direction): Direction

This rotation applied to a direction vector.

operator fun times(other: Rotation): Rotation

Applies other and then this rotation (quaternion product, not commutative).

Link copied to clipboard

Euler angles in degrees, as Direction(pitch, yaw, roll) about X/Y/Z. The inverse of euler — useful for debug readouts and for clamping an axis (e.g. pitch to ±89°).

Link copied to clipboard
Link copied to clipboard

As a column-major 3×3 rotation matrix (9 floats) — the shape Filament's builders take, e.g. IndirectLight.Builder.rotation.