home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / formats / ttddd / code / noise.h < prev    next >
C/C++ Source or Header  |  1994-06-20  |  5KB  |  141 lines

  1. /*------------------------------------------------------------------\
  2. |  Name:          NOISE.H                                           |
  3. |  Author:        Charles Congdon                                   |
  4. |  Created:       09/23/92                                          |
  5. |  Last Updated:  10/29/92                                          |
  6. |                                                                   |
  7. |  Purpose:                                                         |
  8. |      This module contains the includes for 3D noise functions.    |
  9. \------------------------------------------------------------------*/
  10.  
  11. #ifndef NOISEH
  12.  
  13. #define NOISEH 1
  14.  
  15. /*---------------------------\
  16. |  Pull in main includes.    |
  17. \---------------------------*/
  18.  
  19. #include <stdlib.h>
  20. #include <math.h>
  21.  
  22. /*-------------------------------------------------------\
  23. |  I suggest use the following two lines only with -f8   |
  24. |  (floating point accelerator, optimized code).         |
  25. \-------------------------------------------------------*/
  26. #ifdef _M68881
  27. #include <m68881.h>
  28. #endif
  29. #define FLOOR_ERROR 0   /* The Lattice 5.10a 68881 library incorrectly sets
  30.                            floor -4.5 to -4.  This inserts code to correct
  31.                for this sin */
  32.  
  33. #undef CONSUME_MY_CPU
  34. /*---------------------------------------- ------------------------------\
  35. |  Uncomment the following line if you wish to use Hermit interpolation  |
  36. |  for the vector direction as well as the vector magnitude (overkill    |
  37. |  unless you really need all 4 of these values smooth - the vector      |
  38. |  directions, although usually linearly interpolated, add to a pretty   |
  39. |  smooth direction change, and the vector magnitude is always           |
  40. |  interpolated with care.                                               |
  41. \-----------------------------------------------------------------------*/
  42. /* #define CONSUME_MY_CPU 1 */
  43.  
  44. /*---------------------------------------\
  45. |  Define matrix and vector datatypes    |
  46. \---------------------------------------*/
  47. /* #ifdef INITNOISE */
  48. #define MATRIXSIZE 4
  49. #define COORD double                          
  50.                                          
  51.    /*-----------------------------------------------------------\
  52.    |  It may make sense to externalize these type definitions   |
  53.    \-----------------------------------------------------------*/
  54.    typedef double matrix[MATRIXSIZE][MATRIXSIZE]; 
  55.    typedef COORD  vector[3];
  56. /* #endif */
  57.  
  58.  
  59. /*-------------------\
  60. |  Noise defaults    |
  61. \-------------------*/
  62. #define IINIT_SCALE   10.0
  63. #define INUM_SCALES   5.0
  64. #define ISCALE_RATIO  0.4
  65. #define IAMP_RATIO    0.4
  66. #define ITIME_RATIO   0.4
  67. #define ITIME         0.0
  68. #define IMAX_SCALES   20.0
  69. #define IIMAX_SCALES  20
  70.  
  71. #ifdef INITNOISE                     
  72.    /*----------------------------\ 
  73.    |  Initialization variables.  | 
  74.    \----------------------------*/ 
  75. #  define EI               
  76. #  define II(x)  = { (x) }          
  77.  
  78. #else  /* INITNOISE */
  79.  
  80.    /*-----------------------------\
  81.    |  External reference macros.  |
  82.    \-----------------------------*/
  83. #  define EI extern
  84. #  define II(x)
  85.  
  86. #endif  /* INITNOISE */
  87.  
  88. #define SLONG signed   long int
  89. #define ULNG  unsigned long int
  90.  
  91. /*---------------------------\
  92. |  Noise function globals    |
  93. \---------------------------*/
  94. EI SLONG  xlim[3][2];  /* Global variable for the cube containing the point */
  95. EI double xarg[3];     /* Global variable for the fractional parts for each
  96.                           coord - always positive (critical!) */
  97. EI short int    Noiseinit;   /* Have we set up the noise function yet? */
  98. EI double Frame;             /* The frame number - use as needed */
  99.  
  100. /*-------------------------------\
  101. |  Noise function prototypes.    |
  102. \-------------------------------*/
  103.  
  104. #ifdef __STDC__
  105. #define P8(a,b,c,d,e,f,g,h) a,b,c,d,e,f,g,h
  106. #else
  107. #define P8(a,b,c,d,e,f,g,h)
  108. #endif
  109.  
  110. void   ninterp(P3(double f[4],
  111.                    short int i,
  112.            register short int n)
  113.           );
  114. void   normalze(P3(double scale,
  115.                     vector in,
  116.             vector out)
  117.            );
  118.  
  119. double frand( P1(SLONG s) );
  120. double Noise3D(P2(vector point,
  121.                   vector noisev)
  122.           );
  123. double wfractalval3(P8(vector in,
  124.                         double Initial_scale,
  125.             double NumScales,
  126.                         double Scale_Ratio,
  127.             double Amplitude_Ratio, 
  128.                   double Time_Ratio,
  129.             double Time,
  130.             vector out)
  131.            );
  132. void NiceN3D(P4(vector point,
  133.                  vector noisev,
  134.          double scale,
  135.          double NumScales)
  136.         );
  137.  
  138. #endif /* Not NOISEH */
  139.  
  140.  
  141.