-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniversalUnityExtensions.cs
More file actions
56 lines (51 loc) · 1.01 KB
/
UniversalUnityExtensions.cs
File metadata and controls
56 lines (51 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
#if UNITY
using UnityEngine;
#else
using System.Numerics;
#endif
namespace EchoVRAPI
{
public static class UniversalUnityExtensions
{
public static float UniversalLength(this Vector3 v)
{
#if UNITY
return v.magnitude;
#else
return v.Length();
#endif
}
public static Vector3 UniversalVector3Zero()
{
#if UNITY
return Vector3.zero;
#else
return Vector3.Zero;
#endif
}
public static Quaternion UniversalQuaternionIdentity()
{
#if UNITY
return Quaternion.identity;
#else
return Quaternion.Identity;
#endif
}
/// <summary>
/// <para>Returns the angle in degrees between two rotations</para>
/// </summary>
public static float QuaternionAngle(Quaternion a, Quaternion b)
{
#if UNITY
return Quaternion.Angle(a, b);
#else
float num = Quaternion.Dot(a, b);
return IsEqualUsingDot(num)
? 0.0f
: (float) (Math.Acos(Math.Min(Math.Abs(num), 1f)) * 2.0 * 57.2957801818848);
#endif
}
private static bool IsEqualUsingDot(float dot) => dot > 0.999998986721039;
}
}