コード例 #1
0
    //For all rotations in 2D (and a subset in 3D) calculate the pivot of this transformation
    public static Vector3 calculatePivotPoint(Vector3 deltaPosition, Quaternion deltaRotation)
    {
        Vector3    axis; float angle; deltaRotation.ToAngleAxis(out angle, out axis);
        Vector3    halfAngleDirection = Vector3.Cross(axis, deltaPosition);
        Quaternion halfRotation       = Quaternion.Slerp(Quaternion.identity, deltaRotation, 0.5f);
        Ray        preRay             = new Ray(Vector3.zero, Quaternion.Inverse(halfRotation) * halfAngleDirection);
        Ray        postRay            = new Ray(deltaPosition, halfRotation * halfAngleDirection);

        return(Constraints.ClosestPointOnRayToRay(preRay, postRay));
    }