Panda3D
 All Classes Functions Variables Enumerations
particleCommonFuncs.h
1 // Filename: particleCommonFuncs.h
2 // Created by: darren (02Oct00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PARTICLECOMMONFUNCS_H
16 #define PARTICLECOMMONFUNCS_H
17 
18 // evaluates to a float in the range [0,1]
19 #define NORMALIZED_RAND() ((PN_stdfloat)rand() / (PN_stdfloat)RAND_MAX)
20 
21 // linear interpolation
22 // t is in [0,1]
23 // result is in [X0,X1]
24 #define LERP(t,X0,X1) ((X0) + ((t) * ((X1) - (X0))))
25 
26 // linear t -> cubic t
27 // t is in [0,1]
28 // result is in [0,1]
29 #define CUBIC_T(t) ((t)*(t)*(3-(2*(t))))
30 
31 // cubic interpolation
32 // t is in [0,1]
33 // result is in [X0,X1]
34 #define CLERP(t,X0,X1) LERP(CUBIC_T(t), (X0), (X1))
35 
36 // spread calculator
37 // spread is non-negative spread magnitude
38 // result is in [-spread,spread]
39 #define SPREAD(magnitude) ((magnitude) - (NORMALIZED_RAND() * 2.0f * (magnitude)))
40 
41 // integer spread calculator
42 // spread is non-negative spread magnitude (integer)
43 // result is in [-spread,spread]
44 #define I_SPREAD(magnitude) ((magnitude) - ((int)rand() % ((2*(magnitude))+1)))
45 
46 #endif // PARTICLECOMMONFUNCS_H