- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# FMath/FMath.h

Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 2005-2007 Feeling Software Inc.
    00003     Portions of the code are:
    00004     Copyright (C) 2005-2007 Sony Computer Entertainment America
    00005
    00006     MIT License: http://www.opensource.org/licenses/mit-license.php
    00007 */
    00008
    00016 #ifndef _F_MATH_H_
    00017 #define _F_MATH_H_
    00018
    00019 #ifndef _INC_MATH
    00020 #include <math.h>
    00021 #endif // _INC_MATH
    00022
    00023 #ifndef _FM_FLOAT_H_
    00024 #include "FMath/FMFloat.h"
    00025 #endif // _FM_FLOAT_H_
    00026
    00027
    00033 template <class T>
    00034 bool IsEquivalent(const T& v1, const T& v2) { return v1 == v2; }
    00035
    00036 // Includes the improved vector class.
    00037 #ifndef _FM_ARRAY_H_
    00038 #include "FMath/FMArray.h"
    00039 #endif // _FM_ARRAY_H_
    00040 #ifndef _FM_ARRAY_POINTER_H_
    00041 #include "FMath/FMArrayPointer.h"
    00042 #endif // _FM_ARRAY_POINTER_H_
    00043 #ifndef _FM_TREE_H_
    00044 #include "FMath/FMTree.h"
    00045 #endif // _FM_TREE_H_
    00046
    00048 typedef fm::vector<double, true> DoubleList;
    00049
    00051 typedef fm::vector<float, true> FloatList;
    00052
    00054 typedef fm::vector<int, true> IntList;
    00055
    00056
    00057 #ifndef _FM_INTEGER_H_
    00058 #include "FMath/FMInteger.h"
    00059 #endif // _FM_INTEGER_H_
    00060
    00065 namespace FMath
    00066 {
    00068     const double Pi = 3.14159265358979323846264338327950288419716939937510;
    00069     const float Pif = 3.14159265358979323846264338327950288419716939937510f;
    00073     enum AXIS
    00074     {
    00075         X = 0,
    00076         Y,
    00077         Z,
    00078         W,
    00080         TRANS = W
    00081     };
    00082
    00086     inline double RadToDeg(double val) { return (val * 180.0/Pi); }
    00087
    00091     inline float RadToDeg(float val) { return (val * 180.0f/Pif); }
    00092
    00096     inline double DegToRad(double val) { return (val * Pi/180.0); }
    00097
    00101     inline float DegToRad(float val) { return (val * (float)Pi/180.0f); }
    00102
    00106 #ifdef WIN32
    00107     inline int IsNotANumber(float f) { return _isnan(f); }
    00108 #elif __PPU__
    00109     inline int IsNotANumber(float f) { return !isfinite(f); }
    00110 #else // Linux and Mac
    00111     inline int IsNotANumber(float f) { return !finite(f); }
    00112 #endif
    00113
    00117     template <class T>
    00118     inline T Sign(const T& val) { return (val >= T(0)) ? T(1) : T(-1); }
    00119
    00129     template <class T, class T2, class T3>
    00130     inline T Clamp(T val, T2 mn, T3 mx) { return (T) ((val > (T) mx) ? (T) mx : (val < (T) mn) ? (T) mn : val); }
    00131
    00141     template <class T, class T2, class T3>
    00142     inline T Wrap(T val, T2 mn, T3 mx) { T d = (T)(mx - mn); while (val > (T)mx) val -= d; while (val < (T)mn) val += d; return val; }
    00143
    00146     template <>
    00147     inline float Wrap(float val, float mn, float mx) {
    00148         if (val > mx) return (mn + fmodf(val - mx, mx - mn));
    00149         else if (val < mn) return (mx - fmodf(mn - val, mx - mn));
    00150         return val; }
    00152     template <>
    00153     inline double Wrap(double val, double mn, double mx) {
    00154         if (val > mx) return (mn + fmod(val - mx, mx - mn));
    00155         else if (val < mn) return (mx - fmod(mn - val, mx - mn));
    00156         return val; }
    00158     template <>
    00159     inline int Wrap(int val, int mn, int mx) {
    00160         if (val > mx) return mn + ((val - mx) % (mx - mn));
    00161         else if (val < mn) return mx - ((mn - val) % (mx - mn));
    00162         return val; }
    00164     template <>
    00165     inline uint32 Wrap(uint32 val, uint32 mn, uint32 mx) {
    00166         if (val > mx) return mn + ((val - mx) % (mx - mn));
    00167         else if (val < mn) return mx - ((mn - val) % (mx - mn));
    00168         return val; }
    00169 };
    00170
    00171 // Include commonly used mathematical classes
    00172 #include "FMath/FMVector2.h"
    00173 #include "FMath/FMVector3.h"
    00174 #include "FMath/FMVector4.h"
    00175 #include "FMath/FMColor.h"
    00176 #include "FMath/FMMatrix33.h"
    00177 #include "FMath/FMMatrix44.h"
    00178
    00179 #endif // _F_MATH_H_