s&box docs

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.

Broader workflow and conceptual references connected to this API.

Constructors

Showing 3 constructors

Methods

Showing 30 methods

public bool AlmostEqual(Rotation r, float delta = 1E-05)

Returns true if we're nearly equal to the passed rotation. Checks if each component is within a threshold, and handles the fact that there are two ways to represent the same rotation as a quaternion.

Parameters

  • r: The value to compare with
  • delta: Per-component threshold. Default: 1E-05

Returns

True if nearly equal

public float Angle()

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

public Angles Angles()

Return this Rotation as pitch, yaw, roll angles

public Vector3 ClosestAxis(Vector3 normal)

Will give you the axis most aligned with the given normal

public static Rotation Difference(Rotation from, Rotation to)

Returns the difference between two rotations, as a rotation

public float Distance(Rotation to)

The degree angular distance between this rotation and the target

public static Rotation FromAxis(Vector3 axis, float degrees)

Create from angle and an axis

Note

`axis` vector must be normalized before calling this method or the resulting `Rotation` will be incorrect.

public static Rotation FromPitch(float pitch)

Create a Rotation (quaternion) from pitch (degrees)

public static Rotation FromRoll(float roll)

Create a Rotation (quaternion) from roll (degrees)

public static Rotation FromToRotation(Vector3 fromDirection, Vector3 toDirection)

Returns a Rotation that rotates from one direction to another.

public static Rotation FromYaw(float yaw)

Create a Rotation (quaternion) from yaw (degrees)

public static Rotation Lerp(Rotation a, Rotation b, float frac, bool clamp = True)

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

Parameters

  • clamp: Default: True

public Rotation LerpTo(Rotation target, float frac, bool clamp = True)

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

Parameters

  • clamp: Default: True

public float Pitch()

Return this Rotation pitch

public float Roll()

Return this Rotation roll

public Rotation RotateAroundAxis(Vector3 axis, float degrees)

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

Note

`axis` vector must be normalized before calling this method or the resulting `Rotation` will be incorrect.

public static Rotation Slerp(Rotation a, Rotation b, float amount, bool clamp = True)

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

Parameters

  • clamp: Default: True

public Rotation SlerpTo(Rotation target, float frac, bool clamp = True)

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

Parameters

  • clamp: Default: True

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

Smoothly move towards the target rotation

public float Yaw()

Return this Rotation yaw

Properties

Showing 14 properties

public Vector3 Rotation.Backward { get; set; }

The backwards direction of this rotation.

public Rotation Rotation.Conjugate { get; set; }

Returns conjugate of this rotation, meaning the X Y and Z components are negated.

public Vector3 Rotation.Down { get; set; }

The downwards direction of this rotation.

public Vector3 Rotation.Forward { get; set; }

The forwards direction of this rotation.

public Rotation Rotation.Inverse { get; set; }

Returns the inverse of this rotation.

public Vector3 Rotation.Left { get; set; }

The left hand direction of this rotation.

public Rotation Rotation.Normal { get; set; }

Divides each component of the rotation by its length, normalizing the rotation.

public static Rotation Rotation.Random { get; set; }

Returns a uniformly random rotation.

public Vector3 Rotation.Right { get; set; }

The right hand direction of this rotation.

public Vector3 Rotation.Up { get; set; }

The upwards direction of this rotation.

public float Rotation.w { get; set; }

The W component of this rotation (rotation around the normal defined by X,Y,Z components).

public float Rotation.x { get; set; }

The X component of this rotation.

public float Rotation.y { get; set; }

The Y component of this rotation.

public float Rotation.z { get; set; }

The Z component of this rotation.

Metadata

FieldValue
Namespaceglobal
Typeclass
AssemblySandbox.System
Doc IDT:Rotation

On this page

Constructorspublic Rotation()public Rotation(System.Single x, System.Single y, System.Single z, System.Single w)public Rotation(Vector3 v, System.Single w)Methodspublic System.Boolean AlmostEqual(Rotation r, System.Single delta = 1E-05)public System.Single Angle()public Angles Angles()public Rotation Clamp(Rotation to, System.Single degrees, System.Single change)public Rotation Clamp(Rotation to, System.Single degrees)public Vector3 ClosestAxis(Vector3 normal)public static Rotation Difference(Rotation from, Rotation to)public System.Single Distance(Rotation to)public static Rotation From(Angles angles)public static Rotation From(System.Single pitch, System.Single yaw, System.Single roll)public static Rotation FromAxis(Vector3 axis, System.Single degrees)public static Rotation FromPitch(System.Single pitch)public static Rotation FromRoll(System.Single roll)public static Rotation FromToRotation(Vector3 fromDirection, Vector3 toDirection)public static Rotation FromYaw(System.Single yaw)public static Rotation Lerp(Rotation a, Rotation b, System.Single frac, System.Boolean clamp = True)public Rotation LerpTo(Rotation target, System.Single frac, System.Boolean clamp = True)public static Rotation LookAt(Vector3 forward, Vector3 up)public static Rotation LookAt(Vector3 forward)public static override Rotation Parse(System.String str, System.IFormatProvider provider)public static Rotation Parse(System.String str)public System.Single Pitch()public System.Single Roll()public Rotation RotateAroundAxis(Vector3 axis, System.Single degrees)public static Rotation Slerp(Rotation a, Rotation b, System.Single amount, System.Boolean clamp = True)public Rotation SlerpTo(Rotation target, System.Single frac, System.Boolean clamp = True)public static Rotation SmoothDamp(Rotation current, Rotation target, Vector3 velocity, System.Single smoothTime, System.Single deltaTime)public static System.Boolean TryParse(System.String str, Rotation result)public static override System.Boolean TryParse(System.String str, System.IFormatProvider provider, Rotation result)public System.Single Yaw()Propertiespublic Vector3 Rotation.Backward { get; set; }public Rotation Rotation.Conjugate { get; set; }public Vector3 Rotation.Down { get; set; }public Vector3 Rotation.Forward { get; set; }public Rotation Rotation.Inverse { get; set; }public Vector3 Rotation.Left { get; set; }public Rotation Rotation.Normal { get; set; }public static Rotation Rotation.Random { get; set; }public Vector3 Rotation.Right { get; set; }public Vector3 Rotation.Up { get; set; }public System.Single Rotation.w { get; set; }public System.Single Rotation.x { get; set; }public System.Single Rotation.y { get; set; }public System.Single Rotation.z { get; set; }Metadata