NoiseTest.cpp 7.5 KB

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