Vixen
02b45cc4
csharp
public readonly struct Quaternion

A rotation, stored as a unit quaternion. Four floats instead of a matrix's nine, no gimbal lock, and it interpolates — which is why every transform, every animation channel and every bone pose is one of these rather than Euler angles.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Composition reads left to right, matching the matrices: a * b is "rotate by a, then by b", and Matrix4x4.FromQuaternion(a * b) equals Matrix4x4.FromQuaternion(a) * Matrix4x4.FromQuaternion(b). Underneath, that is the Hamilton product with its arguments swapped; the swap lives here, once, so that no caller has to think about it.

Positive angles are counter-clockwise looking down the axis toward the origin. See Conventions.md.

Fields and properties (8)

  • public const int ComponentCount

    Number of components.

  • public readonly float X

    The X component of the vector part.

  • public readonly float Y

    The Y component of the vector part.

  • public readonly float Z

    The Z component of the vector part.

  • public readonly float W

    The scalar part.

  • public static Quaternion Identity

    The rotation that does nothing.

  • public Vector3 Xyz

    The vector part.

  • public bool IsIdentity

    Whether this is the identity rotation, to within the default tolerance.

Methods (32)

  • public Quaternion(float x, float y, float z, float w)

    Builds a quaternion from its components. Rarely what a caller wants directly.

  • public Quaternion(Vector3 vector, float scalar)

    Builds a quaternion from a vector part and a scalar part.

  • public ReadOnlySpan<float> AsSpan()

    The components as a span. Valid as long as the quaternion it came from.

  • public float Length()

    The length. Unit for any rotation; drifts from 1 as rotations accumulate.

  • public float LengthSquared()

    The squared length.

  • public float Angle()

    The angle of the rotation, in radians, in [0, π].

  • public Vector3 Axis()

    The axis of the rotation, or UnitY if there is no rotation.

  • public static Quaternion FromAxisAngle(Vector3 axis, float angle)

    The rotation of radians about .

  • public static Quaternion FromYawPitchRoll(float yaw, float pitch, float roll)

    The rotation described by three Euler angles, applied yaw then pitch then roll.

  • public static Quaternion FromToRotation(Vector3 from, Vector3 to)

    The shortest rotation taking one direction to another.

  • public static Quaternion Normalize(Quaternion value)

    The quaternion scaled to unit length; Identity if degenerate.

  • public static Quaternion Conjugate(Quaternion value)

    Negates the vector part, which for a unit quaternion is the inverse rotation.

  • public static Quaternion Inverse(Quaternion value)

    The rotation that undoes .

  • public static float Dot(Quaternion left, Quaternion right)

    The dot product, whose sign says whether two rotations take the same path.

  • public static Quaternion Concatenate(Quaternion first, Quaternion second)

    Composes two rotations: apply , then .

  • public static Vector3 Transform(Vector3 value, Quaternion rotation)

    Rotates a vector.

  • public static Quaternion Slerp(Quaternion from, Quaternion to, float amount)

    Interpolates along the shortest arc at constant angular velocity. The correct blend for two poses; Nlerp is the cheaper approximation.

  • public static Quaternion Nlerp(Quaternion from, Quaternion to, float amount)

    Interpolates linearly and renormalises. Cheaper than Slerp and visually identical for the small steps an animation blend actually takes; the angular velocity is not constant, which only shows up across a wide arc.

  • public static bool NearEqual(Quaternion left, Quaternion right, float tolerance = 1E-06)

    Whether two rotations agree to within a tolerance, component by component.

  • public static bool SameRotation(Quaternion left, Quaternion right, float tolerance = 1E-06)

    Whether two quaternions describe the same rotation, sign included or not.

  • public static Quaternion operator *(Quaternion first, Quaternion second)
  • public static bool operator ==(Quaternion left, Quaternion right)

    Exact component-wise equality, IEEE semantics. See NearEqual.

  • public static bool operator !=(Quaternion left, Quaternion right)

    The negation of op_Equality.

  • public static implicit operator Quaternion(Quaternion value)

    Converts to the BCL quaternion, which has the same layout and the same components.

  • public static implicit operator Quaternion(Quaternion value)

    Converts from the BCL quaternion.

  • public void Deconstruct(out float x, out float y, out float z, out float w)

    Splits the quaternion into its components.

  • public bool Equals(Quaternion other)

    Indicates whether the current object is equal to another object of the same type.

  • public override bool Equals(object? obj)

    Indicates whether this instance and a specified object are equal.

  • public override int GetHashCode()

    Returns the hash code for this instance.

  • public override string ToString()

    Returns the fully qualified type name of this instance.

  • public string ToString(string? format, IFormatProvider? formatProvider)

    Formats the value of the current instance using the specified format.

  • public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default(ReadOnlySpan<char>), IFormatProvider? provider = null)

    Tries to format the value of the current instance into the provided span of characters.

Used by (252, showing 40)

  • ArenaMultiplayer
  • ArenaThirdPersonShooter
  • ArenaBoxThirdPersonShooter
  • ArenaCameraOcclusionThirdPersonShooter
  • ArenaIlluminationThirdPersonShooter
  • CharacterAnimationThirdPersonShooter
  • PbrShowcaseGamePbrShowcase
  • PlayerRigThirdPersonShooter
  • SoakNetworkSoak
  • SunOrbitThirdPersonShooter
  • BulkTransformBenchmarksVixen.Benchmarks.Math
  • MatrixBenchmarksVixen.Benchmarks.Math
  • RigsVixen.Benchmarks.Animation
  • AimGoalVixen.Animation
  • AlgebraicPropertyTestsVixen.Core.Mathematics.Tests
  • AnimationChannelVixen.Rendering
  • AnimationClipVixen.Animation
  • AnimationClipContentVixen.Animation
  • AnimationCurveCompressorVixen.Animation
  • AnimatorTestsVixen.Animation.Tests
  • AttachmentSocketVixen.Animation
  • AuthoringTestsVixen.Animation.Tests
  • BehaviorVixen.Engine
  • BitExactnessTestsVixen.Net.Tests
  • BodyDescriptionVixen.Physics
  • BodyHistoryVixen.Net.Physics
  • BodyPoseVixen.Net.Physics
  • BoneTransformVixen.Animation
  • BoneTransformTestsVixen.Animation.Tests
  • CameraBlendVixen.Engine
  • CameraDampingVixen.Engine
  • CameraDampingTestsVixen.Engine.Tests
  • CameraDirectorSystemVixen.Engine
  • CameraDirectorTestsVixen.Engine.Tests
  • CameraFramingVixen.Engine
  • CameraShotVixen.Engine
  • ChainSolveRequestVixen.Animation
  • CharacterControllerVixen.Physics
  • CharacterControllerSettingsVixen.Physics
  • CharacterSceneTestsVixen.Physics.Tests