struct
Eagle::Quat
- Eagle::Quat
- Struct
- Value
- Object
Overview
A unit quaternion: the way Eagle stores 3D rotations.
You rarely touch the four components. Build rotations from something readable, combine them by multiplication, and apply them to vectors:
.from_axis_angle(Vec3::UP, angle)spins around an axis..from_euler(pitch, yaw, roll)takes angles in radians.look_rotation(dir)faces along a direction.a * bapplies b first, then a.q * vrotates the vector v.#slerpblends smoothly between two orientations.
Node3D#rotation is a Quat, and Node3D has helpers like rotate_y and look_at
that cover most needs.
spin = Quat.from_axis_angle(Vec3::UP, Mathf.deg2rad(90))
spin * Vec3::FORWARD # => roughly (-1, 0, 0): forward turned left
from = Quat.look_rotation(v3(0, 0, -1))
to = Quat.look_rotation(v3(1, 0, 0))
halfway = from.slerp(to, 0.5)
node = Node3D.new
node.rotation = halfway
Defined in:
eagle/math/quat.crConstant Summary
-
IDENTITY =
Quat.new -
No rotation.
Constructors
-
.from_axis_angle(axis : Vec3, rad : Number) : Quat
A rotation of rad radians around axis.
-
.from_euler(pitch : Number, yaw : Number, roll : Number) : Quat
Builds a rotation from Euler angles in radians.
-
.from_euler(v : Vec3) : Quat
.from_eulerwith(pitch, yaw, roll)packed into aVec3. -
.identity : Quat
Returns
IDENTITY. -
.look_rotation(forward : Vec3, up : Vec3 = Vec3::UP) : Quat
A rotation whose forward (-Z) points along forward, keeping up as close to up as possible.
-
.new(x : Number, y : Number, z : Number, w : Number)
Creates a quaternion from raw components.
-
.new
Creates the identity rotation.
Instance Method Summary
-
#*(o : Quat) : Quat
Combines rotations:
a * bapplies b first, then a. -
#*(v : Vec3) : Vec3
Rotates the vector v.
-
#/(s : Number) : Quat
Divides every component.
-
#==(o : Quat) : Bool
Exact equality.
-
#approx?(o : Quat, eps = 1e-4) : Bool
True when the components are within eps.
-
#conjugate : Quat
The conjugate.
-
#dot(o : Quat) : Float32
Dot product.
-
#forward : Vec3
This rotation's forward direction: where -Z ends up.
-
#inverse : Quat
The rotation that undoes this one.
-
#length : Float32
Length.
-
#length_squared : Float32
Squared length.
-
#normalized : Quat
Rescales to unit length.
-
#right : Vec3
This rotation's right direction: where +X ends up.
-
#slerp(o : Quat, t : Number) : Quat
Spherical interpolation, which blends orientations at constant angular speed.
-
#to_euler : Vec3
Euler angles
(pitch, yaw, roll)in radians, the approximate inverse of.from_euler. -
#to_mat4 : Mat4
The rotation as a 4x4 matrix.
-
#to_s(io : IO) : Nil
Same as
#inspect(io). -
#up : Vec3
This rotation's up direction: where +Y ends up.
-
#w : Float32
Scalar part.
-
#w=(w : Float32)
Scalar part.
-
#x : Float32
Vector part x.
-
#x=(x : Float32)
Vector part x.
-
#y : Float32
Vector part y.
-
#y=(y : Float32)
Vector part y.
-
#z : Float32
Vector part z.
-
#z=(z : Float32)
Vector part z.
Constructor Detail
A rotation of rad radians around axis. The axis doesn't need to be normalized.
Builds a rotation from Euler angles in radians. Yaw turns around Y, pitch around X and roll around Z, applied as yaw, then pitch, then roll. This matches how an FPS camera turns.
A rotation whose forward (-Z) points along forward, keeping up as close to up as possible.
Creates a quaternion from raw components. Prefer the named constructors.
Instance Method Detail
Spherical interpolation, which blends orientations at constant angular speed. Takes the short way round.