Api Rotation
struct

Rotation

public sealed struct Rotation

Represents a Quaternion rotation. Can be interpreted as a direction unit vector (x,y,z) + rotation around the direction vector (w) which represents the up direction. Unlike Angles, this cannot store multiple revolutions around an axis.

Constructors

Rotation()

Initializes this rotation to identity.

Rotation(Single x, Single y, Single z, Single w)

Initializes the rotation from given components.

x — The X component.
y — The Y component.
z — The Z component.
w — The W component.
Rotation(Vector3 v, Single w)

Initializes the rotation from a normal vector + rotation around it.

v — The normal vector.
w — The W component, aka rotation around the normal vector.

Properties

Name Type Description
x Single The X component of this rotation.
y Single The Y component of this rotation.
z Single The Z component of this rotation.
w Single The W component of this rotation (rotation around the normal defined by X,Y,Z components).
Forward Vector3 The forwards direction of this rotation.
Backward Vector3 The backwards direction of this rotation.
Right Vector3 The right hand direction of this rotation.
Left Vector3 The left hand direction of this rotation.
Up Vector3 The upwards direction of this rotation.
Down Vector3 The downwards direction of this rotation.
Inverse Rotation Returns the inverse of this rotation.
Normal Rotation Divides each component of the rotation by its length, normalizing the rotation.
Conjugate Rotation Returns conjugate of this rotation, meaning the X Y and Z components are negated.
Random static Rotation Returns a uniformly random rotation.

Methods

static Rotation FromAxis(Vector3 axis, Single degrees)

Create from angle and an axis

static Rotation From(Angles angles)

Create a Rotation (quaternion) from Angles

static Rotation From(Single pitch, Single yaw, Single roll)

Create a Rotation (quaternion) from pitch yaw roll (degrees)

static Rotation FromPitch(Single pitch)

Create a Rotation (quaternion) from pitch (degrees)

static Rotation FromYaw(Single yaw)

Create a Rotation (quaternion) from yaw (degrees)

static Rotation FromRoll(Single roll)

Create a Rotation (quaternion) from roll (degrees)

static Rotation LookAt(Vector3 forward, Vector3 up)

Create a Rotation (quaternion) from a forward and up vector

static Rotation LookAt(Vector3 forward)

Create a Rotation (quaternion) from a forward vector, using Up as an up vector. This won't give nice results if is very close to straight up or down, if that can happen you should use LookAt(Vector3,Vector3).

static Rotation Difference(Rotation from, Rotation to)

Returns the difference between two rotations, as a rotation

Single Distance(Rotation to)

The degree angular distance between this rotation and the target

Single Angle()

Returns the turn length of this rotation (from identity) in degrees

Angles Angles()

Return this Rotation as pitch, yaw, roll angles

Single Pitch()

Return this Rotation pitch

Single Yaw()

Return this Rotation yaw

Single Roll()

Return this Rotation roll

static Rotation Lerp(Rotation a, Rotation b, Single frac, Boolean clamp = True)

Perform a linear interpolation from a to b by given amount.

static Rotation Slerp(Rotation a, Rotation b, Single amount, Boolean clamp = True)

Perform a spherical interpolation from a to b by given amount.

Rotation LerpTo(Rotation target, Single frac, Boolean clamp = True)

Perform a linear interpolation from this rotation to a target rotation by given amount.

Rotation SlerpTo(Rotation target, Single frac, Boolean clamp = True)

Perform a spherical interpolation from this rotation to a target rotation by given amount.

Rotation Clamp(Rotation to, Single degrees)

Clamp to within degrees of passed rotation

Rotation Clamp(Rotation to, Single degrees, Single change)

Clamp to within degrees of passed rotation. Also pases out the change in degrees, if any.

Rotation RotateAroundAxis(Vector3 axis, Single degrees)

A convenience function that rotates this rotation around a given axis given amount of degrees

static Rotation SmoothDamp(Rotation current, Rotation target, Vector3 velocity, Single smoothTime, Single deltaTime)

Smoothly move towards the target rotation

Vector3 ClosestAxis(Vector3 normal)

Will give you the axis most aligned with the given normal

static Rotation FromToRotation(Vector3 fromDirection, Vector3 toDirection)

Returns a Rotation that rotates from one direction to another.

static Rotation Parse(String str)

Given a string, try to convert this into a quaternion rotation. The format is "x,y,z,w"

static override Rotation Parse(String str, IFormatProvider provider)
static Boolean TryParse(String str, Rotation result)
static override Boolean TryParse(String str, IFormatProvider provider, Rotation result)
Boolean AlmostEqual(Rotation r, Single delta = 0.0001)

Returns true if we're nearly equal to the passed rotation.

r — The value to compare with
delta — The max difference between component values
returns — True if nearly equal

Fields

Name Type Description
Identity static Rotation A rotation that represents no rotation.
Assembly: Sandbox.System Full Name: Rotation