diff --git a/SimpleHydrology.cpp b/SimpleHydrology.cpp index 9bcf5c3..2ef5e71 100644 --- a/SimpleHydrology.cpp +++ b/SimpleHydrology.cpp @@ -166,8 +166,8 @@ int main( int argc, char* args[] ) { model.construct(constructor); //Reconstruct Updated Model //Redraw the Path and Death Image - if(viewmap) - map.raw(image::make(world.dim, world.waterpath, world.waterpool, hydromap)); + if(viewmap) // make map transposed + map.raw(image::makeT(world.dim, world.waterpath, world.waterpool, hydromap)); } }); diff --git a/TinyEngine/TinyEngine.h b/TinyEngine/TinyEngine.h index 19cb35d..ffbea1e 100644 --- a/TinyEngine/TinyEngine.h +++ b/TinyEngine/TinyEngine.h @@ -79,6 +79,8 @@ bool init(std::string windowName, int width, int height){ std::cout<<"Failed to launch audio interface."< + SDL_Surface* makeT(glm::ivec2 size, T* data1, T* data2, std::function handle){ + SDL_Surface *s = SDL_CreateRGBSurface(0, size.x, size.y, 32, 0, 0, 0, 0); + SDL_LockSurface(s); + + unsigned char* img_raw = (unsigned char*)s->pixels; //Raw Data + + // transpose! + for (int x=0, i=0; x 0){ // - density[index - 256] += f*0.6; //(-1, 0) + density[index - dim.y] += f*0.6; //(-1, 0) if(pos.y > 0) - density[index - 257] += f*0.4; //(-1, -1) + density[index - dim.y - 1] += f*0.4; //(-1, -1) - if(pos.y < 256-1) - density[index - 255] += f*0.4; //(-1, 1) + if(pos.y < dim.y - 1) + density[index - dim.y + 1] += f*0.4; //(-1, 1) } - if(pos.x < 256-1){ + if(pos.x < dim.x - 1){ // - density[index + 256] += f*0.6; //(1, 0) + density[index + dim.y] += f*0.6; //(1, 0) if(pos.y > 0) - density[index + 255] += f*0.4; //(1, -1) + density[index + dim.y - 1] += f*0.4; //(1, -1) - if(pos.y < 256-1) - density[index + 257] += f*0.4; //(1, 1) + if(pos.y < dim.y - 1) + density[index + dim.y + 1] += f*0.4; //(1, 1) } if(pos.y > 0) density[index - 1] += f*0.6; //(0, -1) - if(pos.y < 256-1) + if(pos.y < dim.y - 1) density[index + 1] += f*0.6; //(0, 1) } + diff --git a/source/water.h b/source/water.h index 50b5fc3..c11229d 100644 --- a/source/water.h +++ b/source/water.h @@ -31,12 +31,26 @@ struct Drop{ glm::vec3 surfaceNormal(int index, double* h, glm::ivec2 dim, double scale){ //Two large triangels adjacent to the plane (+Y -> +X) (-Y -> -X) - glm::vec3 n = glm::cross(glm::vec3(0.0, scale*(h[index+1]-h[index]), 1.0), glm::vec3(1.0, scale*(h[index+dim.y]-h[index]), 0.0)); - n += glm::cross(glm::vec3(0.0, scale*(h[index-1]-h[index]), -1.0), glm::vec3(-1.0, scale*(h[index-dim.y]-h[index]), 0.0)); + glm::vec3 n = {0,0,0}; + + // would be better to get x,y + // right in the arguments instead of index + int x = index / dim.y; + int y = index % dim.y; + + if (x0 && y>0) + n += glm::cross(glm::vec3(0.0, scale*(h[index-1]-h[index]), -1.0), glm::vec3(-1.0, scale*(h[index-dim.y]-h[index]), 0.0)); //Two Alternative Planes (+X -> -Y) (-X -> +Y) - n += glm::cross(glm::vec3(1.0, scale*(h[index+dim.y]-h[index]), 0.0), glm::vec3(0.0, scale*(h[index-1]-h[index]), -1.0)); - n += glm::cross(glm::vec3(-1.0, scale*(h[index-dim.y]-h[index]), 0.0), glm::vec3(0.0, scale*(h[index+1]-h[index]), 1.0)); + + if (x0) + n += glm::cross(glm::vec3(1.0, scale*(h[index+dim.y]-h[index]), 0.0), glm::vec3(0.0, scale*(h[index-1]-h[index]), -1.0)); + + if (x>0 && y trees; - double plantdensity[256*256] = {0.0}; //Density for Plants + double plantdensity[size] = {0.0}; //Density for Plants //Erosion Process bool active = false; @@ -50,8 +54,14 @@ void World::generate(){ perlin.SetPersistence(0.5); double min, max = 0.0; + for(int i = 0; i < dim.x*dim.y; i++){ - heightmap[i] = perlin.GetValue((i/dim.y)*(1.0/dim.x), (i%dim.y)*(1.0/dim.y), SEED); + + double x = i / dim.y; + double y = i % dim.y; + + heightmap[i] = perlin.GetValue(x/dim.x, y/dim.y, SEED); + if(heightmap[i] > max) max = heightmap[i]; if(heightmap[i] < min) min = heightmap[i]; } @@ -205,7 +215,7 @@ glm::mat4 biasMatrix = glm::mat4( 0.5, 0.5, 0.5, 1.0 ); -std::function constructor = [&](Model* m){ +std::function constructor = [](Model* m){ //Clear the Containers m->indices.clear(); m->positions.clear(); @@ -331,7 +341,7 @@ std::function constructor = [&](Model* m){ } }; -std::function eventHandler = [&](){ +std::function eventHandler = [](){ if(!Tiny::event.scroll.empty()){ @@ -353,6 +363,7 @@ std::function eventHandler = [&](){ } //Adjust Stuff + if(rotation < 0.0) rotation = 360.0 + rotation; else if(rotation > 360.0) rotation = rotation - 360.0; camera = glm::rotate(glm::lookAt(cameraPos, lookPos, glm::vec3(0,1,0)), glm::radians(rotation), glm::vec3(0,1,0));