00001 // Filename: particleCommonFuncs.h 00002 // Created by: darren (02Oct00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #ifndef PARTICLECOMMONFUNCS_H 00020 #define PARTICLECOMMONFUNCS_H 00021 00022 // evaluates to a float in the range [0,1] 00023 #define NORMALIZED_RAND() ((float)rand() / (float)RAND_MAX) 00024 00025 // linear interpolation 00026 // t is in [0,1] 00027 // result is in [X0,X1] 00028 #define LERP(t,X0,X1) ((X0) + ((t) * ((X1) - (X0)))) 00029 00030 // linear t -> cubic t 00031 // t is in [0,1] 00032 // result is in [0,1] 00033 #define CUBIC_T(t) ((t)*(t)*(3-(2*(t)))) 00034 00035 // cubic interpolation 00036 // t is in [0,1] 00037 // result is in [X0,X1] 00038 #define CLERP(t,X0,X1) LERP(CUBIC_T(t), (X0), (X1)) 00039 00040 // spread calculator 00041 // spread is non-negative spread magnitude 00042 // result is in [-spread,spread] 00043 #define SPREAD(magnitude) ((magnitude) - (NORMALIZED_RAND() * 2.0f * (magnitude))) 00044 00045 // integer spread calculator 00046 // spread is non-negative spread magnitude (integer) 00047 // result is in [-spread,spread] 00048 #define I_SPREAD(magnitude) ((magnitude) - ((int)rand() % ((2*(magnitude))+1))) 00049 00050 #endif // PARTICLECOMMONFUNCS_H