Skip to content
EvilEngine.Api.Physics

Orientation record struct

public readonly record struct Orientation

A rotation, as a quaternion in doubles on Godot’s axes. It’s a small value type, so pass it around and compare it freely.

var turned = Orientation.Yaw(90).Then(Orientation.Axis(new MapVector(1, 0, 0), Math.PI / 8));
var ahead = turned.Rotate(new MapVector(0, 0, -1));
Assembly
EvilEngine.Api
Commit
4ff877b1

Members

Orientation constructor

public Orientation(double X, double Y, double Z, double W)

Makes one from its four components. Nothing normalises them, so use Normalised if they might not be.

Identity field

public static readonly Orientation Identity

No rotation: (0, 0, 0, 1).

X property

public double X { get; init; }

The X component of the quaternion’s axis part.

Y property

public double Y { get; init; }

The Y component of the quaternion’s axis part.

Z property

public double Z { get; init; }

The Z component of the quaternion’s axis part.

W property

public double W { get; init; }

The quaternion’s scalar part.

Length property

public double Length { get; }

The quaternion’s length, 1 for a rotation.

Facing method

public static Orientation Facing(MapVector direction)

The orientation that turns a model’s forward axis, +Z, to point along a direction, keeping its up as close to the world’s up as it can.

Basis method

public static Orientation Basis(MapVector x, MapVector y, MapVector z)

The orientation whose rotation takes +X, +Y and +Z to the three given axes.

Yaw method

public static Orientation Yaw(double degrees)

A turn of degrees about +Y, the up axis, counter-clockwise seen from above.

Axis method

public static Orientation Axis(MapVector axis, double radians)

A turn of radians about axis, which doesn’t need to be unit length. A zero axis gives Identity.

Normalised method

public Orientation Normalised()

This scaled to length 1, or Identity when it’s zero.

Inverse method

public Orientation Inverse()

The rotation that undoes this one. Turning a world point by a body’s orientation’s inverse puts it in the body’s own space.

Then method

public Orientation Then(Orientation after)

This rotation followed by after.

Rotate method

public MapVector Rotate(MapVector v)

Returns v turned by this rotation.

Slerp method

public Orientation Slerp(Orientation to, double weight)

The rotation weight of the way from this one to to, 0 being this and 1 being to, along the shorter way round. Both are normalised first, so the result is a unit rotation whatever lengths it’s given. Two rotations within a hair of each other blend linearly and normalise instead.