NoiseTest.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. #include <AsynchronCall.h>
  2. #include <Bild.h>
  3. #include <Bildschirm.h>
  4. #include <Fenster.h>
  5. #include <Globals.h>
  6. #include <iostream>
  7. #include <RenderThread.h>
  8. #include <string.h>
  9. #include "FastNoiseLite.h"
  10. #include "FastNoiseWrapper.h"
  11. #include "RandNoise.h"
  12. #include "ShapedNoise.h"
  13. #include "NoiseCombiner.h"
  14. using namespace Framework;
  15. WFenster* window;
  16. Bild* img;
  17. Vec3<int> position(0, 0, 0);
  18. float zoom = 0.1;
  19. bool exitF = 0;
  20. Noise* wrapper;
  21. float border = 0.5;
  22. float border2 = -1;
  23. bool showValue = 1;
  24. void updateView()
  25. {
  26. Vec3<int> minP
  27. = position
  28. - Vec3<float>(img->getBreite() / 2, img->getHeight() / 2, 0) / zoom;
  29. Vec3<int> maxP
  30. = position
  31. + Vec3<float>(img->getBreite() / 2, img->getHeight() / 2, 0) / zoom;
  32. int counter = 0;
  33. double min = INFINITY;
  34. double max = -INFINITY;
  35. for (int i = 0; i < img->getBreite(); i++)
  36. {
  37. for (int j = 0; j < img->getHeight(); j++)
  38. {
  39. Vec3<float> pos(i, j, 0);
  40. pos -= Vec3<int>(img->getBreite() / 2, img->getHeight() / 2, 0);
  41. pos /= zoom;
  42. pos += position;
  43. double noise = wrapper->getNoise(pos.x, pos.y, pos.z);
  44. if (noise > max)
  45. {
  46. max = noise;
  47. }
  48. if (noise < min)
  49. {
  50. min = noise;
  51. }
  52. if (showValue)
  53. {
  54. int value = (int)(noise * 255);
  55. img->setPixelDP(
  56. i, j, 0xFF000000 | (value << 16) | (value << 8) | value);
  57. }
  58. else
  59. {
  60. if (noise < border && noise > border2)
  61. {
  62. img->setPixelDP(i, j, 0xFFFFFFFF);
  63. counter++;
  64. }
  65. else
  66. {
  67. img->setPixelDP(i, j, 0xFF000000);
  68. }
  69. }
  70. }
  71. }
  72. float percentage
  73. = ((float)counter / (img->getBreite() * img->getHeight())) * 100;
  74. std::cout << "Showing " << minP.x << " " << minP.y << " to " << maxP.x
  75. << " " << maxP.y << " at height " << position.z << " with border "
  76. << border2 << " to " << border << " true for " << percentage
  77. << "% of "
  78. << (img->getBreite() / zoom) * (img->getHeight() / zoom)
  79. << " blocks. Min: " << min << " Max: " << max << std::endl;
  80. }
  81. int main()
  82. {
  83. Framework::initFramework();
  84. FastNoiseLite* noise = new FastNoiseLite(1);
  85. noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_Perlin);
  86. FastNoiseWrapper *wrapper1 = new FastNoiseWrapper(noise, 0);
  87. //wrapper = wrapper2;
  88. /* FastNoiseLite* noise = new FastNoiseLite(0);
  89. noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
  90. noise->SetFrequency(3.f);
  91. wrapper = new FastNoiseWrapper(noise, 0);*/
  92. FastNoiseLite* n = new FastNoiseLite(2);
  93. n->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_Cellular);
  94. n->SetFrequency(0.005f);
  95. n->SetRotationType3D(FastNoiseLite::RotationType3D::RotationType3D_None);
  96. n->SetCellularDistanceFunction(FastNoiseLite::CellularDistanceFunction::
  97. CellularDistanceFunction_Hybrid);
  98. n->SetCellularJitter(1.f);
  99. n->SetCellularReturnType(
  100. FastNoiseLite::CellularReturnType::CellularReturnType_Distance);
  101. n->SetFractalType(
  102. FastNoiseLite::FractalType::FractalType_DomainWarpIndependent);
  103. n->SetDomainWarpType(
  104. FastNoiseLite::DomainWarpType::DomainWarpType_OpenSimplex2);
  105. n->SetDomainWarpAmp(100.f);
  106. n->SetFractalOctaves(3.f);
  107. n->SetFractalLacunarity(2.f);
  108. n->SetFractalGain(0.5f);
  109. FastNoiseWrapper* wrapper2 = new FastNoiseWrapper(n, 2);
  110. wrapper2->setMultiplier(0.1f);
  111. wrapper = new NoiseCombinerM(wrapper1, wrapper2);
  112. n = new FastNoiseLite(3);
  113. n->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_Cellular);
  114. n->SetFrequency(0.005f);
  115. n->SetRotationType3D(FastNoiseLite::RotationType3D::RotationType3D_None);
  116. n->SetCellularDistanceFunction(FastNoiseLite::CellularDistanceFunction::
  117. CellularDistanceFunction_Hybrid);
  118. n->SetCellularJitter(1.f);
  119. n->SetCellularReturnType(
  120. FastNoiseLite::CellularReturnType::CellularReturnType_Distance);
  121. n->SetFractalType(
  122. FastNoiseLite::FractalType::FractalType_DomainWarpIndependent);
  123. n->SetDomainWarpType(
  124. FastNoiseLite::DomainWarpType::DomainWarpType_OpenSimplex2);
  125. n->SetDomainWarpAmp(100.f);
  126. n->SetFractalOctaves(3.f);
  127. n->SetFractalLacunarity(2.f);
  128. n->SetFractalGain(0.5f);
  129. wrapper2 = new FastNoiseWrapper(n, 0);
  130. wrapper2->setMultiplier(0.4f);
  131. wrapper = new NoiseCombinerM(wrapper, wrapper2);
  132. noise = new FastNoiseLite(10);
  133. noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
  134. wrapper2 = new FastNoiseWrapper(noise, 0);
  135. wrapper2->setMultiplier(0.15f);
  136. wrapper = new NoiseCombinerA(wrapper, wrapper2);
  137. //wrapper = new ShapedNoise(wrapper);
  138. //((ShapedNoise*)wrapper)->setNeighborOffset(4.f);
  139. //wrapper = new RandNoise(34255);
  140. img = new Bild();
  141. img->neuBild(1600, 1600, 0xFF000000);
  142. BildZ* view = new BildZ();
  143. view->setBildZ(img);
  144. view->setStyle(BildZ::Style::Sichtbar);
  145. view->setSize(800, 800);
  146. WNDCLASS wc = Framework::F_Normal(GetModuleHandle(NULL));
  147. wc.lpszClassName = "Fenster";
  148. window = new WFenster();
  149. window->erstellen(WS_OVERLAPPEDWINDOW, wc);
  150. window->setSize(800, 800);
  151. window->setPosition(100, 100);
  152. window->setAnzeigeModus(SW_SHOW);
  153. window->setVSchließAktion([](void* p, void* o) {
  154. StopNachrichtenSchleife(window->getFensterHandle());
  155. });
  156. Bildschirm* screen = new Bildschirm2D(window);
  157. window->setBildschirm(dynamic_cast<Bildschirm*>(screen->getThis()));
  158. screen->addMember(view);
  159. screen->setTestRend(0);
  160. screen->update();
  161. screen->render();
  162. RenderTh* rth = new RenderTh();
  163. rth->setQuiet(1);
  164. rth->setBildschirm(screen);
  165. rth->beginn();
  166. updateView();
  167. new AsynchronCall([]() {
  168. char line[256];
  169. while (!exitF)
  170. {
  171. std::cin.getline(line, 256);
  172. if (strcmp(line, "exit") == 0)
  173. {
  174. StopNachrichtenSchleife(window->getFensterHandle());
  175. break;
  176. }
  177. Text txt(line);
  178. if (txt.positionVon("show ") == 0)
  179. {
  180. Text* x = txt.getTeilText(5);
  181. position.x = (int)*x;
  182. Text* y = x->getTeilText(x->positionVon(" ") + 1);
  183. position.y = (int)*y;
  184. Text* z = y->getTeilText(y->positionVon(" ") + 1);
  185. position.z = (int)*z;
  186. updateView();
  187. z->release();
  188. y->release();
  189. x->release();
  190. }
  191. if (txt.positionVon("border ") == 0)
  192. {
  193. Text* x = txt.getTeilText(7);
  194. border = (float)*x;
  195. updateView();
  196. x->release();
  197. }
  198. if (txt.positionVon("border2 ") == 0)
  199. {
  200. Text* x = txt.getTeilText(7);
  201. border2 = (float)*x;
  202. updateView();
  203. x->release();
  204. }
  205. if (txt.positionVon("zoom ") == 0)
  206. {
  207. Text* x = txt.getTeilText(5);
  208. zoom = (int)*x;
  209. updateView();
  210. x->release();
  211. }
  212. if (txt.positionVon("show value") == 0)
  213. {
  214. showValue = 1;
  215. updateView();
  216. }
  217. if (txt.positionVon("show border") == 0)
  218. {
  219. showValue = 0;
  220. updateView();
  221. }
  222. }
  223. });
  224. StartNachrichtenSchleife();
  225. exitF = 1;
  226. rth->beenden();
  227. window->setBildschirm(0);
  228. rth->release();
  229. Framework::releaseFramework();
  230. return 0;
  231. }