Rotationclass

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.

objectRotation
Namespace
global
Assembly
Sandbox.System
Declaration
public sealed struct Rotation

Constructors3

Showing 3 constructors

Methods30

Showing 30 methods

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

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.

ParameterTypeDescription
rRotationThe value to compare with
delta = 1E-05floatPer-component threshold.
Returns:boolTrue if nearly equal

public float Angle()PUBLIC

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

Returns:float

public Angles Angles()PUBLIC

Return this Rotation as pitch, yaw, roll angles

Returns:Angles

public Vector3 ClosestAxis(Vector3 normal)PUBLIC

Will give you the axis most aligned with the given normal

ParameterTypeDescription
normalVector3
Returns:Vector3

public float Distance(Rotation to)PUBLIC

The degree angular distance between this rotation and the target

ParameterTypeDescription
toRotation
Returns:float

public static Rotation FromAxis(Vector3 axis, float degrees)PUBLICSTATIC

Create from angle and an axis

Note

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

ParameterTypeDescription
axisVector3
degreesfloat
Returns:Rotation

public static Rotation FromPitch(float pitch)PUBLICSTATIC

Create a Rotation (quaternion) from pitch (degrees)

ParameterTypeDescription
pitchfloat
Returns:Rotation

public static Rotation FromRoll(float roll)PUBLICSTATIC

Create a Rotation (quaternion) from roll (degrees)

ParameterTypeDescription
rollfloat
Returns:Rotation

public static Rotation FromToRotation(Vector3 fromDirection, Vector3 toDirection)PUBLICSTATIC

Returns a Rotation that rotates from one direction to another.

ParameterTypeDescription
fromDirectionVector3
toDirectionVector3
Returns:Rotation

public static Rotation FromYaw(float yaw)PUBLICSTATIC

Create a Rotation (quaternion) from yaw (degrees)

ParameterTypeDescription
yawfloat
Returns:Rotation

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

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

ParameterTypeDescription
aRotation
bRotation
fracfloat
clamp = Truebool
Returns:Rotation

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

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

ParameterTypeDescription
targetRotation
fracfloat
clamp = Truebool
Returns:Rotation

public float Pitch()PUBLIC

Return this Rotation pitch

Returns:float

public float Roll()PUBLIC

Return this Rotation roll

Returns:float

public Rotation RotateAroundAxis(Vector3 axis, float degrees)PUBLIC

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.

ParameterTypeDescription
axisVector3
degreesfloat
Returns:Rotation

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

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

ParameterTypeDescription
aRotation
bRotation
amountfloat
clamp = Truebool
Returns:Rotation

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

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

ParameterTypeDescription
targetRotation
fracfloat
clamp = Truebool
Returns:Rotation

public float Yaw()PUBLIC

Return this Rotation yaw

Returns:float

Properties14

Showing 14 properties

public Vector3 Rotation.Backward { get; set; }PUBLICGETSET

The backwards direction of this rotation.

Returns:Vector3

public Rotation Rotation.Conjugate { get; set; }PUBLICGETSET

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

Returns:Rotation

public Vector3 Rotation.Down { get; set; }PUBLICGETSET

The downwards direction of this rotation.

Returns:Vector3

public Vector3 Rotation.Forward { get; set; }PUBLICGETSET

The forwards direction of this rotation.

Returns:Vector3

public Vector3 Rotation.Left { get; set; }PUBLICGETSET

The left hand direction of this rotation.

Returns:Vector3

public Rotation Rotation.Normal { get; set; }PUBLICGETSET

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

Returns:Rotation

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

Returns a uniformly random rotation.

Returns:Rotation

public Vector3 Rotation.Right { get; set; }PUBLICGETSET

The right hand direction of this rotation.

Returns:Vector3

public float Rotation.w { get; set; }PUBLICGETSET

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

Returns:float

public float Rotation.x { get; set; }PUBLICGETSET

The X component of this rotation.

Returns:float

public float Rotation.y { get; set; }PUBLICGETSET

The Y component of this rotation.

Returns:float

public float Rotation.z { get; set; }PUBLICGETSET

The Z component of this rotation.

Returns:float

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