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