Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Quat

struct Quat { x: float, y: float, z: float, w: float }

A rotation in 3D space, stored as a quaternion with float components x, y, z, and w. Scripts usually create one with Quat::from_rotation_z and pass it to the host, such as for the rotation of a Bevy transform.

Implementations

from_rotation_z

fn from_rotation_z(radians: float) -> Quat

Creates a rotation of radians around the z axis. For 2D work, this is a turn within the x-y plane.

use std::math::{PI, Quat};

let quarter_turn = Quat::from_rotation_z(PI / 2.0);

rotate_z

fn rotate_z(self, radians: float) -> Quat

Returns the rotation turned a further radians around its own z axis.

use std::math::{PI, Quat};

let facing = Quat::from_rotation_z(0.0);
let turned = facing.rotate_z(PI / 2.0); // a quarter turn