generator_random.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * .þÛÛþ þ þ þÛÛþ. þ þ þÛÛÛþ. þÛÛÛþ .þÛÛþ. þ þ
  3. * .þ Û Ûþ. Û Û þ. Û Û Û þ Û. Û. Û Ûþ. Û
  4. * Û Û Û Û Û Û Û Û þ. Û. Û Û Û Û Û Û Û
  5. * .þþÛÛÛÛþ Û Û Û þÛÛÛÛþþ. þþÛÛ. þþÛÛþ. þÛ Û Û Û Û Û
  6. * .Û Û Û .þÛ Û Û. Û Û Û Û Û. þ. Û Û .þÛ
  7. * þ. þ þ þ þ .þ þ .þ þ .þ þÛÛÛþ .þÛÛþ. þ þ
  8. *
  9. * AGE (C) AnakreoN
  10. * Martin Stransky <stransky@anakreon.cz>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. *
  26. */
  27. #ifndef __GENERATOR_RANDOM_H__
  28. #define __GENERATOR_RANDOM_H__
  29. /*
  30. * Generator type
  31. */
  32. typedef enum {
  33. GENERATOR_GAUSS = 0,
  34. GENERATOR_RAND = 1
  35. } RANDOM_GENERATOR_TYPE;
  36. /*
  37. * Generator class
  38. */
  39. typedef class random_generator
  40. {
  41. public:
  42. /*
  43. Random number generator
  44. range is 0...1
  45. */
  46. static float generator_rand(void);
  47. /*
  48. Random number generator
  49. range is -1...1
  50. */
  51. static float generator_rand_0(void);
  52. /*
  53. Gauss random number generator
  54. center is 0.5
  55. range is +- 0.5
  56. */
  57. static float generator_gauss(void);
  58. /*
  59. Gauss random number generator
  60. center is 0.0
  61. range is +- 1.0
  62. */
  63. static float generator_gauss_0(void);
  64. /*
  65. Gauss random number generator
  66. center (and maximum) is 1.0
  67. range is 1.0 - 0.0
  68. */
  69. static float generator_gauss_1(void);
  70. /*
  71. * Generate scattering
  72. */
  73. static float generate_scattering(RANDOM_GENERATOR_TYPE generator_type);
  74. } RANDOM_GENERATOR;
  75. /*
  76. * Random generator fractal
  77. */
  78. typedef class random_generator_fractal
  79. : public random_generator
  80. {
  81. /*
  82. * Fractal generator params
  83. */
  84. public:
  85. /*
  86. <0,1>
  87. 0 - maximax disertion
  88. 1 - minimal disertion
  89. */
  90. float generator_hurst;
  91. public:
  92. float generator_delta;
  93. float generator_center;
  94. public:
  95. void generator_range_set(float min, float max)
  96. {
  97. generator_delta = max - min;
  98. generator_center = min + generator_delta/2;
  99. }
  100. void generator_center_set(float center, float delta)
  101. {
  102. generator_delta = delta;
  103. generator_center = center;
  104. }
  105. void generator_hurst_set(float hurst)
  106. {
  107. generator_hurst = hurst;
  108. }
  109. public:
  110. /*
  111. * Generate height
  112. */
  113. float generate_height(int iteration);
  114. static float generate_height(int iteration, float hurst, float center, float delta);
  115. public:
  116. random_generator_fractal(void);
  117. } RANDOM_GENERATOR_FRACTAL;
  118. #endif // __GENERATOR_RANDOM_H__