diff --git a/PlanetCreator/cw 6/src/ex_6_1.hpp b/PlanetCreator/cw 6/src/ex_6_1.hpp index b1c2d63..60f6126 100644 --- a/PlanetCreator/cw 6/src/ex_6_1.hpp +++ b/PlanetCreator/cw 6/src/ex_6_1.hpp @@ -156,6 +156,7 @@ struct PlanetParams { float humidity = 0.0f; // Начальное значение для влажности float temperature = 0.0f; // Начальное значение для осадков std::vector < std::tuple> Plant_info; // ID , position + std::vector Plant_type_count; }; std::vector planets; // Список всех планет @@ -170,14 +171,17 @@ bool sortFunction(std::tuple objA, std::tuple objB) PlanetParams populatePlanet(PlanetParams planet, std::vector plants) { float probability=0.5f; - int HOW_MANY_PLANTS = 10000; + int HOW_MANY_PLANTS = 1000; int PRECISION = 10000; float NOTHING_SPAWNS_CUTOFF = 0.2; int sum = 0; int chosen_number = 0; std::vector> probabilities; int plant_count = 0; - + for (int i = 0; i < plant_specimens.size(); i++) + { + planet.Plant_type_count.push_back(0); + } sum = NOTHING_SPAWNS_CUTOFF * PRECISION; int j = 0; for (auto& plant : plants) { @@ -195,6 +199,7 @@ PlanetParams populatePlanet(PlanetParams planet, std::vector plant } std::sort(probabilities.begin(), probabilities.end(), sortFunction); + for (int i = 0; i < HOW_MANY_PLANTS; i++) { chosen_number = int(sum * (rand() / (RAND_MAX + 1.0))) ; @@ -202,7 +207,7 @@ PlanetParams populatePlanet(PlanetParams planet, std::vector plant int winnerId = -1; for (auto& probability : probabilities) { - if (chosen_number > std::get<1>(probability)) + if (chosen_number < std::get<1>(probability)) { winnerId = std::get<0>(probability); break; @@ -213,13 +218,19 @@ PlanetParams populatePlanet(PlanetParams planet, std::vector plant { Plant::Plant plant = plants[winnerId]; plant_count += 1; + planet.Plant_type_count[winnerId] += 1; plant.pos = glm::vec3((2.0 * (rand() / (RAND_MAX + 1.0))-1), (2.0 * (rand() / (RAND_MAX + 1.0))-1), (2.0 * (rand() / (RAND_MAX + 1.0)))-1); planet.Plant_info.push_back(std::make_tuple(winnerId,plant.pos)); + } } std::cout <<"plant_count:" << plant_count << std::endl; - + for (int i = 0; i < planet.Plant_type_count.size(); i++) + { + std::cout << " " <