NoiseTest.cpp 8.0 KB

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