32 lines
748 B
C#
32 lines
748 B
C#
using UnityEngine;
|
|
|
|
namespace R0bbie.VRSubtitles
|
|
{
|
|
/// <summary>
|
|
/// Some useful Math functions
|
|
/// </summary>
|
|
public class Math
|
|
{
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="a"></param>
|
|
/// <param name="b"></param>
|
|
/// <param name="n"></param>
|
|
/// <returns></returns>
|
|
public static float SignedAngleBetween(Vector3 a, Vector3 b, Vector3 n)
|
|
{
|
|
// angle in [0,180]
|
|
float angle = Vector3.Angle(a,b);
|
|
float sign = Mathf.Sign(Vector3.Dot(n,Vector3.Cross(a,b)));
|
|
|
|
// angle in [-179,180]
|
|
float signed_angle = angle * sign;
|
|
|
|
return signed_angle;
|
|
}
|
|
|
|
}
|
|
|
|
} |