NoiseTest.cpp 7.7 KB

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