1 /*
2 	This file is part of Warzone 2100.
3 	Copyright (C) 1999-2004  Eidos Interactive
4 	Copyright (C) 2005-2020  Warzone 2100 Project
5 
6 	Warzone 2100 is free software; you can redistribute it and/or modify
7 	it under the terms of the GNU General Public License as published by
8 	the Free Software Foundation; either version 2 of the License, or
9 	(at your option) any later version.
10 
11 	Warzone 2100 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. See the
14 	GNU General Public License for more details.
15 
16 	You should have received a copy of the GNU General Public License
17 	along with Warzone 2100; if not, write to the Free Software
18 	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 /**
21  * @file
22  *
23  * Handles fixed point operations for degrees and matrix math.
24  */
25 
26 #ifndef FIXEDPOINT_H
27 #define FIXEDPOINT_H
28 
29 #include "wzglobal.h"
30 
31 //! PSX-style float emulation: 12 digit semi-floats stored in an int
32 // FIXME!
33 #define FP12_SHIFT 12
34 #define FP12_MULTIPLIER (1 << FP12_SHIFT)
35 
36 
37 /*
38  *	Global Definitions (CONSTANTS)
39  */
40 static const int DEG_360 = 65536;
41 static const float DEG_1 = (float)65536 / 360.f;
42 
RADIANS(float degrees)43 static inline WZ_DECL_CONST float RADIANS(float degrees)
44 {
45 	return degrees * (3.141592f / 180.0f);
46 }
47 
UNDEG(uint16_t angle)48 static inline WZ_DECL_CONST float UNDEG(uint16_t angle)
49 {
50 	return angle * (360.f / 65536.0f) * (3.141592f / 180.0f);
51 }
52 
53 // Should be a macro (or two separate functions), since we can't do function overloading for float and int, and we don't want to use the float version for anything game-state related.
54 // 65536 / 360 = 8192 / 45, with a bit less overflow risk.
55 #define DEG(degrees) ((degrees) * 8192 / 45)
56 
57 #endif // FIXEDPOINT_H
58