From 5de034f0736a40149481db87375af3a06d0a5fa4 Mon Sep 17 00:00:00 2001 From: Nejcraft Date: Sat, 20 Feb 2021 14:20:26 +0100 Subject: [PATCH 1/4] Add some defaults to Quaternion helpers --- Source/Engine/Core/Math/Quaternion.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Core/Math/Quaternion.cs b/Source/Engine/Core/Math/Quaternion.cs index 938bf48b1..ed09e7307 100644 --- a/Source/Engine/Core/Math/Quaternion.cs +++ b/Source/Engine/Core/Math/Quaternion.cs @@ -975,7 +975,7 @@ namespace FlaxEngine /// The camera look-at target. /// The camera's up vector. /// The created look-at quaternion. - public static Quaternion LookAt(Vector3 eye, Vector3 target, Vector3 up) + public static Quaternion LookAt(Vector3 eye, Vector3 target, Vector3 up = Vector3.Up) { LookAt(ref eye, ref target, ref up, out var result); return result; @@ -999,7 +999,7 @@ namespace FlaxEngine /// The camera's forward direction. /// The camera's up vector. /// The created look-at quaternion. - public static Quaternion RotationLookAt(Vector3 forward, Vector3 up) + public static Quaternion RotationLookAt(Vector3 forward, Vector3 up = Vector3.Up) { RotationLookAt(ref forward, ref up, out var result); return result; @@ -1011,7 +1011,7 @@ namespace FlaxEngine /// The forward direction. Direction to orient towards. /// Up direction. Constrains y axis orientation to a plane this vector lies on. This rule might be broken if forward and up direction are nearly parallel. /// The calculated quaternion. - public static Quaternion LookRotation(Vector3 forward, Vector3 up) + public static Quaternion LookRotation(Vector3 forward, Vector3 up = Vector3.Up) { LookRotation(ref forward, ref up, out var result); return result; From 2f0c96abe209afa50b76eeca8a645b78aa47f8f1 Mon Sep 17 00:00:00 2001 From: Nejcraft Date: Sat, 20 Feb 2021 14:52:02 +0100 Subject: [PATCH 2/4] now it'll work --- Source/Engine/Core/Math/Quaternion.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Core/Math/Quaternion.cs b/Source/Engine/Core/Math/Quaternion.cs index ed09e7307..19eb199fe 100644 --- a/Source/Engine/Core/Math/Quaternion.cs +++ b/Source/Engine/Core/Math/Quaternion.cs @@ -975,8 +975,10 @@ namespace FlaxEngine /// The camera look-at target. /// The camera's up vector. /// The created look-at quaternion. - public static Quaternion LookAt(Vector3 eye, Vector3 target, Vector3 up = Vector3.Up) + public static Quaternion LookAt(Vector3 eye, Vector3 target, Vector3 up = null) { + if(up == null) + up = Vector3.Up; LookAt(ref eye, ref target, ref up, out var result); return result; } @@ -999,8 +1001,10 @@ namespace FlaxEngine /// The camera's forward direction. /// The camera's up vector. /// The created look-at quaternion. - public static Quaternion RotationLookAt(Vector3 forward, Vector3 up = Vector3.Up) + public static Quaternion RotationLookAt(Vector3 forward, Vector3 up = null) { + if(up == null) + up = Vector3.Up; RotationLookAt(ref forward, ref up, out var result); return result; } @@ -1011,8 +1015,10 @@ namespace FlaxEngine /// The forward direction. Direction to orient towards. /// Up direction. Constrains y axis orientation to a plane this vector lies on. This rule might be broken if forward and up direction are nearly parallel. /// The calculated quaternion. - public static Quaternion LookRotation(Vector3 forward, Vector3 up = Vector3.Up) + public static Quaternion LookRotation(Vector3 forward, Vector3 up = null) { + if(up == null) + up = Vector3.Up; LookRotation(ref forward, ref up, out var result); return result; } From 3da17918aacacdf16895a32231c571a55b691d53 Mon Sep 17 00:00:00 2001 From: Nejcraft Date: Sat, 20 Feb 2021 14:58:05 +0100 Subject: [PATCH 3/4] Overloaded --- Source/Engine/Core/Math/Quaternion.cs | 40 ++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/Source/Engine/Core/Math/Quaternion.cs b/Source/Engine/Core/Math/Quaternion.cs index 19eb199fe..fb763154e 100644 --- a/Source/Engine/Core/Math/Quaternion.cs +++ b/Source/Engine/Core/Math/Quaternion.cs @@ -967,7 +967,17 @@ namespace FlaxEngine Matrix3x3.LookAt(ref eye, ref target, ref up, out var matrix); RotationMatrix(ref matrix, out result); } - + + /// + /// Creates a left-handed, look-at quaternion. + /// + /// The position of the viewer's eye. + /// The camera look-at target. + /// The created look-at quaternion. + public static Quaternion LookAt(Vector3 eye, Vector3 target){ + return LookAt(eye, target, Vector3.Up); + } + /// /// Creates a left-handed, look-at quaternion. /// @@ -975,10 +985,8 @@ namespace FlaxEngine /// The camera look-at target. /// The camera's up vector. /// The created look-at quaternion. - public static Quaternion LookAt(Vector3 eye, Vector3 target, Vector3 up = null) + public static Quaternion LookAt(Vector3 eye, Vector3 target, Vector3 up) { - if(up == null) - up = Vector3.Up; LookAt(ref eye, ref target, ref up, out var result); return result; } @@ -995,20 +1003,38 @@ namespace FlaxEngine LookAt(ref eye, ref forward, ref up, out result); } + /// + /// Creates a left-handed, look-at quaternion. + /// + /// The camera's forward direction. + /// The created look-at quaternion. + public static Quaternion RotationLookAt(Vector3 forward) + { + return RotationLookAt(forward, Vector3.Up); + } + /// /// Creates a left-handed, look-at quaternion. /// /// The camera's forward direction. /// The camera's up vector. /// The created look-at quaternion. - public static Quaternion RotationLookAt(Vector3 forward, Vector3 up = null) + public static Quaternion RotationLookAt(Vector3 forward, Vector3 up) { - if(up == null) - up = Vector3.Up; RotationLookAt(ref forward, ref up, out var result); return result; } + /// + /// Creates a rotation with the specified forward and upwards directions. + /// + /// The forward direction. Direction to orient towards. + /// The calculated quaternion. + public static Quaternion LookRotation(Vector3 forward) + { + return LookRotation(forward, Vector3.Up); + } + /// /// Creates a rotation with the specified forward and upwards directions. /// From db3552509a0375377e931c2f9619dd920151eb20 Mon Sep 17 00:00:00 2001 From: Nejcraft Date: Sat, 20 Feb 2021 14:59:42 +0100 Subject: [PATCH 4/4] How many times can I fuck up? --- Source/Engine/Core/Math/Quaternion.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Source/Engine/Core/Math/Quaternion.cs b/Source/Engine/Core/Math/Quaternion.cs index fb763154e..a3aa0732b 100644 --- a/Source/Engine/Core/Math/Quaternion.cs +++ b/Source/Engine/Core/Math/Quaternion.cs @@ -1041,10 +1041,8 @@ namespace FlaxEngine /// The forward direction. Direction to orient towards. /// Up direction. Constrains y axis orientation to a plane this vector lies on. This rule might be broken if forward and up direction are nearly parallel. /// The calculated quaternion. - public static Quaternion LookRotation(Vector3 forward, Vector3 up = null) + public static Quaternion LookRotation(Vector3 forward, Vector3 up) { - if(up == null) - up = Vector3.Up; LookRotation(ref forward, ref up, out var result); return result; }