NoiseTest.cpp 8.0 KB

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