Merge remote-tracking branch 'origin/master' into 1.2

This commit is contained in:
Wojtek Figat
2021-03-23 12:32:04 +01:00
14 changed files with 121 additions and 47 deletions

View File

@@ -697,6 +697,27 @@ namespace FlaxEngine
return result;
}
/// <summary>
/// Calculates the orientation from the direction vector.
/// </summary>
/// <param name="direction">The direction vector (normalized).</param>
/// <returns>The orientation.</returns>
public static Quaternion FromDirection(Vector3 direction)
{
Quaternion orientation;
if (Vector3.Dot(direction, Vector3.Up) >= 0.999f)
{
orientation = RotationAxis(Vector3.Left, Mathf.PiOverTwo);
}
else
{
Vector3 right = Vector3.Cross(direction, Vector3.Up);
Vector3 up = Vector3.Cross(right, direction);
orientation = LookRotation(direction, up);
}
return orientation;
}
/// <summary>
/// Performs a linear interpolation between two quaternions.
/// </summary>