Compatibility Fixes

This commit is contained in:
Pascal Serrarens 2025-04-17 09:38:15 +02:00
parent 4ef3b24eae
commit 83159b487d
2 changed files with 28 additions and 25 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
#if UNITY_5_3_OR_NEWER #if UNITY_5_3_OR_NEWER
using Vector3Float = UnityEngine.Vector3; //using Vector3Float = UnityEngine.Vector3;
using Vector3 = UnityEngine.Vector3;
#endif #endif
namespace LinearAlgebra { namespace LinearAlgebra {
@ -66,16 +67,16 @@ namespace LinearAlgebra {
public readonly static Spherical forward = new(1, Direction.forward); public readonly static Spherical forward = new(1, Direction.forward);
public static Spherical FromVector3Float(Vector3Float v) { // public static Spherical FromVector3Float(Vector3Float v) {
float distance = v.magnitude; // float distance = v.magnitude;
if (distance == 0.0f) // if (distance == 0.0f)
return Spherical.zero; // return Spherical.zero;
else { // else {
float verticalAngle = (float)((Angle.pi / 2 - Math.Acos(v.y / distance)) * Angle.Rad2Deg); // float verticalAngle = (float)((Angle.pi / 2 - Math.Acos(v.y / distance)) * Angle.Rad2Deg);
float horizontalAngle = (float)Math.Atan2(v.x, v.z) * Angle.Rad2Deg; // float horizontalAngle = (float)Math.Atan2(v.x, v.z) * Angle.Rad2Deg;
return Spherical.Degrees(distance, horizontalAngle, verticalAngle); // return Spherical.Degrees(distance, horizontalAngle, verticalAngle);
} // }
} // }
public static Spherical FromVector3(Vector3 v) { public static Spherical FromVector3(Vector3 v) {
float distance = v.magnitude; float distance = v.magnitude;
@ -88,21 +89,21 @@ namespace LinearAlgebra {
} }
} }
public Vector3Float ToVector3Float() { // public Vector3Float ToVector3Float() {
float verticalRad = (Angle.pi / 2) - this.direction.vertical * Angle.Deg2Rad; // float verticalRad = (Angle.pi / 2) - this.direction.vertical * Angle.Deg2Rad;
float horizontalRad = this.direction.horizontal * Angle.Deg2Rad; // float horizontalRad = this.direction.horizontal * Angle.Deg2Rad;
float cosVertical = (float)Math.Cos(verticalRad); // float cosVertical = (float)Math.Cos(verticalRad);
float sinVertical = (float)Math.Sin(verticalRad); // float sinVertical = (float)Math.Sin(verticalRad);
float cosHorizontal = (float)Math.Cos(horizontalRad); // float cosHorizontal = (float)Math.Cos(horizontalRad);
float sinHorizontal = (float)Math.Sin(horizontalRad); // float sinHorizontal = (float)Math.Sin(horizontalRad);
float x = this.distance * sinVertical * sinHorizontal; // float x = this.distance * sinVertical * sinHorizontal;
float y = this.distance * cosVertical; // float y = this.distance * cosVertical;
float z = this.distance * sinVertical * cosHorizontal; // float z = this.distance * sinVertical * cosHorizontal;
Vector3Float v = new(x, y, z); // Vector3Float v = new(x, y, z);
return v; // return v;
} // }
public Vector3 ToVector3() { public Vector3 ToVector3() {
float verticalRad = (Angle.pi / 2) - this.direction.vertical * Angle.Deg2Rad; float verticalRad = (Angle.pi / 2) - this.direction.vertical * Angle.Deg2Rad;

View File

@ -1,3 +1,4 @@
#if !UNITY_5_6_OR_NEWER
using NUnit.Framework; using NUnit.Framework;
namespace LinearAlgebra.Test { namespace LinearAlgebra.Test {
@ -26,3 +27,4 @@ namespace LinearAlgebra.Test {
} }
} }
} }
#endif