docs.unity3d.com
    Show / Hide Table of Contents

    Class UnityQuaternionExtensions

    Extensions to the Quaternion class, usen in various places by Cinemachine

    Inheritance
    Object
    UnityQuaternionExtensions
    Namespace: Cinemachine.Utility
    Syntax
    public static class UnityQuaternionExtensions

    Methods

    ApplyCameraRotation(Quaternion, Vector2, Vector3)

    Apply rotations, first about world up, then about (travelling) local right. rot.y is rotation about worldUp, and rot.x is second rotation, about local right.

    Declaration
    public static Quaternion ApplyCameraRotation(this Quaternion orient, Vector2 rot, Vector3 worldUp)
    Parameters
    Type Name Description
    Quaternion orient
    Vector2 rot

    Vector2.y is rotation about worldUp, and Vector2.x is second rotation, about local right.

    Vector3 worldUp

    Which way is up

    Returns
    Type Description
    Quaternion

    Result rotation after the input is applied to the input quaternion

    GetCameraRotationToTarget(Quaternion, Vector3, Vector3)

    Get the rotations, first about world up, then about (travelling) local right, necessary to align the quaternion's forward with the target direction. This represents the tripod head movement needed to look at the target. This formulation makes it easy to interpolate without introducing spurious roll.

    Declaration
    public static Vector2 GetCameraRotationToTarget(this Quaternion orient, Vector3 lookAtDir, Vector3 worldUp)
    Parameters
    Type Name Description
    Quaternion orient
    Vector3 lookAtDir

    The worldspace target direction in which we want to look

    Vector3 worldUp

    Which way is up. Must have a length of 1.

    Returns
    Type Description
    Vector2

    Vector2.y is rotation about worldUp, and Vector2.x is second rotation, about local right.

    Normalized(Quaternion)

    Normalize a quaternion

    Declaration
    public static Quaternion Normalized(this Quaternion q)
    Parameters
    Type Name Description
    Quaternion q
    Returns
    Type Description
    Quaternion

    The normalized quaternion. Unit length is 1.

    SlerpWithReferenceUp(Quaternion, Quaternion, Single, Vector3)

    This is a slerp that mimics a camera operator's movement in that it chooses a path that avoids the lower hemisphere, as defined by the up param

    Declaration
    public static Quaternion SlerpWithReferenceUp(Quaternion qA, Quaternion qB, float t, Vector3 up)
    Parameters
    Type Name Description
    Quaternion qA

    First direction

    Quaternion qB

    Second direction

    Single t

    Interpolation amount

    Vector3 up

    Defines the up direction. Must have a length of 1.

    Returns
    Type Description
    Quaternion

    Interpolated quaternion

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023