Line data Source code
1 0 : /* 2 : 3 : OOMaths.h 4 : 5 : Mathematical framework for Oolite. 6 : 7 : Provides utility routines for Vectors, Quaternions, rotation matrices, and 8 : conversion to OpenGL transformation matrices. 9 : 10 : Oolite 11 : Copyright (C) 2004-2013 Giles C Williams and contributors 12 : 13 : This program is free software; you can redistribute it and/or 14 : modify it under the terms of the GNU General Public License 15 : as published by the Free Software Foundation; either version 2 16 : of the License, or (at your option) any later version. 17 : 18 : This program is distributed in the hope that it will be useful, 19 : but WITHOUT ANY WARRANTY; without even the implied warranty of 20 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 : GNU General Public License for more details. 22 : 23 : You should have received a copy of the GNU General Public License 24 : along with this program; if not, write to the Free Software 25 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 26 : MA 02110-1301, USA. 27 : 28 : */ 29 : 30 : 31 : #ifndef INCLUDED_OOMATHS_h 32 : #define INCLUDED_OOMATHS_h 33 : 34 : #ifdef __cplusplus 35 : extern "C" { 36 : #endif 37 : 38 : #ifndef OOMATHS_STANDALONE 39 0 : #define OOMATHS_STANDALONE 0 40 : #endif 41 : 42 : #ifndef OOMATHS_OPENGL_INTEGRATION 43 0 : #define OOMATHS_OPENGL_INTEGRATION !OOMATHS_STANDALONE 44 : #endif 45 : 46 : #ifdef __OBJC__ 47 : #import <Foundation/Foundation.h> 48 : #endif 49 : 50 : #include "OOFunctionAttributes.h" 51 : #include <tgmath.h> 52 : #include <stdbool.h> 53 : #include <stdlib.h> 54 : #include <stdint.h> 55 : #include <limits.h> 56 : #include <assert.h> 57 : 58 : #if OOMATHS_OPENGL_INTEGRATION 59 : #include "OOOpenGL.h" 60 : #endif 61 : 62 : 63 : #if OOMATHS_OPENGL_INTEGRATION 64 0 : typedef GLfloat OOScalar; 65 : #else 66 : typedef float OOScalar; 67 : #endif 68 : 69 0 : typedef double OOHPScalar; 70 : 71 : 72 : #ifndef M_PI 73 0 : #define M_PI 3.14159265358979323846 /* pi */ 74 : #endif 75 : #ifndef M_PI_2 76 0 : #define M_PI_2 1.57079632679489661923 /* pi/2 */ 77 : #endif 78 : #ifndef M_PI_4 79 0 : #define M_PI_4 0.78539816339744830962 /* pi/4 */ 80 : #endif 81 : #ifndef M_1_PI 82 0 : #define M_1_PI 0.31830988618379067154 /* 1/pi */ 83 : #endif 84 : #ifndef M_2_PI 85 0 : #define M_2_PI 0.63661977236758134308 /* 2/pi */ 86 : #endif 87 : #ifndef M_2_SQRTPI 88 0 : #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ 89 : #endif 90 : #ifndef M_SQRT2 91 0 : #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ 92 : #endif 93 : #ifndef M_SQRT1_2 94 0 : #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ 95 : #endif 96 : 97 : 98 : #if defined(__GNUC__) && !defined(__STRICT_ANSI__) 99 : #ifndef MIN 100 : #define MIN(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; }) 101 : #endif 102 : #if !defined(MAX) 103 : #define MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; }) 104 : #endif 105 : #if !defined(ABS) 106 : #define ABS(A) ({ __typeof__(A) __a = (A); __a < 0 ? -__a : __a; }) 107 : #endif 108 : #else 109 : /* These definitions are unsafe in that the "winning" expression is evaluated twice. */ 110 : #if !defined(MIN) 111 0 : #define MIN(A,B) ((A) < (B) ? (A) : (B)) 112 : #endif 113 : #if !defined(MAX) 114 0 : #define MAX(A,B) ((A) > (B) ? (A) : (B)) 115 : #endif 116 : #if !defined(ABS) 117 0 : #define ABS(A) ((A) < 0 ? (-(A)) : (A)) 118 : #endif 119 : #endif 120 : 121 : 122 : #include "OOFastArithmetic.h" 123 : #include "OOVector.h" 124 : #include "OOHPVector.h" 125 : #include "OOQuaternion.h" 126 : #include "OOMatrix.h" 127 : 128 : #if !OOMATHS_STANDALONE 129 : #include "OOVoxel.h" 130 : #include "OOTriangle.h" 131 : #include "OOBoundingBox.h" 132 : 133 : #include "legacy_random.h" 134 : #endif 135 : 136 : 137 : #ifdef __cplusplus 138 : } 139 : #endif 140 : 141 : #endif /* INCLUDED_OOMATHS_h */