Panda3D
 All Classes Functions Variables Enumerations
particleCommonFuncs.h
00001 // Filename: particleCommonFuncs.h
00002 // Created by:  darren (02Oct00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef PARTICLECOMMONFUNCS_H
00016 #define PARTICLECOMMONFUNCS_H
00017 
00018 // evaluates to a float in the range [0,1]
00019 #define NORMALIZED_RAND() ((PN_stdfloat)rand() / (PN_stdfloat)RAND_MAX)
00020 
00021 // linear interpolation
00022 // t is in [0,1]
00023 // result is in [X0,X1]
00024 #define LERP(t,X0,X1) ((X0) + ((t) * ((X1) - (X0))))
00025 
00026 // linear t -> cubic t
00027 // t is in [0,1]
00028 // result is in [0,1]
00029 #define CUBIC_T(t) ((t)*(t)*(3-(2*(t))))
00030 
00031 // cubic interpolation
00032 // t is in [0,1]
00033 // result is in [X0,X1]
00034 #define CLERP(t,X0,X1) LERP(CUBIC_T(t), (X0), (X1))
00035 
00036 // spread calculator
00037 // spread is non-negative spread magnitude
00038 // result is in [-spread,spread]
00039 #define SPREAD(magnitude) ((magnitude) - (NORMALIZED_RAND() * 2.0f * (magnitude)))
00040 
00041 // integer spread calculator
00042 // spread is non-negative spread magnitude (integer)
00043 // result is in [-spread,spread]
00044 #define I_SPREAD(magnitude) ((magnitude) - ((int)rand() % ((2*(magnitude))+1)))
00045 
00046 #endif // PARTICLECOMMONFUNCS_H
 All Classes Functions Variables Enumerations