This commit is contained in:
Pascal Serrarens 2025-03-12 15:32:30 +01:00
commit 828223f548
4 changed files with 41 additions and 3 deletions

View File

@ -12,8 +12,8 @@ namespace LinearAlgebra
// public static float Rad2Deg = 360.0f / ((float)Math.PI * 2);
// public static float Deg2Rad = ((float)Math.PI * 2) / 360.0f;
public const float Deg2Rad = 360.0f / ((float)Math.PI * 2); //0.0174532924F;
public const float Rad2Deg = ((float)Math.PI * 2) / 360.0f; //57.29578F;
public const float Rad2Deg = 360.0f / ((float)Math.PI * 2); //0.0174532924F;
public const float Deg2Rad = ((float)Math.PI * 2) / 360.0f; //57.29578F;
/// <summary>
/// Clamp the angle between the given min and max values

View File

@ -1,3 +1,8 @@
using System;
#if UNITY_5_3_OR_NEWER
using Vector3Float = UnityEngine.Vector3;
#endif
namespace LinearAlgebra
{
@ -32,6 +37,23 @@ namespace LinearAlgebra
this.horizontal += 180;
this.vertical = 180 - this.vertical;
}
}
public Vector3Float ToVector3()
{
float verticalRad = (Angle.pi / 2) - this.vertical * Angle.Deg2Rad;
float horizontalRad = this.horizontal * Angle.Deg2Rad;
float cosVertical = (float)Math.Cos(verticalRad);
float sinVertical = (float)Math.Sin(verticalRad);
float cosHorizontal = (float)Math.Cos(horizontalRad);
float sinHorizontal = (float)Math.Sin(horizontalRad);
float x = sinVertical * sinHorizontal;
float y = cosVertical;
float z = sinVertical * cosHorizontal;
Vector3Float v = new(x, y, z);
return v;
}
}

View File

@ -1,3 +1,8 @@
using System.Numerics;
#if UNITY_5_3_OR_NEWER
using Quaternion = UnityEngine.Quaternion;
#endif
namespace LinearAlgebra
{
@ -27,6 +32,15 @@ namespace LinearAlgebra
SwingTwist r = new SwingTwist(up, right, forward);
return r;
}
#if UNITY_5_3_OR_NEWER
public Quaternion ToQuaternion() {
Quaternion q = Quaternion.Euler(-this.swing.vertical,
this.swing.horizontal,
this.twist);
return q;
}
#endif
}
}

View File

@ -1,3 +1,4 @@
#if !UNITY_5_6_OR_NEWER
using NUnit.Framework;
namespace LinearAlgebra.Test
@ -166,4 +167,5 @@ namespace LinearAlgebra.Test
}
}
}
}
#endif