|
@@ -1,5 +1,6 @@
|
|
using System;
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
using System.Runtime.InteropServices;
|
|
|
|
+using System.ComponentModel;
|
|
|
|
|
|
namespace Godot
|
|
namespace Godot
|
|
{
|
|
{
|
|
@@ -623,21 +624,31 @@ namespace Godot
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="target">The position to look at.</param>
|
|
/// <param name="target">The position to look at.</param>
|
|
/// <param name="up">The relative up direction.</param>
|
|
/// <param name="up">The relative up direction.</param>
|
|
|
|
+ /// <param name="useModelFront">
|
|
|
|
+ /// If true, then the model is oriented in reverse,
|
|
|
|
+ /// towards the model front axis (+Z, Vector3.ModelFront),
|
|
|
|
+ /// which is more useful for orienting 3D models.
|
|
|
|
+ /// </param>
|
|
/// <returns>The resulting basis matrix.</returns>
|
|
/// <returns>The resulting basis matrix.</returns>
|
|
- public static Basis LookingAt(Vector3 target, Vector3 up)
|
|
|
|
|
|
+ public static Basis LookingAt(Vector3 target, Vector3? up = null, bool useModelFront = false)
|
|
{
|
|
{
|
|
|
|
+ up ??= Vector3.Up;
|
|
#if DEBUG
|
|
#if DEBUG
|
|
if (target.IsZeroApprox())
|
|
if (target.IsZeroApprox())
|
|
{
|
|
{
|
|
throw new ArgumentException("The vector can't be zero.", nameof(target));
|
|
throw new ArgumentException("The vector can't be zero.", nameof(target));
|
|
}
|
|
}
|
|
- if (up.IsZeroApprox())
|
|
|
|
|
|
+ if (up.Value.IsZeroApprox())
|
|
{
|
|
{
|
|
throw new ArgumentException("The vector can't be zero.", nameof(up));
|
|
throw new ArgumentException("The vector can't be zero.", nameof(up));
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
- Vector3 column2 = -target.Normalized();
|
|
|
|
- Vector3 column0 = up.Cross(column2);
|
|
|
|
|
|
+ Vector3 column2 = target.Normalized();
|
|
|
|
+ if (!useModelFront)
|
|
|
|
+ {
|
|
|
|
+ column2 = -column2;
|
|
|
|
+ }
|
|
|
|
+ Vector3 column0 = up.Value.Cross(column2);
|
|
#if DEBUG
|
|
#if DEBUG
|
|
if (column0.IsZeroApprox())
|
|
if (column0.IsZeroApprox())
|
|
{
|
|
{
|
|
@@ -649,6 +660,13 @@ namespace Godot
|
|
return new Basis(column0, column1, column2);
|
|
return new Basis(column0, column1, column2);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <inheritdoc cref="LookingAt(Vector3, Nullable{Vector3}, bool)"/>
|
|
|
|
+ [EditorBrowsable(EditorBrowsableState.Never)]
|
|
|
|
+ public static Basis LookingAt(Vector3 target, Vector3 up)
|
|
|
|
+ {
|
|
|
|
+ return LookingAt(target, up, false);
|
|
|
|
+ }
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Returns the orthonormalized version of the basis matrix (useful to
|
|
/// Returns the orthonormalized version of the basis matrix (useful to
|
|
/// call occasionally to avoid rounding errors for orthogonal matrices).
|
|
/// call occasionally to avoid rounding errors for orthogonal matrices).
|