True Axis Physics SDK 1.2.0.1 Beta Documentation
www.trueaxis.com

RandFunc.h

00001 //---------------------------------------------------------------------------------
00002 // File Name: RandFunc.h
00003 // Description:
00004 //
00005 // Copyright (C) 2004 - 2006 True Axis Pty Ltd, Australia. 
00006 // All Rights Reserved.
00007 //
00008 // History:
00009 //      Created File.
00010 //---------------------------------------------------------------------------------
00011 
00012 #ifndef TA_RANDFUNC_H
00013 #define TA_RANDFUNC_H
00014 
00015 #ifndef TA_TYPES_H
00016 #include "Types.h"
00017 #endif // TA_TYPES_H
00018 
00019 #ifndef TA_COMMON_H
00020 #include "Common.h"
00021 #endif // TA_COMMON_H
00022 
00023 #include <stdlib.h>
00024 
00025 TA_OBFUSCATION_SKIP_PASS_2
00026 
00027 namespace TA
00028 {
00029 
00030 TA_OBFUSCATION_RESERVED_ON
00031 
00032 class RandFunc
00033 {
00034 public:
00035 
00036     // stdlib rand functions
00037     //---------------------------------------------------------------------------------
00038     //---------------------------------------------------------------------------------
00039     static inline void TAC_CALL RandSeed(u32 nSeed) { srand(nSeed); }
00040 
00041     //---------------------------------------------------------------------------------
00042     //---------------------------------------------------------------------------------
00043     static inline float TAC_CALL RandUnit() { return (float)rand() / (float)RAND_MAX; }
00044 
00045     //---------------------------------------------------------------------------------
00046     //---------------------------------------------------------------------------------
00047     static inline float TAC_CALL RandBetweenPosNeg(float fScale) { return (RandUnit() * 2.0f - 1.0f) * fScale; }
00048 
00049     //---------------------------------------------------------------------------------
00050     // Random number from min to max, including min and excluding max
00051     //---------------------------------------------------------------------------------
00052     static inline int TAC_CALL RandBetween(int nMin, int nMax) { return (rand() % (nMax - nMin)) + nMin; }
00053 
00054     //---------------------------------------------------------------------------------
00055     //---------------------------------------------------------------------------------
00056     static inline float TAC_CALL RandBetween(float fMin, float fMax) { return RandUnit() * (fMax - fMin) + fMin;  }
00057 
00058     // internal rand functions
00059     
00060     //---------------------------------------------------------------------------------
00061     //---------------------------------------------------------------------------------
00062     static void TAC_CALL TaRandSeed(u32 nSeed);
00063 
00064     //---------------------------------------------------------------------------------
00065     //---------------------------------------------------------------------------------
00066     static u32 TAC_CALL TaRandInt();
00067 
00068     //---------------------------------------------------------------------------------
00069     //---------------------------------------------------------------------------------
00070     static inline float TAC_CALL TaRandUnit() { return (float)TaRandInt() / (float)0xFFFFFFFF; }
00071 
00072     //---------------------------------------------------------------------------------
00073     //---------------------------------------------------------------------------------
00074     static inline float TAC_CALL TaRandBetweenPosNeg(float fScale) { return (TaRandUnit() * 2.0f - 1.0f) * fScale; }
00075 
00076     //---------------------------------------------------------------------------------
00077     // Random number from min to max, including min and excluding max
00078     //---------------------------------------------------------------------------------
00079     static inline int TAC_CALL TaRandBetween(int nMin, int nMax) { return (TaRandInt() % (nMax - nMin)) + nMin; }
00080 
00081     //---------------------------------------------------------------------------------
00082     //---------------------------------------------------------------------------------
00083     static inline float TAC_CALL TaRandBetween(float fMin, float fMax) { return TaRandUnit() * (fMax - fMin) + fMin;  }
00084 
00085 
00086 };
00087 TA_OBFUSCATION_RESERVED_OFF
00088 
00089 };
00090 
00091 #endif // TA_RANDFUNC_H


© Copyright 2004-2006 TRUE AXIS PTY LTD Australia. All rights reserved.