Tactics: Western Philosophers Vs. Musicians  0.12
A turn-based tactical game combining rules and gameplay elements inspired by Final Fantasy Tactics and the Mayfair Exponential Game System. Unlike most games of this type, motion is in full, grid-less 3D.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MFun.h
Go to the documentation of this file.
1 // Copyright (C) 2004-2013 Dylan Blair
3 //
4 // email: dblair@alumni.cs.utexas.edu
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library 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 GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 
21 #ifndef MFUN_H
22 #define MFUN_H
23 
24 #include "../Utils_LIB/UTypes.h"
25 
26 #include <stdlib.h>
27 #include <math.h>
28 #include <assert.h>
29 #include <time.h>
30 
31 #ifndef _WIN32
32 #include <unistd.h>
33 extern long CLK_TCK;
34 #else
35 #ifndef NOMINMAX
36 #define NOMINMAX
37 #endif
38 #endif
39 
43 namespace OpenSkyNet {
46  namespace Math {
47  const float PI(3.14159265f);
48  const float DEGREES_TO_RADIANS(0.01745329f);
49  const float RADIANS_TO_DEGREES(57.29577951f);
50  const float PSEUDO_INFINITY(1000000.0f);
51  const float CLOSE_TO_ZERO(0.00001f);
52 
54  inline float getRadFromDeg(float deg_) { return deg_*PI/180.0f; }
55 
57  inline float rand01() { return static_cast<float>(rand()) / static_cast<float>(RAND_MAX); }
58 
60  inline float randNeg1Pos1() { return ((static_cast<float>(rand()) / (static_cast<float>(RAND_MAX)/2.0f)) - 1.0f); }
61 
63  inline int roundToInt(double num_) { return static_cast<int>(num_+(num_>=0.0?0.5:-0.5)); }
64 
66  inline Utils::uint roundToUInt(float num_) { return static_cast<Utils::uint>(num_+0.5f); }
67 
69  inline Utils::uint timeStamp() { return static_cast<Utils::uint>(clock()/CLK_TCK); }
70 
76  template<class T>
77  inline T clamp(T& num_, const T& min_=0, const T& max_=1) {
78  if (num_ > max_) {
79  T diff = num_ - max_;
80  num_ = max_;
81  return diff;
82  }
83  if (num_ < min_) {
84  T diff = num_ - min_;
85  num_ = min_;
86  return diff;
87  }
88  return 0;
89  }
90  }
91 }
92 
93 #endif //MFUN_H
long CLK_TCK
Definition: MFun.cpp:4
const float DEGREES_TO_RADIANS(0.01745329f)
int roundToInt(double num_)
Definition: MFun.h:63
T clamp(T &num_, const T &min_=0, const T &max_=1)
Definition: MFun.h:77
Utils::uint roundToUInt(float num_)
Definition: MFun.h:66
const float PSEUDO_INFINITY(1000000.0f)
unsigned int uint
Definition: UTypes.h:39
Utils::uint timeStamp()
Definition: MFun.h:69
float randNeg1Pos1()
Definition: MFun.h:60
const float PI(3.14159265f)
const float CLOSE_TO_ZERO(0.00001f)
float getRadFromDeg(float deg_)
Definition: MFun.h:54
const float RADIANS_TO_DEGREES(57.29577951f)
float rand01()
Definition: MFun.h:57