annotate engine/core/util/math/fife_math.h @ 623:684e5537eef7

* Moving the math constants to the FIFE namespace * Added swig interfaces for the math constants
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 01 Oct 2010 16:26:22 +0000
parents 356634098bd9
children 07b1cf8e92b5
rev   line source
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 /***************************************************************************
621
356634098bd9 * Removed the image chunking size variable from engine settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 620
diff changeset
2 * Copyright (C) 2005-2010 by the FIFE team *
356634098bd9 * Removed the image chunking size variable from engine settings.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 620
diff changeset
3 * http://www.fifengine.net *
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4 * This file is part of FIFE. *
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 * *
46
90005975cdbb * Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
6 * FIFE is free software; you can redistribute it and/or *
90005975cdbb * Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
7 * modify it under the terms of the GNU Lesser General Public *
90005975cdbb * Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
8 * License as published by the Free Software Foundation; either *
90005975cdbb * Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
9 * version 2.1 of the License, or (at your option) any later version. *
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 * *
46
90005975cdbb * Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
11 * This library is distributed in the hope that it will be useful, *
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
46
90005975cdbb * Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
90005975cdbb * Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
14 * Lesser General Public License for more details. *
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 * *
46
90005975cdbb * Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
16 * You should have received a copy of the GNU Lesser General Public *
90005975cdbb * Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
17 * License along with this library; if not, write to the *
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 * Free Software Foundation, Inc., *
46
90005975cdbb * Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 ***************************************************************************/
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 #ifndef FIFE_UTIL_FIFE_MATH_H
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23 #define FIFE_UTIL_FIFE_MATH_H
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 // Standard C++ library includes
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26 #include <cmath>
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27
620
853d25234671 * Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 46
diff changeset
28 // Platform specific includes
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 // 3rd party library includes
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32 // FIFE includes
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33 // These includes are split up in two parts, separated by one empty line
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 // First block: files included from the FIFE root src directory
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 // Second block: files included from the same folder
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36
623
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
37 #ifndef ABS
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
38 #define ABS(x) ((x)<0?-(x):(x))
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
39
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
40 #endif
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42 // Sort out the missing round function in MSVC:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 #if defined( WIN32 ) && defined( _MSC_VER )
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 inline double round(const double x) {
620
853d25234671 * Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 46
diff changeset
45 return x < 0.0 ? ceil(x - 0.5) : floor(x + 0.5);
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 }
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47 #endif
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48
623
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
49 namespace FIFE {
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50
623
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
51 static const float FLT_ZERO_TOLERANCE = 1e-06f;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
52 static const float FLT_PI = 4.0f*std::atan(1.0f);
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
53 static const float FLT_TWO_PI = 2.0f*FLT_PI;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
54 static const float FLT_HALF_PI = 0.5f*FLT_PI;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
55 static const float FLT_INVERSE_PI = 1.0f/FLT_PI;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
56 static const float FLT_INVERSE_TWO_PI = 1.0f/FLT_TWO_PI;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
57 static const float FLT_DEG_TO_RAD = FLT_PI/180.0f;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
58 static const float FLT_RAD_TO_DEG = 180.0f/FLT_PI;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
59 static const float FLT_LOG_2 = std::log(2.0f);
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
60 static const float FLT_LOG_10 = std::log(10.0f);
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
61 static const float FLT_INV_LOG_2 = 1.0f/std::log(2.0f);
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
62 static const float FLT_INV_LOG_10 = 1.0f/std::log(10.0f);
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
63
623
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
64 static const double DBL_ZERO_TOLERANCE = 1e-08;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
65 static const double DBL_PI = 4.0*std::atan(1.0f);
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
66 static const double DBL_TWO_PI = 2.0*DBL_PI;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
67 static const double DBL_HALF_PI = 0.5*DBL_PI;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
68 static const double DBL_INVERSE_PI = 1.0/DBL_PI;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
69 static const double DBL_INVERSE_TWO_PI = 1.0/DBL_TWO_PI;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
70 static const double DBL_DEG_TO_RAD = DBL_PI/180.0;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
71 static const double DBL_RAD_TO_DEG = 180.0/DBL_PI;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
72 static const double DBL_LOG_2 = std::log(2.0f);
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
73 static const double DBL_LOG_10 = std::log(10.0f);
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
74 static const double DBL_INV_LOG_2 = 1.0/std::log(2.0f);
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
75 static const double DBL_INV_LOG_10 = 1.0/std::log(10.0f);
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76
623
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
77 inline unsigned nextPow2(unsigned x)
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
78 {
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
79 --x;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
80 x |= x >> 1;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
81 x |= x >> 2;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
82 x |= x >> 4;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
83 x |= x >> 8;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
84 x |= x >> 16;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
85 return ++x;
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
86 }
684e5537eef7 * Moving the math constants to the FIFE namespace
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 621
diff changeset
87 } //FIFE
620
853d25234671 * Moved the GLEnable and GLDisable structures from opengl_gui_graphics.cpp to fife_opengl.h as they may prove to be useful elsewhere.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 46
diff changeset
88
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
89 #endif // FIFE_UTIL_FIFE_MATH_H