- Main Page
- Classes
- Files

- File List
- File Members

# flMath.h

Go to the documentation of this file.

    00001 // Funclib Math v1.0.0 (CORE)
    00002 //
    00003 // This module contains maths functions.
    00004 // It will in the future also act as a wrapper for most math.h functions.
    00005 // This module requires doesn't require anything else.
    00006 //
    00007 // Contributor(s): Flatmush
    00008
    00009
    00010
    00011 #ifndef FLMATH_H
    00012 #define FLMATH_H
    00013
    00014 #include "flGlobal.h"
    00015
    00016 #if FL_MATH
    00017
    00018 #ifdef __cplusplus
    00019 extern "C" {
    00020 #endif
    00021
    00022 #include <math.h>
    00023
    00024 #if FL_MATH_TRIGCACHE > 0
    00025
    00030 typedef struct {
    00034      u64   mtgLastUsed;
    00038      float mtgIn;
    00042      float mtgOut;
    00043 } MathTrigCache;
    00044
    00051 MathTrigCache* mathTrigCacheSin;
    00052
    00057 bool           mathTrigCacheInitialized;
    00058 #endif
    00059
    00060
    00061
    00067 extern void         mathInit();
    00068
    00069
    00070
    00076 extern void         mathRandSeed(u32 inSeed);
    00077
    00083 extern float        mathRandf(float inSize);
    00088 extern float        mathRandFractf();
    00089
    00096 extern unsigned int mathRandi(unsigned int inSize);
    00097
    00105 extern s64          mathRandl(s64 inSize);
    00106
    00107
    00108
    00114 extern float        mathFixDegRange(float inDeg);
    00115
    00121 extern float        mathFixRadRange(float inRad);
    00122
    00128 extern float        mathDegToRad(float inDeg);
    00129
    00135 extern float        mathRadToDeg(float inRad);
    00136
    00137
    00138
    00146 extern float        mathSinf(float inAngle);
    00147
    00155 extern float        mathCosf(float inAngle);
    00156
    00164 extern float        mathACosf(float inAngle);
    00165
    00174 extern float        mathATanf(float inAngle);
    00175
    00176
    00177
    00184 extern float        mathExpnf(float inValue);
    00185
    00192 extern float        mathLnf(float inValue);
    00193
    00194
    00195
    00203 extern float        mathPythag2f(float inX, float inY);
    00204
    00213 extern float        mathPythag3f(float inX, float inY, float inZ);
    00214
    00215
    00216
    00224 extern float        mathDotProdN(float* inValue0, float* inValue1, u8 inCount);
    00225
    00226
    00227
    00228 extern float        mathQuatLength(quat4f inQuat);
    00229 extern quat4f*      mathQuatNormalize(quat4f* inQuat);
    00230 extern quat4f       mathQuatNormal(quat4f inQuat);
    00231 extern quat4f*      mathQuatNegate(quat4f* inQuat);
    00232 extern quat4f       mathQuatNegation(quat4f inQuat);
    00233 extern quat4f       mathQuatMult(quat4f inQuat0, quat4f inQuat1);
    00234
    00235
    00236
    00245 extern vect3f       mathVect3fRotate(vect3f inVect, vect3f inAxis, float inAngle);
    00246 extern vect3f       mathVect3fCrossProd(vect3f inVect0, vect3f inVect1);
    00247 extern float        mathVect3fLength(vect3f inVect);
    00248 extern vect3f*      mathVect3fNormalize(vect3f* inVect);
    00249 extern vect3f       mathVect3fNormal(vect3f inVect);
    00250 #define mathVect3fRotateX(inView, inAngle) mathVect3fRotate(inView, { 1.0f, 0.0f, 0.0f }, inAngle)
    00251 #define mathVect3fRotateY(inView, inAngle) mathVect3fRotate(inView, { 0.0f, 1.0f, 0.0f }, inAngle)
    00252 #define mathVect3fRotateZ(inView, inAngle) mathVect3fRotate(inView, { 0.0f, 0.0f, 1.0f }, inAngle)
    00253
    00254 #if FL_MATH_TRIGCACHE > 0
    00255 extern void   mathTrigCacheInit();
    00256 extern float* mathTrigCacheCheckSin(float inAngle);
    00257 extern void   mathTrigCacheAddSin(float inAngle, float inAnswer);
    00258 extern float* mathTrigCacheCheckCos(float inAngle);
    00259 extern void   mathTrigCacheAddCos(float inAngle, float inAnswer);
    00260 #endif
    00261
    00262 #ifdef __cplusplus
    00263 }
    00264 #endif
    00265
    00266 #else
    00267 #include <math.h>
    00268
    00269 #define mathDegToRad(inDeg) (((inDeg) * MATH_PI) * 180.0f)
    00270 #define mathRadToDeg(inRad) (((inRad) * 180.0f) / MATH_PI)
    00271
    00272 #define mathSinf(inAngle) sinf(inAngle)
    00273 #define mathCosf(inAngle) cosf(inAngle)
    00274 #define mathACosf(inAngle) acosf(inAngle)
    00275 #define mathATanf(inAngle) atanf(inAngle)
    00276
    00277 #define mathExpf(inValue) expf(inValue)
    00278 #define mathLnf(inValue) logf(inValue)
    00279
    00280 #define mathPythag2f(inX, inY) sqrtf(((inX) * (inX)) + ((inY) * (inY)))
    00281 #define mathPythag3f(inX, inY, inZ) sqrtf(((inX) * (inX)) + ((inY) * (inY)) + ((inZ) * (inZ)))
    00282
    00283 #endif
    00284
    00285
    00286 #define mathSign(inValue) ((inValue) < 0 ? -1 : 1)
    00287 #define mathSignf(inValue) ((inValue) < 0.0f ? -1.0f : 1.0f)
    00288 #define mathSigni(inValue) mathSign(inValue)
    00289 #define mathAbsf(inValue) fabsf(inValue)
    00290
    00291 #define mathLogef(inValue) mathLnf(inValue)
    00292
    00293 #define mathSqrtf(inValue) sqrtf(inValue)
    00294
    00295 #define mathDegreesToRadians(inDeg) mathDegToRad(inDeg)
    00296 #define mathRadiansToDegrees(inRad) mathRadToDeg(inRad)
    00297
    00298 #endif