1 /* 2 Copyright (C) 2007, 2010 - Bit-Blot 3 4 This file is part of Aquaria. 5 6 Aquaria is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License 8 as published by the Free Software Foundation; either version 2 9 of the License, or (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 15 See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 */ 21 #include "Base.h" 22 23 #ifdef __GNUC__ 24 #define UNUSED __attribute__((unused)) // Avoid "unused function" warnings 25 #else 26 #define UNUSED //nothing 27 #endif 28 29 namespace MathFunctions 30 { calculateAngleBetweenVectorsInDegrees(const Vector & vector1,const Vector & vector2,float & solutionAngle)31 UNUSED static void calculateAngleBetweenVectorsInDegrees(const Vector &vector1, const Vector &vector2, float &solutionAngle) 32 { 33 Vector dist = vector1 - vector2; 34 35 // 0 is down 36 // 90 is right 37 // 180 is up 38 // 270 is left 39 // 360 is down 40 solutionAngle = atan2f(dist.y, fabsf(dist.x)); 41 solutionAngle = (solutionAngle/PI)*180; 42 if (dist.x < 0) 43 solutionAngle = 180-solutionAngle; 44 solutionAngle += 90; 45 } 46 toRadians(float rot)47 UNUSED static float toRadians(float rot) 48 { 49 return PI-(rot*PI)/180.0f; 50 } 51 52 UNUSED static float getAngleToVector(const Vector &addVec, float offsetAngle = 0) 53 { 54 float angle=0; 55 MathFunctions::calculateAngleBetweenVectorsInDegrees(Vector(0,0,0), addVec, angle); 56 angle = 180-(360-angle); 57 angle += offsetAngle; 58 return angle; 59 } 60 61 }; 62 63