NoiseTest.cpp 7.7 KB

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