2008-11-30 02:17:19 +00:00
|
|
|
|
2007-06-14 23:31:57 +00:00
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
2007-06-13 19:39:38 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-06-14 23:31:57 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
2007-06-13 19:39:38 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Text;
|
|
|
|
|
2007-06-14 23:31:57 +00:00
|
|
|
#endregion
|
|
|
|
|
2007-06-13 19:39:38 +00:00
|
|
|
namespace CodeImp.DoomBuilder.Geometry
|
|
|
|
{
|
2007-07-07 09:40:34 +00:00
|
|
|
public struct Angle2D
|
2007-06-13 19:39:38 +00:00
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
public const float PI = (float)Math.PI;
|
2008-01-05 18:11:29 +00:00
|
|
|
public const float PIHALF = (float)Math.PI * 0.5f;
|
2007-06-13 19:39:38 +00:00
|
|
|
public const float PI2 = (float)Math.PI * 2f;
|
2007-10-21 18:06:10 +00:00
|
|
|
public const float PIDEG = 57.295779513082320876798154814105f;
|
2008-11-30 02:17:19 +00:00
|
|
|
public const float SQRT2 = 1.4142135623730950488016887242097f;
|
|
|
|
|
2007-06-13 19:39:38 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
2008-05-15 19:48:07 +00:00
|
|
|
// This converts degrees to radians
|
|
|
|
public static float DegToRad(float deg)
|
|
|
|
{
|
|
|
|
return deg / PIDEG;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This converts radians to degrees
|
|
|
|
public static float RadToDeg(float rad)
|
|
|
|
{
|
|
|
|
return rad * PIDEG;
|
|
|
|
}
|
|
|
|
|
2007-06-13 19:39:38 +00:00
|
|
|
// This normalizes an angle
|
|
|
|
public static float Normalized(float a)
|
|
|
|
{
|
|
|
|
while(a < 0f) a += PI2;
|
|
|
|
while(a > PI2) a -= PI2;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This returns the difference between two angles
|
|
|
|
public static float Difference(float a, float b)
|
|
|
|
{
|
|
|
|
float d;
|
|
|
|
|
|
|
|
// Calculate delta angle
|
|
|
|
d = Normalized(a) - Normalized(b);
|
|
|
|
|
|
|
|
// Make corrections for zero barrier
|
|
|
|
if(d < 0f) d += PI2;
|
2008-01-08 18:52:20 +00:00
|
|
|
if(d > PI) d = PI2 - d;
|
2007-06-13 19:39:38 +00:00
|
|
|
|
|
|
|
// Return result
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|