123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- #include <AsynchronCall.h>
- #include <Bild.h>
- #include <Bildschirm.h>
- #include <Fenster.h>
- #include <Globals.h>
- #include <iostream>
- #include <RenderThread.h>
- #include <string.h>
- #include "FastNoiseLite.h"
- #include "FastNoiseWrapper.h"
- #include "RandNoise.h"
- #include "ShapedNoise.h"
- using namespace Framework;
- WFenster* window;
- Bild* img;
- Vec3<int> position(0, 0, 0);
- int zoom = 1;
- bool exitF = 0;
- Noise* wrapper;
- float border = 0.5;
- float border2 = -1;
- bool showValue = 1;
- void updateView()
- {
- Vec3<int> minP
- = position
- - Vec3<int>(img->getBreite() / 2, img->getHeight() / 2, 0) / zoom;
- Vec3<int> maxP
- = position
- + Vec3<int>(img->getBreite() / 2, img->getHeight() / 2, 0) / zoom;
- int counter = 0;
- for (int i = 0; i < img->getBreite(); i++)
- {
- for (int j = 0; j < img->getHeight(); j++)
- {
- Vec3<int> pos(i, j, 0);
- pos -= Vec3<int>(img->getBreite() / 2, img->getHeight() / 2, 0);
- pos /= zoom;
- pos += position;
- double noise = wrapper->getNoise(pos.x, pos.y, pos.z);
- if (showValue)
- {
- int value = (int)(noise * 255);
- img->setPixelDP(
- i, j, 0xFF000000 | (value << 16) | (value << 8) | value);
- }
- else
- {
- if (noise < border && noise > border2)
- {
- img->setPixelDP(i, j, 0xFFFFFFFF);
- counter++;
- }
- else
- {
- img->setPixelDP(i, j, 0xFF000000);
- }
- }
- }
- }
- float percentage = ((float)counter / (img->getBreite() * img->getHeight())) * 100;
- std::cout << "Showing " << minP.x << " " << minP.y << " to " << maxP.x
- << " " << maxP.y << " at height " << position.z << " with border "
- << border2 << " to "
- << border << " true for " << percentage << "% of "
- << (img->getBreite() / zoom) * (img->getHeight() / zoom) << " blocks"
- << std::endl;
- }
- int main()
- {
- Framework::initFramework();
- /* FastNoiseLite* noise = new FastNoiseLite(0);
- noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
- noise->SetFrequency(3.f);
- wrapper = new FastNoiseWrapper(noise, 0);*/
- FastNoiseLite* n = new FastNoiseLite(0);
- n->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_Cellular);
- n->SetFrequency(0.005f);
- n->SetRotationType3D(FastNoiseLite::RotationType3D::RotationType3D_None);
- n->SetCellularDistanceFunction(FastNoiseLite::CellularDistanceFunction::
- CellularDistanceFunction_Hybrid);
- n->SetCellularJitter(1.f);
- n->SetCellularReturnType(
- FastNoiseLite::CellularReturnType::CellularReturnType_CellValue);
- n->SetFractalType(
- FastNoiseLite::FractalType::FractalType_DomainWarpIndependent);
- n->SetDomainWarpType(
- FastNoiseLite::DomainWarpType::DomainWarpType_OpenSimplex2);
- n->SetDomainWarpAmp(100.f);
- n->SetFractalOctaves(3.f);
- n->SetFractalLacunarity(2.f);
- n->SetFractalGain(0.5f);
- wrapper = new FastNoiseWrapper(n, 0);
- wrapper = new ShapedNoise(wrapper);
- ((ShapedNoise*)wrapper)->setNeighborOffset(4.f);
- wrapper = new RandNoise(34255);
- img = new Bild();
- img->neuBild(800, 800, 0xFF000000);
- BildZ* view = new BildZ();
- view->setBildZ(img);
- view->setStyle(BildZ::Style::Sichtbar);
- view->setSize(800, 800);
- WNDCLASS wc = Framework::F_Normal(GetModuleHandle(NULL));
- wc.lpszClassName = "Fenster";
- window = new WFenster();
- window->erstellen(WS_OVERLAPPEDWINDOW, wc);
- window->setSize(800, 800);
- window->setPosition(100, 100);
- window->setAnzeigeModus(SW_SHOW);
- window->setVSchließAktion([](void* p, void* o) {
- StopNachrichtenSchleife(window->getFensterHandle());
- });
- Bildschirm* screen = new Bildschirm2D(window);
- window->setBildschirm(dynamic_cast<Bildschirm*>(screen->getThis()));
- screen->addMember(view);
- screen->setTestRend(0);
- screen->update();
- screen->render();
- RenderTh* rth = new RenderTh();
- rth->setQuiet(1);
- rth->setBildschirm(screen);
- rth->beginn();
- updateView();
- new AsynchronCall([]() {
- char line[256];
- while (!exitF)
- {
- std::cin.getline(line, 256);
- if (strcmp(line, "exit") == 0)
- {
- StopNachrichtenSchleife(window->getFensterHandle());
- break;
- }
- Text txt(line);
- if (txt.positionVon("show ") == 0)
- {
- Text* x = txt.getTeilText(5);
- position.x = (int)*x;
- Text* y = x->getTeilText(x->positionVon(" ") + 1);
- position.y = (int)*y;
- Text* z = y->getTeilText(y->positionVon(" ") + 1);
- position.z = (int)*z;
- updateView();
- z->release();
- y->release();
- x->release();
- }
- if (txt.positionVon("border ") == 0)
- {
- Text* x = txt.getTeilText(7);
- border = (float)*x;
- updateView();
- x->release();
- }
- if (txt.positionVon("border2 ") == 0)
- {
- Text* x = txt.getTeilText(7);
- border2 = (float)*x;
- updateView();
- x->release();
- }
- if (txt.positionVon("zoom ") == 0)
- {
- Text* x = txt.getTeilText(5);
- zoom = (int)*x;
- updateView();
- x->release();
- }
- if (txt.positionVon("show value") == 0)
- {
- showValue = 1;
- updateView();
- }
- if (txt.positionVon("show border") == 0)
- {
- showValue = 0;
- updateView();
- }
- }
- });
- StartNachrichtenSchleife();
- exitF = 1;
- rth->beenden();
- window->setBildschirm(0);
- rth->release();
- Framework::releaseFramework();
- return 0;
- }
|