#region ================== Copyright (c) 2021 Boris Iwanski /* * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * 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. * * You should have received a copy of the GNU General Public License * along with this program.If not, see. */ #endregion #region ================== Namespaces using CodeImp.DoomBuilder.Geometry; #endregion namespace CodeImp.DoomBuilder.UDBScript.Wrapper { internal struct Angle2DWrapper { #region ================== Methods /// /// Converts a Doom angle (where 0° is east) to a real world angle (where 0° is north). /// /// Doom angle in degrees /// Doom angle in degrees public double doomToReal(int doomangle) { return normalized(doomangle + 90); } /// /// Converts a Doom angle (where 0° is east) to a real world angle (where 0° is north) in radians. /// /// Doom angle in degrees /// Doom angle in radians public double doomToRealRad(int doomangle) { return Angle2D.DoomToReal(doomangle); } /// /// Converts a real world angle (where 0° is north) to a Doom angle (where 0° is east). /// /// Real world angle in degrees /// Doom angle in degrees public int realToDoom(double realangle) { return normalized((int)(realangle - 90)); } /// /// Converts a real world angle (where 0° is north) to a Doom angle (where 0° is east) in radians. /// /// Real world angle in radians /// Doom angle in degrees public int realToDoomRad(double realangle) { return Angle2D.RealToDoom(realangle); } /// /// Converts radians to degrees. /// /// Angle in radians /// Angle in degrees public double radToDeg(double rad) { return Angle2D.RadToDeg(rad); } /// /// Converts degrees to radians. /// /// Angle in degrees /// Angle in radians public double degToRad(double deg) { return Angle2D.DegToRad(deg); } /// /// Normalizes an angle in degrees so that it is bigger or equal to 0° and smaller than 360°. /// /// Angle in degrees /// Normalized angle in degrees public int normalized(int angle) { while (angle < 0) angle += 360; while (angle >= 360) angle -= 360; return angle; } /// /// Normalizes an angle in radians so that it is bigger or equal to 0 and smaller than 2 Pi. /// /// Angle in radians /// Normalized angle in radians public double normalizedRad(double angle) { return Angle2D.Normalized(angle); } /// /// Returns the angle between three positions. /// /// First position /// Second position /// Third position /// Angle in degrees public double getAngle(object p1, object p2, object p3) { try { Vector2D v1 = BuilderPlug.Me.GetVector3DFromObject(p1); Vector2D v2 = BuilderPlug.Me.GetVector3DFromObject(p2); Vector2D v3 = BuilderPlug.Me.GetVector3DFromObject(p3); return Angle2D.RadToDeg(Angle2D.GetAngle(v1, v2, v3)); } catch (CantConvertToVectorException e) { throw BuilderPlug.Me.ScriptRunner.CreateRuntimeException(e.Message); } } /// /// Returns the angle between three positions in radians. /// /// First position /// Second position /// Third position /// Angle in radians public double getAngleRad(object p1, object p2, object p3) { try { Vector2D v1 = BuilderPlug.Me.GetVector3DFromObject(p1); Vector2D v2 = BuilderPlug.Me.GetVector3DFromObject(p2); Vector2D v3 = BuilderPlug.Me.GetVector3DFromObject(p3); return Angle2D.GetAngle(v1, v2, v3); } catch (CantConvertToVectorException e) { throw BuilderPlug.Me.ScriptRunner.CreateRuntimeException(e.Message); } } #endregion } }