# Orientation record struct

> 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.

Namespace `EvilEngine.Api.Physics`, assembly `EvilEngine.Api`. Engine commit 4ff877b1.

```csharp
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.

```csharp
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));
```

## Members

### Orientation (constructor)

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

Makes one from its four components. Nothing normalises them, so use [Normalised](#normalised) if they might not be.

### Identity (field)

```csharp
public static readonly Orientation Identity
```

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

### X (property)

```csharp
public double X { get; init; }
```

The X component of the quaternion's axis part.

### Y (property)

```csharp
public double Y { get; init; }
```

The Y component of the quaternion's axis part.

### Z (property)

```csharp
public double Z { get; init; }
```

The Z component of the quaternion's axis part.

### W (property)

```csharp
public double W { get; init; }
```

The quaternion's scalar part.

### Length (property)

```csharp
public double Length { get; }
```

The quaternion's length, 1 for a rotation.

### Facing (method)

```csharp
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)

```csharp
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)

```csharp
public static Orientation Yaw(double degrees)
```

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

### Axis (method)

```csharp
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](#identity).

### Normalised (method)

```csharp
public Orientation Normalised()
```

This scaled to length 1, or [Identity](#identity) when it's zero.

### Inverse (method)

```csharp
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)

```csharp
public Orientation Then(Orientation after)
```

This rotation followed by `after`.

### Rotate (method)

```csharp
public MapVector Rotate(MapVector v)
```

Returns `v` turned by this rotation.

### Slerp (method)

```csharp
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.
